Skip to content

Commit

Permalink
Add auto-suggestions for skipping index definition and export types (o…
Browse files Browse the repository at this point in the history
…pensearch-project#1552) (opensearch-project#1569)

* add generate modal and status check for workbench



* remove debug logs



* expose types for cachemanager



* rebase changes



---------


(cherry picked from commit 6dfafbd)

Signed-off-by: Shenoy Pratik <[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>
Co-authored-by: Shenoy Pratik <[email protected]>
  • Loading branch information
3 people authored Mar 19, 2024
1 parent e916ef2 commit dc0245f
Show file tree
Hide file tree
Showing 25 changed files with 902 additions and 472 deletions.
1 change: 1 addition & 0 deletions common/constants/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const observabilityDataConnectionsTitle = 'Data sources';
export const observabilityDataConnectionsPluginOrder = 9030;

export const queryWorkbenchPluginID = 'opensearch-query-workbench';
export const queryWorkbenchPluginCheck = 'plugin:queryWorkbenchDashboards';

// Shared Constants
export const SQL_DOCUMENTATION_URL = 'https://opensearch.org/docs/latest/search-plugins/sql/index/';
Expand Down
7 changes: 7 additions & 0 deletions common/types/data_connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { EuiComboBoxOptionOption } from '@elastic/eui';
import { DirectQueryLoadingStatus } from './explorer';

export type AccelerationStatus = 'ACTIVE' | 'INACTIVE';

Expand Down Expand Up @@ -233,3 +234,9 @@ export interface CreateAccelerationForm {
refreshIntervalOptions: RefreshIntervalType;
formErrors: FormErrorsType;
}

export interface LoadCachehookOutput {
loadStatus: DirectQueryLoadingStatus;
startLoading: (dataSourceName: string, databaseName?: string, tableName?: string) => void;
stopLoading: () => void;
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,24 @@ import Adapter from 'enzyme-adapter-react-16';
import toJson from 'enzyme-to-json';
import React from 'react';
import { coreMock } from '../../../../../../../../../../../src/core/public/mocks';
import { queryWorkbenchPluginCheck } from '../../../../../../../../../common/constants/shared';
import { mockDatasourcesQuery } from '../../../../../../../../../test/accelerations';
import { CreateAcceleration } from '../create_acceleration';

const coreStartMock = coreMock.createStart();

// @ts-ignore
global.fetch = jest.fn(() =>
Promise.resolve({
json: () =>
Promise.resolve({
status: {
statuses: [{ id: queryWorkbenchPluginCheck }],
},
}),
})
);

describe('Create acceleration flyout components', () => {
configure({ adapter: new Adapter() });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,24 @@ describe('validateReplicaCount', () => {

describe('validateRefreshInterval', () => {
it('should return an array with an error message when refreshType is "interval" and refreshWindow is less than 1', () => {
expect(validateRefreshInterval('interval', 0)).toEqual([
expect(validateRefreshInterval('autoInterval', 0)).toEqual([
'refresh window should be greater than 0',
]);
expect(validateRefreshInterval('interval', -1)).toEqual([
expect(validateRefreshInterval('autoInterval', -1)).toEqual([
'refresh window should be greater than 0',
]);
expect(validateRefreshInterval('interval', -10)).toEqual([
expect(validateRefreshInterval('autoInterval', -10)).toEqual([
'refresh window should be greater than 0',
]);
});

it('should return an empty array when refreshType is not "interval" or when refreshWindow is greater than or equal to 1', () => {
expect(validateRefreshInterval('auto', 0)).toEqual([]);
expect(validateRefreshInterval('auto', 1)).toEqual([]);
expect(validateRefreshInterval('interval', 1)).toEqual([]);
expect(validateRefreshInterval('auto', 5)).toEqual([]);
expect(validateRefreshInterval('autoInterval', 1)).toEqual([]);
expect(validateRefreshInterval('autoInterval', 5)).toEqual([]);
expect(validateRefreshInterval('manual', 0)).toEqual([]);
expect(validateRefreshInterval('manualIncrement', 0)).toEqual([]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ export const CreateAcceleration = ({
},
});
const [tableFieldsLoading, setTableFieldsLoading] = useState(false);
const { loadStatus, startLoading } = useLoadTableColumnsToCache();
const {
loadStatus,
startLoading,
stopLoading: stopLoadingTableFields,
} = useLoadTableColumnsToCache();

const loadColumnsToAccelerationForm = (cachedTable: CachedTable) => {
const idPrefix = htmlIdGenerator()();
Expand All @@ -117,6 +121,7 @@ export const CreateAcceleration = ({
...accelerationFormData,
dataTableFields: [],
});
stopLoadingTableFields();
if (dataTable !== '') {
setTableFieldsLoading(true);
const cachedTable = CatalogCacheManager.getTable(dataSource, database, dataTable);
Expand Down Expand Up @@ -179,6 +184,7 @@ export const CreateAcceleration = ({
setAccelerationFormData={setAccelerationFormData}
selectedDatasource={selectedDatasource}
dataSourcesPreselected={dataSourcesPreselected}
tableFieldsLoading={tableFieldsLoading}
/>
<EuiSpacer size="xxl" />
<IndexTypeSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const validateRefreshInterval = (
refreshType: AccelerationRefreshType,
refreshWindow: number
) => {
return refreshType !== 'auto' && refreshType !== 'manual' && refreshWindow < 1
return refreshType === 'autoInterval' && refreshWindow < 1
? ['refresh window should be greater than 0']
: [];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,43 +90,7 @@ exports[`Preview SQL acceleration components renders Preview SQL settings with d
</div>
<div
className="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
className="euiButton euiButton--primary"
disabled={false}
style={
Object {
"minWidth": undefined,
}
}
type="button"
>
<span
className="euiButtonContent euiButtonContent--iconRight euiButton__content"
>
<svg
aria-hidden={true}
className="euiIcon euiIcon--medium euiIcon--inherit euiButtonContent__icon"
focusable="false"
height={16}
role="img"
style={null}
viewBox="0 0 16 16"
width={16}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M13 8.5a.5.5 0 1 1 1 0V12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h3.5a.5.5 0 0 1 0 1H4a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V8.5Zm-5.12.339a.5.5 0 1 1-.706-.707L13.305 2H10.5a.5.5 0 1 1 0-1H14a1 1 0 0 1 1 1v3.5a.5.5 0 1 1-1 0V2.72L7.88 8.838Z"
/>
</svg>
<span
className="euiButton__text"
>
Open in Query Workbench
</span>
</span>
</button>
</div>
/>
</div>
<div
className="euiSpacer euiSpacer--l"
Expand Down Expand Up @@ -240,43 +204,7 @@ exports[`Preview SQL acceleration components renders Preview SQL settings with d
</div>
<div
className="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
className="euiButton euiButton--primary"
disabled={false}
style={
Object {
"minWidth": undefined,
}
}
type="button"
>
<span
className="euiButtonContent euiButtonContent--iconRight euiButton__content"
>
<svg
aria-hidden={true}
className="euiIcon euiIcon--medium euiIcon--inherit euiIcon-isLoading euiButtonContent__icon"
focusable="false"
height={16}
role="img"
style={null}
viewBox="0 0 16 16"
width={16}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M5.277 10.088c.02.014.04.03.057.047.582.55 1.134.812 1.666.812.586 0 1.84-.293 3.713-.88L9 6.212V2H7v4.212l-1.723 3.876Zm-.438.987L3.539 14h8.922l-1.32-2.969C9.096 11.677 7.733 12 7 12c-.74 0-1.463-.315-2.161-.925ZM6 2H5V1h6v1h-1v4l3.375 7.594A1 1 0 0 1 12.461 15H3.54a1 1 0 0 1-.914-1.406L6 6V2Z"
/>
</svg>
<span
className="euiButton__text"
>
Open in Query Workbench
</span>
</span>
</button>
</div>
/>
</div>
<div
className="euiSpacer euiSpacer--l"
Expand Down Expand Up @@ -391,43 +319,7 @@ exports[`Preview SQL acceleration components renders Preview SQL settings with e
</div>
<div
className="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
className="euiButton euiButton--primary"
disabled={false}
style={
Object {
"minWidth": undefined,
}
}
type="button"
>
<span
className="euiButtonContent euiButtonContent--iconRight euiButton__content"
>
<svg
aria-hidden={true}
className="euiIcon euiIcon--medium euiIcon--inherit euiButtonContent__icon"
focusable="false"
height={16}
role="img"
style={null}
viewBox="0 0 16 16"
width={16}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M13 8.5a.5.5 0 1 1 1 0V12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h3.5a.5.5 0 0 1 0 1H4a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V8.5Zm-5.12.339a.5.5 0 1 1-.706-.707L13.305 2H10.5a.5.5 0 1 1 0-1H14a1 1 0 0 1 1 1v3.5a.5.5 0 1 1-1 0V2.72L7.88 8.838Z"
/>
</svg>
<span
className="euiButton__text"
>
Open in Query Workbench
</span>
</span>
</button>
</div>
/>
</div>
<div
className="euiSpacer euiSpacer--l"
Expand Down Expand Up @@ -542,43 +434,7 @@ exports[`Preview SQL acceleration components renders Preview SQL settings with m
</div>
<div
className="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
className="euiButton euiButton--primary"
disabled={false}
style={
Object {
"minWidth": undefined,
}
}
type="button"
>
<span
className="euiButtonContent euiButtonContent--iconRight euiButton__content"
>
<svg
aria-hidden={true}
className="euiIcon euiIcon--medium euiIcon--inherit euiButtonContent__icon"
focusable="false"
height={16}
role="img"
style={null}
viewBox="0 0 16 16"
width={16}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M13 8.5a.5.5 0 1 1 1 0V12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h3.5a.5.5 0 0 1 0 1H4a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V8.5Zm-5.12.339a.5.5 0 1 1-.706-.707L13.305 2H10.5a.5.5 0 1 1 0-1H14a1 1 0 0 1 1 1v3.5a.5.5 0 1 1-1 0V2.72L7.88 8.838Z"
/>
</svg>
<span
className="euiButton__text"
>
Open in Query Workbench
</span>
</span>
</button>
</div>
/>
</div>
<div
className="euiSpacer euiSpacer--l"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Array [
<input
aria-controls=""
data-test-subj="comboBoxSearchInput"
disabled={false}
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -138,6 +139,7 @@ Array [
aria-label="Open list of options"
className="euiFormControlLayoutCustomIcon euiFormControlLayoutCustomIcon--clickable"
data-test-subj="comboBoxToggleListButton"
disabled={false}
onClick={[Function]}
type="button"
>
Expand Down Expand Up @@ -261,6 +263,7 @@ Array [
<input
aria-controls=""
data-test-subj="comboBoxSearchInput"
disabled={false}
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -295,6 +298,7 @@ Array [
aria-label="Open list of options"
className="euiFormControlLayoutCustomIcon euiFormControlLayoutCustomIcon--clickable"
data-test-subj="comboBoxToggleListButton"
disabled={false}
onClick={[Function]}
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { configure, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import toJson from 'enzyme-to-json';
import React from 'react';
import { queryWorkbenchPluginCheck } from '../../../../../../../../../common/constants/shared';
import { CreateAccelerationForm } from '../../../../../../../../../common/types/data_connections';
import {
coveringIndexBuilderMock1,
Expand All @@ -16,6 +17,18 @@ import {
} from '../../../../../../../../../test/accelerations';
import { PreviewSQLDefinition } from '../preview_sql_defintion';

// @ts-ignore
global.fetch = jest.fn(() =>
Promise.resolve({
json: () =>
Promise.resolve({
status: {
statuses: [{ id: queryWorkbenchPluginCheck }],
},
}),
})
);

describe('Preview SQL acceleration components', () => {
configure({ adapter: new Adapter() });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('Source selector components', () => {
accelerationFormData={accelerationFormData}
setAccelerationFormData={setAccelerationFormData}
dataSourcesPreselected={false}
tableFieldsLoading={false}
/>
);
wrapper.update();
Expand Down Expand Up @@ -67,6 +68,7 @@ describe('Source selector components', () => {
accelerationFormData={accelerationFormData}
setAccelerationFormData={setAccelerationFormData}
dataSourcesPreselected={true}
tableFieldsLoading={false}
/>
);
wrapper.update();
Expand Down
Loading

0 comments on commit dc0245f

Please sign in to comment.