Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable non index pattern datasources redirection when new nav is on and query enhancement is off #7584

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
defaultDataSourceMetadata,
s3DataSourceMetadata,
} from '../constants';
import { IUiSettingsClient } from '../../../../../../src/core/public';

describe('DataSourceSelectable', () => {
let dataSourcesMock: DataSource[];
Expand All @@ -23,6 +24,7 @@ describe('DataSourceSelectable', () => {
let setSelectedSourcesMock: (sources: DataSourceOption[]) => void = jest.fn();
let setDataSourceOptionListMock: (sources: DataSourceGroup[]) => void = jest.fn();
let onFetchDataSetErrorMock: (error: Error) => void = jest.fn();
let uiSettingsMock: IUiSettingsClient;
const onRefresh: () => void = jest.fn();

beforeEach(() => {
Expand All @@ -46,6 +48,27 @@ describe('DataSourceSelectable', () => {
setSelectedSourcesMock = jest.fn();
setDataSourceOptionListMock = jest.fn();
onFetchDataSetErrorMock = jest.fn();
uiSettingsMock = {
get: jest.fn().mockImplementation((key) => {
switch (key) {
case 'home:useNewHomePage':
return true; // or false based on your test case
case 'query:enhancements:enabled':
return true; // or false based on your test case
default:
return undefined;
}
}),
get$: jest.fn(),
getAll: jest.fn(),
set: jest.fn(),
overrideLocalDefault: jest.fn(),
remove: jest.fn(),
removeMany: jest.fn(),
isDeclared: jest.fn(),
isDefault: jest.fn(),
isCustom: jest.fn(),
};
});

it('renders without crashing', () => {
Expand All @@ -58,6 +81,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);
});
Expand All @@ -73,6 +97,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);
});
Expand All @@ -93,6 +118,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);
});
Expand Down Expand Up @@ -131,6 +157,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);

Expand Down Expand Up @@ -183,6 +210,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);

Expand Down Expand Up @@ -235,6 +263,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);

Expand All @@ -259,6 +288,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);
const refreshButton = getByLabelText('sourceRefresh');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,13 @@
onGetDataSetError, // onGetDataSetError, Callback for handling get data set errors. Ensure it's memoized.
singleSelection = { asPlainText: true },
onRefresh,
uiSettings,
...comboBoxProps
}: DataSourceSelectableProps) => {
// This effect gets data sets and prepares the datasource list for UI rendering.
useEffect(() => {
const newHomePageEnabled = uiSettings.get('home:useNewHomePage');
const queryEnhancementsEnabled = uiSettings.get('query:enhancements:enabled');

Check warning on line 132 in src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx#L131-L132

Added lines #L131 - L132 were not covered by tests
Promise.all(
getAllDataSets(
dataSources.filter((ds) => ds.getMetadata().ui.selector.displayDatasetsAsSource)
Expand All @@ -136,12 +139,14 @@
setDataSourceOptionList(
consolidateDataSourceGroups(
dataSetResults as DataSetWithDataSource[],
dataSources.filter((ds) => !ds.getMetadata().ui.selector.displayDatasetsAsSource)
newHomePageEnabled && !queryEnhancementsEnabled
? []
: dataSources.filter((ds) => !ds.getMetadata().ui.selector.displayDatasetsAsSource)

Check warning on line 144 in src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx#L144

Added line #L144 was not covered by tests
)
);
})
.catch((e) => onGetDataSetError(e));
}, [dataSources, setDataSourceOptionList, onGetDataSetError]);
}, [dataSources, setDataSourceOptionList, onGetDataSetError, uiSettings]);

const handleSourceChange = useCallback(
(selectedOptions: any) => onDataSourceSelect(selectedOptions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import { EuiComboBoxProps, EuiComboBoxSingleSelectionShape } from '@elastic/eui';
import { IUiSettingsClient } from 'opensearch-dashboards/public';
import { DataSource } from '../datasource/datasource';

export interface DataSourceGroup {
Expand Down Expand Up @@ -35,4 +36,5 @@ export interface DataSourceSelectableProps extends Pick<EuiComboBoxProps<unknown
selectedSources: DataSourceOption[];
setDataSourceOptionList: (dataSourceList: DataSourceGroup[]) => void;
onRefresh: () => void;
uiSettings: IUiSettingsClient;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const Sidebar: FC = ({ children }) => {
data: { indexPatterns, dataSources, ui },
notifications: { toasts },
application,
uiSettings,
},
} = useOpenSearchDashboards<DataExplorerServices>();

Expand Down Expand Up @@ -168,6 +169,7 @@ export const Sidebar: FC = ({ children }) => {
selectedSources={selectedSources}
onGetDataSetError={handleGetDataSetError}
onRefresh={memorizedReload}
uiSettings={uiSettings}
fullWidth
/>
</EuiSplitPanel.Inner>
Expand Down
Loading