Skip to content

Commit

Permalink
refactor to add config
Browse files Browse the repository at this point in the history
Signed-off-by: Lu Yu <[email protected]>
  • Loading branch information
BionIT committed Mar 26, 2024
1 parent 374707a commit e726972
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { DataSourceSelectable } from './data_source_selectable';
import { DataSourceAggregatedView } from '../data_source_aggregated_view';
import { DataSourceView } from '../data_source_view';
import { DataSourceMultiSelectable } from '../data_source_multi_selectable/data_source_multi_selectable';
import { DataSourceAttributes } from '../../types';
import {
DataSourceAggregatedViewConfig,
DataSourceComponentType,
DataSourceMenuProps,
DataSourceMultiSelectableConfig,
DataSourceSelectableConfig,
DataSourceViewConfig,
} from './types';
Expand All @@ -31,21 +31,27 @@ export function DataSourceMenu<T>(props: DataSourceMenuProps<T>): ReactElement |
);
}

function renderDataSourceMultiSelectable(config: string): ReactElement | null {
function renderDataSourceMultiSelectable(
config: DataSourceMultiSelectableConfig
): ReactElement | null {
const {
fullWidth,
hideLocalCluster,
savedObjects,
notifications,
onSelectedDataSources,
} = config;
return (

Check warning on line 44 in src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx#L43-L44

Added lines #L43 - L44 were not covered by tests
<EuiHeaderLinks data-test-subj="top-nav" gutterSize="xs" className={className}>
<DataSourceMultiSelectable
fullWidth={fullWidth}
hideLocalCluster={hideLocalCluster || false}
savedObjectsClient={savedObjects!}
notifications={notifications!.toasts}
onSelectedDataSources={onDataSourcesSelectionChange!}
/>
</EuiHeaderLinks>
<DataSourceMultiSelectable
fullWidth={fullWidth}
hideLocalCluster={hideLocalCluster || false}
savedObjectsClient={savedObjects!}
notifications={notifications!.toasts}
onSelectedDataSources={onSelectedDataSources!}
/>
);
}


function renderDataSourceSelectable(config: DataSourceSelectableConfig): ReactElement | null {
const {
onSelectedDataSources,
Expand Down Expand Up @@ -96,7 +102,6 @@ export function DataSourceMenu<T>(props: DataSourceMenuProps<T>): ReactElement |
);
}


function renderLayout(): ReactElement | null {
switch (componentType) {
case DataSourceComponentType.DataSourceAggregatedView:
Expand All @@ -105,6 +110,8 @@ export function DataSourceMenu<T>(props: DataSourceMenuProps<T>): ReactElement |
return renderDataSourceSelectable(componentConfig as DataSourceSelectableConfig);
case DataSourceComponentType.DataSourceView:
return renderDataSourceView(componentConfig as DataSourceViewConfig);
case DataSourceComponentType.DataSourceMultiSelectable:
return renderDataSourceMultiSelectable(componentConfig as DataSourceMultiSelectableConfig);

Check warning on line 114 in src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx#L114

Added line #L114 was not covered by tests
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export {
DataSourceComponentType,
DataSourceViewConfig,
DataSourceMenuProps,
DataSourceMultiSelectableConfig,
} from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const DataSourceComponentType = {
DataSourceSelectable: 'DataSourceSelectable',
DataSourceView: 'DataSourceView',
DataSourceAggregatedView: 'DataSourceAggregatedView',
DataSourceMultiSelectable: 'DataSourceMultiSelectable',
} as const;

export type DataSourceComponentType = typeof DataSourceComponentType[keyof typeof DataSourceComponentType];
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data_source_management/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export {
DataSourceAggregatedViewConfig,
DataSourceViewConfig,
DataSourceMenuProps,
DataSourceMultiSelectableConfig,
} from './components/data_source_menu';

0 comments on commit e726972

Please sign in to comment.