diff --git a/pkg/ui/src/views/app/components/Search/index.tsx b/pkg/ui/src/views/app/components/Search/index.tsx index 2d373f50e71d..8a8fb790664f 100644 --- a/pkg/ui/src/views/app/components/Search/index.tsx +++ b/pkg/ui/src/views/app/components/Search/index.tsx @@ -18,6 +18,7 @@ import "./search.styl"; interface ISearchProps { onSubmit: (value: string) => void; onClear?: () => void; + defaultValue?: string; } interface ISearchState { @@ -30,7 +31,7 @@ type TSearchProps = ISearchProps & InputProps; export class Search extends React.Component { state = { - value: "", + value: this.props.defaultValue || "", submitted: false, }; diff --git a/pkg/ui/src/views/statements/statementsPage.tsx b/pkg/ui/src/views/statements/statementsPage.tsx index 095e5068b066..1aafc923ca5f 100644 --- a/pkg/ui/src/views/statements/statementsPage.tsx +++ b/pkg/ui/src/views/statements/statementsPage.tsx @@ -73,28 +73,44 @@ export class StatementsPage extends React.Component) { super(props); + const { history } = props; + const searchParams = new URLSearchParams(history.location.search); + const sortKey = searchParams.get("sortKey"); + const ascending = searchParams.get("ascending"); + const searchQuery = searchParams.get("q"); + this.state = { sortSetting: { - sortKey: 6, // Latency - ascending: false, + sortKey: sortKey || 6, // Latency column is default for sorting + ascending: Boolean(ascending) || false, }, pagination: { pageSize: 20, current: 1, }, - search: "", + search: searchQuery || "", }; this.activateDiagnosticsRef = React.createRef(); } changeSortSetting = (ss: SortSetting) => { + const { history } = this.props; + this.setState({ sortSetting: ss, }); + + const searchParams = new URLSearchParams(history.location.search); + searchParams.set("sortKey", ss.sortKey); + searchParams.set("ascending", Boolean(ss.ascending).toString()); + history.location.search = searchParams.toString(); + history.replace(history.location); } selectApp = (app: DropdownOption) => { - this.props.history.push(`/statements/${app.value}`); + const { history } = this.props; + history.location.pathname = `/statements/${app.value}`; + history.replace(history.location); } componentWillMount() { @@ -125,9 +141,24 @@ export class StatementsPage extends React.Component this.setState({ pagination: { ...this.state.pagination, current: 1 }, search }); + onSubmitSearchField = (search: string) => { + const { history } = this.props; + this.setState({ pagination: { ...this.state.pagination, current: 1 }, search }); - onClearSearchField = () => this.setState({ search: "" }); + const searchParams = new URLSearchParams(history.location.search); + searchParams.set("q", search); + history.location.search = searchParams.toString(); + history.replace(history.location); + } + + onClearSearchField = () => { + const { history } = this.props; + this.setState({ search: "" }); + const searchParams = new URLSearchParams(history.location.search); + searchParams.delete("q"); + history.location.search = searchParams.toString(); + history.replace(history.location); + } filteredStatementsData = () => { const { search } = this.state; @@ -201,6 +232,7 @@ export class StatementsPage extends React.Component