Skip to content

Commit

Permalink
Interface change for MDS and deprecating dataSourceLabel from the URL (
Browse files Browse the repository at this point in the history
…opensearch-project#1031)

Signed-off-by: Ramakrishna Chilaka <[email protected]>
(cherry picked from commit ed98e4a)
  • Loading branch information
RamakrishnaChilaka committed Apr 12, 2024
1 parent a71371a commit 18dbfb0
Show file tree
Hide file tree
Showing 10 changed files with 507 additions and 476 deletions.
12 changes: 3 additions & 9 deletions public/components/MDSEnabledComponent/MDSEnabledComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default class MDSEnabledComponent<
super(props);
this.state = {
dataSourceId: props.dataSourceId,
dataSourceLabel: props.dataSourceLabel,
multiDataSourceEnabled: props.multiDataSourceEnabled,
} as State;
}
Expand All @@ -21,13 +20,9 @@ export default class MDSEnabledComponent<
prevState: State
) {
// static members cannot reference class type parameters
if (
nextProps.multiDataSourceEnabled &&
(nextProps.dataSourceId !== prevState.dataSourceId || nextProps.dataSourceLabel !== prevState.dataSourceLabel)
) {
if (nextProps.multiDataSourceEnabled && nextProps.dataSourceId !== prevState.dataSourceId) {
return {
dataSourceId: nextProps.dataSourceId,
dataSourceLabel: nextProps.dataSourceLabel,
};
}
return null;
Expand All @@ -36,7 +31,7 @@ export default class MDSEnabledComponent<

export function useUpdateUrlWithDataSourceProperties() {
const dataSourceMenuProps = useContext(DataSourceMenuContext);
const { dataSourceId, dataSourceLabel, multiDataSourceEnabled } = dataSourceMenuProps;
const { dataSourceId, multiDataSourceEnabled } = dataSourceMenuProps;
const history = useHistory();
const currentSearch = history.location.search;
const currentQuery = queryString.parse(currentSearch);
Expand All @@ -46,9 +41,8 @@ export function useUpdateUrlWithDataSourceProperties() {
search: queryString.stringify({
...currentQuery,
dataSourceId,
dataSourceLabel,
}),
});
}
}, [dataSourceId, dataSourceLabel, multiDataSourceEnabled]);
}, [dataSourceId, multiDataSourceEnabled]);
}
1 change: 0 additions & 1 deletion public/pages/Aliases/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ export const DEFAULT_QUERY_PARAMS = {
sortDirection: SortDirection.DESC,
status: "",
dataSourceId: "",
dataSourceLabel: "",
};
1 change: 0 additions & 1 deletion public/pages/ComposableTemplates/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ export const DEFAULT_QUERY_PARAMS = {
sortField: "name" as keyof ICatComposableTemplate,
sortDirection: SortDirection.DESC,
dataSourceId: "",
dataSourceLabel: "",
};
1 change: 0 additions & 1 deletion public/pages/DataStreams/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const DEFAULT_QUERY_PARAMS = {
sortField: "name" as keyof DataStream,
sortDirection: SortDirection.DESC,
dataSourceId: "",
dataSourceLabel: "",
};

export const HEALTH_TO_COLOR: {
Expand Down
3 changes: 0 additions & 3 deletions public/pages/Indices/containers/Indices/Indices.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function renderWithRouter(
Component: React.ComponentType<any>,
data: DataSourceMenuProperties = {
dataSourceId: "",
dataSourceLabel: "",
multiDataSourceEnabled: false,
},
renderFn = render
Expand Down Expand Up @@ -264,7 +263,6 @@ describe("re-render on data-source-id prop change", () => {

const { getByText, queryByText, rerender } = renderWithRouter(Indices, {
dataSourceId: "test_data_source_id",
dataSourceLabel: "test_data_source_label",
multiDataSourceEnabled: true,
});

Expand All @@ -276,7 +274,6 @@ describe("re-render on data-source-id prop change", () => {
Indices,
{
dataSourceId: "test_data_source_id_2",
dataSourceLabel: "test_data_source_label_2",
multiDataSourceEnabled: true,
},
rerender
Expand Down
4 changes: 3 additions & 1 deletion public/pages/Indices/containers/Indices/Indices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ export class Indices extends MDSEnabledComponent<IndicesProps, IndicesState> {
try {
const { indexService, history } = this.props;
const queryObject = this.getQueryObjectFromState(this.state);
const queryParamsString = queryString.stringify({ ...queryObject, dataSourceLabel: this.state.dataSourceLabel });
const queryParamsString = queryString.stringify({
...queryObject,
});
history.replace({ ...this.props.location, search: queryParamsString });

const getIndicesResponse = await indexService.getIndices({
Expand Down
956 changes: 500 additions & 456 deletions public/pages/Main/Main.tsx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/pages/Rollups/containers/Rollups/Rollups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default class Rollups extends Component<RollupsProps, RollupsState> {
try {
const { rollupService, history } = this.props;
const queryObject = Rollups.getQueryObjectFromState(this.state);
const queryParamsString = queryString.stringify(Rollups.getQueryObjectFromState(this.state));
const queryParamsString = queryString.stringify(queryObject);
history.replace({ ...this.props.location, search: queryParamsString });
const rollupJobsResponse = await rollupService.getRollups(queryObject);
if (rollupJobsResponse.ok) {
Expand Down
1 change: 0 additions & 1 deletion public/pages/Templates/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ export const DEFAULT_QUERY_PARAMS = {
sortField: "name" as keyof ITemplate,
sortDirection: SortDirection.DESC,
dataSourceId: "",
dataSourceLabel: "",
};
2 changes: 0 additions & 2 deletions public/services/DataSourceMenuContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import { createContext } from "react";

export interface DataSourceMenuProperties {
dataSourceId: string;
dataSourceLabel: string;
multiDataSourceEnabled: boolean;
}

const DataSourceMenuContext = createContext<DataSourceMenuProperties>({
dataSourceId: "",
dataSourceLabel: "",
multiDataSourceEnabled: false,
});

Expand Down

0 comments on commit 18dbfb0

Please sign in to comment.