Skip to content

Commit

Permalink
select default on load; re-order router paths (opensearch-project#1036)…
Browse files Browse the repository at this point in the history
… (opensearch-project#1038)

(cherry picked from commit cfafb3d)

Signed-off-by: Amardeepsingh Siglani <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 543e478 commit b0193a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
62 changes: 33 additions & 29 deletions public/components/MDS/DataSourceMenuWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export interface DataSourceMenuWrapperProps {
core: CoreStart;
dataSourceManagement?: DataSourceManagementPluginSetup;
dataSourceMenuReadOnly: boolean;
dataSourceLoading: boolean;
setHeaderActionMenu: AppMountParameters['setHeaderActionMenu'];
}

export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
core,
dataSourceManagement,
dataSourceMenuReadOnly,
dataSourceLoading,
setHeaderActionMenu,
}) => {
if (!dataSourceManagement) {
Expand All @@ -39,6 +41,8 @@ export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
DataSourceSelectableConfig
>();

const activeOption = dataSourceLoading ? undefined : [dataSource];

return (
<Switch>
<Route
Expand Down Expand Up @@ -67,9 +71,35 @@ export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
);
}}
/>
<Route
path={[ROUTES.DETECTORS_CREATE]}
render={() => {
return dataSourceMenuReadOnly ? (
<DataSourceMenuViewComponent
componentConfig={{
fullWidth: false,
activeOption: [dataSource],
}}
componentType="DataSourceView"
setMenuMountPoint={setHeaderActionMenu}
/>
) : (
<DataSourceMenuSelectableComponent
componentType="DataSourceSelectable"
setMenuMountPoint={setHeaderActionMenu}
componentConfig={{
fullWidth: false,
activeOption,
notifications: core.notifications,
onSelectedDataSources: setDataSource,
savedObjects: core.savedObjects.client,
}}
/>
);
}}
/>
<Route
path={[
ROUTES.ROOT,
ROUTES.OVERVIEW,
ROUTES.DETECTORS,
ROUTES.ALERTS,
Expand All @@ -83,6 +113,7 @@ export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
ROUTES.RULES_DUPLICATE,
ROUTES.LOG_TYPES_CREATE,
ROUTES.CORRELATION_RULE_CREATE,
ROUTES.ROOT,
]}
render={() => {
return (
Expand All @@ -91,34 +122,7 @@ export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
setMenuMountPoint={setHeaderActionMenu}
componentConfig={{
fullWidth: false,
activeOption: [dataSource],
notifications: core.notifications,
onSelectedDataSources: setDataSource,
savedObjects: core.savedObjects.client,
}}
/>
);
}}
/>
<Route
path={[ROUTES.DETECTORS_CREATE]}
render={() => {
return dataSourceMenuReadOnly ? (
<DataSourceMenuViewComponent
componentConfig={{
fullWidth: false,
activeOption: [dataSource],
}}
componentType="DataSourceView"
setMenuMountPoint={setHeaderActionMenu}
/>
) : (
<DataSourceMenuSelectableComponent
componentType="DataSourceSelectable"
setMenuMountPoint={setHeaderActionMenu}
componentConfig={{
fullWidth: false,
activeOption: [dataSource],
activeOption,
notifications: core.notifications,
onSelectedDataSources: setDataSource,
savedObjects: core.savedObjects.client,
Expand Down
1 change: 1 addition & 0 deletions public/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ export default class Main extends Component<MainProps, MainState> {
<DataSourceMenuWrapper
dataSourceManagement={dataSourceManagement}
core={core}
dataSourceLoading={this.state.dataSourceLoading}
dataSourceMenuReadOnly={dataSourceMenuReadOnly}
setHeaderActionMenu={setActionMenu}
/>
Expand Down

0 comments on commit b0193a4

Please sign in to comment.