Skip to content

Commit ff0c44e

Browse files
committed
temp
1 parent 4965f58 commit ff0c44e

File tree

7 files changed

+32
-33
lines changed

7 files changed

+32
-33
lines changed

x-pack/solutions/observability/plugins/slo/public/pages/slos/components/common/sort_by_select.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ export function SLOSortBy({ state, onStateChange, loading }: Props) {
3232
const sortBy = state.sort.by;
3333

3434
const handleChangeSortBy = ({ value, label }: { value: SortField; label: string }) => {
35-
onStateChange({
36-
page: 0,
37-
sort: { by: value, direction: state.sort.direction },
38-
});
35+
onStateChange(
36+
{
37+
page: 0,
38+
sort: { by: value, direction: state.sort.direction },
39+
},
40+
{ replace: true }
41+
);
3942
};
4043

4144
const sortByOptions: Option[] = [

x-pack/solutions/observability/plugins/slo/public/pages/slos/components/grouped_slos/group_view.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function GroupView({
5555

5656
const { results = [], total = 0 } = data ?? {};
5757
const handlePageClick = (pageNumber: number) => {
58-
onStateChange({ page: pageNumber });
58+
onStateChange({ page: pageNumber }, { replace: true });
5959
};
6060

6161
if (isLoading || isRefetching) {
@@ -101,7 +101,7 @@ export function GroupView({
101101
itemsPerPage={perPage}
102102
itemsPerPageOptions={[10, 25, 50, 100]}
103103
onChangeItemsPerPage={(newPerPage) => {
104-
onStateChange({ perPage: newPerPage, page: 0 });
104+
onStateChange({ perPage: newPerPage, page: 0 }, { replace: true });
105105
}}
106106
/>
107107
</EuiFlexItem>

x-pack/solutions/observability/plugins/slo/public/pages/slos/components/slo_list_group_by.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ export function SloGroupBy({ onStateChange, state, loading }: Props) {
3737
settings && (settings.useAllRemoteClusters || settings.selectedRemoteClusters.length > 0);
3838

3939
const handleChangeGroupBy = (value: GroupByField) => {
40-
onStateChange({
41-
page: 0,
42-
groupBy: value,
43-
});
40+
onStateChange(
41+
{
42+
page: 0,
43+
groupBy: value,
44+
},
45+
{ replace: true }
46+
);
4447
};
4548
const groupByOptions: Option[] = [
4649
{

x-pack/solutions/observability/plugins/slo/public/pages/slos/components/slo_list_search_bar.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
*/
77

88
import { css } from '@emotion/react';
9-
import type { Query } from '@kbn/es-query';
109
import { i18n } from '@kbn/i18n';
1110
import { observabilityAppId } from '@kbn/observability-plugin/public';
12-
import React, { useEffect } from 'react';
11+
import React from 'react';
1312
import { useKibana } from '../../../hooks/use_kibana';
1413
import { useSloCrudLoading } from '../hooks/use_crud_loading';
1514
import { useSloSummaryDataView } from '../hooks/use_summary_dataview';
@@ -18,7 +17,6 @@ import { QuickFilters } from './common/quick_filters';
1817

1918
export function SloListSearchBar() {
2019
const {
21-
data: { query },
2220
unifiedSearch: {
2321
ui: { SearchBar },
2422
},
@@ -29,18 +27,6 @@ export function SloListSearchBar() {
2927

3028
const { isLoading: isDataViewLoading, data: dataView } = useSloSummaryDataView();
3129

32-
useEffect(() => {
33-
const sub = query.state$.subscribe(() => {
34-
const queryState = query.getState();
35-
onStateChange({
36-
kqlQuery: String((queryState.query as Query).query),
37-
filters: queryState.filters,
38-
});
39-
});
40-
41-
return () => sub.unsubscribe();
42-
}, [onStateChange, query]);
43-
4430
return (
4531
<div
4632
css={css`
@@ -50,12 +36,14 @@ export function SloListSearchBar() {
5036
`}
5137
>
5238
<SearchBar
39+
key={`${state.kqlQuery}-${JSON.stringify(state.filters)}`}
5340
appName={observabilityAppId}
5441
placeholder={PLACEHOLDER}
5542
indexPatterns={dataView ? [dataView] : []}
5643
isDisabled={isSloCrudLoading}
5744
renderQueryInputAppend={() => (
5845
<QuickFilters
46+
key={`quick-filters-${state.tagsFilter?.meta?.key}-${state.statusFilter?.meta?.key}`}
5947
dataView={dataView}
6048
initialState={state}
6149
loading={isSloCrudLoading || isDataViewLoading}

x-pack/solutions/observability/plugins/slo/public/pages/slos/components/slos_overview/overview_item.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export function OverviewItem({
4444
}
4545
onStateChange({
4646
kqlQuery: query,
47+
filters: [],
48+
tagsFilter: undefined,
49+
statusFilter: undefined,
4750
});
4851
}}
4952
css={{

x-pack/solutions/observability/plugins/slo/public/pages/slos/components/ungrouped_slos/ungrouped_view.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ export function UngroupedView({ sloList, loading, error, view }: Props) {
3333
pageCount={Math.ceil(total / perPage)}
3434
activePage={page}
3535
onChangePage={(newPage) => {
36-
onStateChange({ page: newPage });
36+
onStateChange({ page: newPage }, { replace: true });
3737
}}
3838
itemsPerPage={perPage}
3939
itemsPerPageOptions={[10, 25, 50, 100]}
4040
onChangeItemsPerPage={(newPerPage) => {
41-
onStateChange({ perPage: newPerPage, page: 0 });
41+
onStateChange({ perPage: newPerPage, page: 0 }, { replace: true });
4242
}}
4343
/>
4444
</EuiFlexItem>

x-pack/solutions/observability/plugins/slo/public/pages/slos/hooks/use_url_search_state.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const DEFAULT_STATE: SearchState = {
4949

5050
export function useUrlSearchState(): {
5151
state: SearchState;
52-
onStateChange: (state: Partial<SearchState>) => void;
52+
onStateChange: (state: Partial<SearchState>, options?: { replace?: boolean }) => void;
5353
} {
5454
const [state, setState] = useState<SearchState>(DEFAULT_STATE);
5555
const history = useHistory();
@@ -67,9 +67,9 @@ export function useUrlSearchState(): {
6767
const sub = urlStateStorage.current
6868
?.change$<SearchState>(SLO_LIST_SEARCH_URL_STORAGE_KEY)
6969
.subscribe((newSearchState) => {
70-
if (newSearchState) {
71-
setState(newSearchState);
72-
}
70+
// When URL has no search params, newSearchState will be null/undefined
71+
// In that case, reset to DEFAULT_STATE
72+
setState(newSearchState ?? DEFAULT_STATE);
7373
});
7474

7575
setState(
@@ -84,12 +84,14 @@ export function useUrlSearchState(): {
8484
}, [urlStateStorage, sessionStorage]);
8585

8686
const onStateChange = useCallback(
87-
(newState: Partial<SearchState>) => {
87+
(newState: Partial<SearchState>, options?: { replace?: boolean }) => {
8888
const updatedState = { ...state, page: 0, ...newState };
8989
setState(() => updatedState);
9090

91+
// Use push (replace: false) by default to create new history entries
92+
// This allows back button to work properly
9193
urlStateStorage.current?.set(SLO_LIST_SEARCH_URL_STORAGE_KEY, updatedState, {
92-
replace: true,
94+
replace: options?.replace ?? false,
9395
});
9496

9597
// Discard search itself from session storage. Keep only view preferences

0 commit comments

Comments
 (0)