Skip to content

Commit

Permalink
Merge branch 'main' into new-core-plugin-to-dynamic-content-rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanyl authored Jul 19, 2024
2 parents 7323272 + 5741fd7 commit 92fc98d
Show file tree
Hide file tree
Showing 21 changed files with 132 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cypress_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ env:
TEST_REPO: ${{ inputs.test_repo != '' && inputs.test_repo || 'opensearch-project/opensearch-dashboards-functional-test' }}
TEST_BRANCH: "${{ inputs.test_branch != '' && inputs.test_branch || github.base_ref }}"
FTR_PATH: 'ftr'
START_CMD: 'node ../scripts/opensearch_dashboards --dev --no-base-path --no-watch --savedObjects.maxImportPayloadBytes=10485760 --server.maxPayloadBytes=1759977 --logging.json=false --data.search.aggs.shardDelay.enabled=true --csp.warnLegacyBrowsers=false'
START_CMD: 'node ../scripts/opensearch_dashboards --dev --no-base-path --no-watch --savedObjects.maxImportPayloadBytes=10485760 --server.maxPayloadBytes=1759977 --logging.json=false --data.search.aggs.shardDelay.enabled=true --csp.warnLegacyBrowsers=false --uiSettings.overrides["query:enhancements:enabled"]=false'
OPENSEARCH_SNAPSHOT_CMD: 'node ../scripts/opensearch snapshot -E cluster.routing.allocation.disk.threshold_enabled=false'
CYPRESS_BROWSER: 'chromium'
CYPRESS_VISBUILDER_ENABLED: true
Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/7314.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Unused config setting and remove data sources as a required plugin. ([#7314](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7314))
2 changes: 2 additions & 0 deletions changelogs/fragments/7318.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- [Workspace]Add "All use case" option to workspace form ([#7318](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7318))
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"start": "scripts/use_node scripts/opensearch_dashboards --dev",
"start:docker": "scripts/use_node scripts/opensearch_dashboards --dev --opensearch.hosts=$OPENSEARCH_HOSTS --opensearch.ignoreVersionMismatch=true --server.host=$SERVER_HOST",
"start:security": "scripts/use_node scripts/opensearch_dashboards --dev --security",
"start:enhancements": "scripts/use_node scripts/opensearch_dashboards --dev --data_source.enabled=true --uiSettings.overrides['query:enhancements:enabled']=true",
"start:enhancements": "scripts/use_node scripts/opensearch_dashboards --dev --uiSettings.overrides['query:enhancements:enabled']=true",
"debug": "scripts/use_node --nolazy --inspect scripts/opensearch_dashboards --dev",
"debug-break": "scripts/use_node --nolazy --inspect-brk scripts/opensearch_dashboards --dev",
"lint": "yarn run lint:es && yarn run lint:style",
Expand Down
11 changes: 1 addition & 10 deletions src/plugins/data/public/ui/query_editor/query_editor_top_row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,7 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
}

function isValidQuery(query: Query | undefined) {
if (!query || !query.query) return false;
return (
!Array.isArray(props.indexPatterns!) ||
compact(props.indexPatterns!).length === 0 ||
fromUser(query!.query).includes(
typeof props.indexPatterns[0] === 'string'
? props.indexPatterns[0]
: props.indexPatterns[0].title
)
);
if (query && query.query) return true;
}

function getQueryStringInitialValue(language: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/ui/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Settings {
private readonly queryEnhancements: Map<string, QueryEnhancement>,
private readonly queryEditorExtensionMap: Record<string, QueryEditorExtensionConfig>
) {
this.isEnabled = false;
this.isEnabled = true;
this.setUserQueryEnhancementsEnabled(this.isEnabled);
this.enhancedAppNames = this.isEnabled ? this.config.supportedAppNames : [];
}
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/ui/ui_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class UiService implements Plugin<IUiSetup, IUiStart> {
return {
__enhance: (enhancements?: UiEnhancements) => {
if (!enhancements) return;
if (!this.enhancementsConfig.enabled) return;
if (enhancements.query && enhancements.query.language) {
this.queryEnhancements.set(enhancements.query.language, enhancements.query);
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ export function getUiSettings(): Record<string, UiSettingsParams<unknown>> {
name: i18n.translate('data.advancedSettings.query.enhancements.enableTitle', {
defaultMessage: 'Enable query enhancements',
}),
value: false,
value: true,
description: i18n.translate('data.advancedSettings.query.enhancements.enableText', {
defaultMessage: `
<strong>Experimental</strong>:
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/query_enhancements/opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "opensearchDashboards",
"server": true,
"ui": true,
"requiredPlugins": ["data", "opensearchDashboardsReact", "opensearchDashboardsUtils", "dataSource", "dataSourceManagement", "savedObjects", "uiActions"],
"optionalPlugins": []
"requiredPlugins": ["data", "opensearchDashboardsReact", "opensearchDashboardsUtils", "dataSourceManagement", "savedObjects", "uiActions"],
"optionalPlugins": ["dataSource"]
}

Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,17 @@ describe('useWorkspaceForm', () => {
})
);
});
it('should update selected use case', () => {
const { renderResult } = setup({
id: 'foo',
name: 'test-workspace-name',
features: ['use-case-observability'],
});

expect(renderResult.result.current.formData.useCase).toBe('observability');
act(() => {
renderResult.result.current.handleUseCaseChange('search');
});
expect(renderResult.result.current.formData.useCase).toBe('search');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {

import { useApplications } from '../../hooks';
import {
getFirstUseCaseOfFeatureConfigs,
getUseCaseFeatureConfig,
getUseCaseFromFeatureConfig,
isUseCaseFeatureConfig,
} from '../../utils';
import { DataSource } from '../../../common/types';
Expand All @@ -30,8 +30,6 @@ import { WorkspacePermissionItemType } from './constants';

const workspaceHtmlIdGenerator = htmlIdGenerator();

const isNotNull = <T extends unknown>(value: T | null): value is T => !!value;

export const useWorkspaceForm = ({
application,
defaultValues,
Expand All @@ -51,10 +49,9 @@ export const useWorkspaceForm = ({
const [featureConfigs, setFeatureConfigs] = useState(
appendDefaultFeatureIds(defaultValues?.features ?? [])
);
const selectedUseCases = useMemo(
() => featureConfigs.map(getUseCaseFromFeatureConfig).filter(isNotNull),
[featureConfigs]
);
const selectedUseCase = useMemo(() => getFirstUseCaseOfFeatureConfigs(featureConfigs), [
featureConfigs,
]);
const [permissionSettings, setPermissionSettings] = useState<
Array<Pick<WorkspacePermissionSetting, 'id'> & Partial<WorkspacePermissionSetting>>
>(initialPermissionSettingsRef.current);
Expand All @@ -72,7 +69,7 @@ export const useWorkspaceForm = ({
name,
description,
features: featureConfigs,
useCases: selectedUseCases,
useCase: selectedUseCase,
color,
permissionSettings,
selectedDataSources,
Expand All @@ -92,14 +89,14 @@ export const useWorkspaceForm = ({
formIdRef.current = workspaceHtmlIdGenerator();
}

const handleUseCasesChange = useCallback(
(newUseCases: string[]) => {
const handleUseCaseChange = useCallback(
(newUseCase: string) => {
setFeatureConfigs((previousFeatureConfigs) => {
return [
...previousFeatureConfigs.filter(
(featureConfig) => !isUseCaseFeatureConfig(featureConfig)
),
...newUseCases.map((useCaseItem) => getUseCaseFeatureConfig(useCaseItem)),
getUseCaseFeatureConfig(newUseCase),
];
});
},
Expand Down Expand Up @@ -157,7 +154,7 @@ export const useWorkspaceForm = ({
numberOfChanges,
handleFormSubmit,
handleColorChange,
handleUseCasesChange,
handleUseCaseChange,
handleNameInputChange,
setPermissionSettings,
setSelectedDataSources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const WorkspaceDetailForm = (props: WorkspaceFormProps) => {
numberOfChanges,
handleFormSubmit,
handleColorChange,
handleUseCasesChange,
handleUseCaseChange,
setPermissionSettings,
handleNameInputChange,
setSelectedDataSources,
Expand Down Expand Up @@ -109,8 +109,8 @@ export const WorkspaceDetailForm = (props: WorkspaceFormProps) => {

<FormGroup title={workspaceUseCaseTitle}>
<WorkspaceUseCase
value={formData.useCases}
onChange={handleUseCasesChange}
value={formData.useCase}
onChange={handleUseCaseChange}
formErrors={formErrors}
availableUseCases={availableUseCases}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const WorkspaceForm = (props: WorkspaceFormProps) => {
numberOfChanges,
handleFormSubmit,
handleColorChange,
handleUseCasesChange,
handleUseCaseChange,
handleNameInputChange,
setPermissionSettings,
setSelectedDataSources,
Expand Down Expand Up @@ -85,8 +85,8 @@ export const WorkspaceForm = (props: WorkspaceFormProps) => {
</EuiTitle>
<EuiSpacer size="s" />
<WorkspaceUseCase
value={formData.useCases}
onChange={handleUseCasesChange}
value={formData.useCase}
onChange={handleUseCaseChange}
formErrors={formErrors}
availableUseCases={availableUseCases}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ const setup = (options?: Partial<WorkspaceUseCaseProps>) => {
id: 'system-use-case',
title: 'System use case',
description: 'System use case description',
features: [],
systematic: true,
},
]}
value={[]}
value=""
onChange={onChangeMock}
formErrors={formErrors}
{...options}
Expand All @@ -49,19 +48,19 @@ describe('WorkspaceUseCase', () => {
expect(renderResult.getByText('Search')).toBeInTheDocument();
});

it('should call onChange with new added use case', () => {
it('should call onChange with new checked use case', () => {
const { renderResult, onChangeMock } = setup();

expect(onChangeMock).not.toHaveBeenCalled();
fireEvent.click(renderResult.getByText('Observability'));
expect(onChangeMock).toHaveBeenLastCalledWith(['observability']);
expect(onChangeMock).toHaveBeenLastCalledWith('observability');
});

it('should call onChange without removed use case', () => {
const { renderResult, onChangeMock } = setup({ value: ['observability'] });
it('should not call onChange after checked use case clicked', () => {
const { renderResult, onChangeMock } = setup({ value: 'observability' });

expect(onChangeMock).not.toHaveBeenCalled();
fireEvent.click(renderResult.getByText('Observability'));
expect(onChangeMock).toHaveBeenLastCalledWith([]);
expect(onChangeMock).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import React, { useCallback } from 'react';
import { i18n } from '@osd/i18n';
import { EuiCheckableCard, EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiText } from '@elastic/eui';

import { DEFAULT_NAV_GROUPS } from '../../../../../core/public';
import { WorkspaceUseCase as WorkspaceUseCaseObject } from '../../types';
import { WorkspaceFormErrors } from './types';
import './workspace_use_case.scss';
Expand All @@ -31,7 +33,7 @@ const WorkspaceUseCaseCard = ({
return (
<EuiCheckableCard
id={id}
checkableType="checkbox"
checkableType="radio"
style={{ height: '100%' }}
label={title}
checked={checked}
Expand All @@ -47,10 +49,12 @@ const WorkspaceUseCaseCard = ({
};

export interface WorkspaceUseCaseProps {
value: string[];
onChange: (newValue: string[]) => void;
value: string | undefined;
onChange: (newValue: string) => void;
formErrors: WorkspaceFormErrors;
availableUseCases: WorkspaceUseCaseObject[];
availableUseCases: Array<
Pick<WorkspaceUseCaseObject, 'id' | 'title' | 'description' | 'systematic'>
>;
}

export const WorkspaceUseCase = ({
Expand All @@ -59,17 +63,6 @@ export const WorkspaceUseCase = ({
formErrors,
availableUseCases,
}: WorkspaceUseCaseProps) => {
const handleCardChange = useCallback(
(id: string) => {
if (!value.includes(id)) {
onChange([...value, id]);
return;
}
onChange(value.filter((item) => item !== id));
},
[value, onChange]
);

return (
<EuiFormRow
label={i18n.translate('workspace.form.workspaceUseCase.name.label', {
Expand All @@ -82,14 +75,15 @@ export const WorkspaceUseCase = ({
<EuiFlexGroup>
{availableUseCases
.filter((item) => !item.systematic)
.concat(DEFAULT_NAV_GROUPS.all)
.map(({ id, title, description }) => (
<EuiFlexItem key={id}>
<WorkspaceUseCaseCard
id={id}
title={title}
description={description}
checked={value.includes(id)}
onChange={handleCardChange}
checked={value === id}
onChange={onChange}
/>
</EuiFlexItem>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jest.mock('../delete_workspace_modal', () => ({

function getWrapWorkspaceListInContext(
workspaceList = [
{ id: 'id1', name: 'name1', features: [] },
{ id: 'id1', name: 'name1', features: ['use-case-all'] },
{ id: 'id2', name: 'name2' },
{ id: 'id3', name: 'name3', features: ['use-case-observability'] },
]
Expand Down Expand Up @@ -69,6 +69,7 @@ describe('WorkspaceList', () => {
expect(getByText('name2')).toBeInTheDocument();

// should display use case
expect(getByText('All use case')).toBeInTheDocument();
expect(getByText('Observability')).toBeInTheDocument();
});
it('should be able to apply debounce search after input', async () => {
Expand Down
23 changes: 10 additions & 13 deletions src/plugins/workspace/public/components/workspace_list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import useObservable from 'react-use/lib/useObservable';
import { BehaviorSubject, of } from 'rxjs';
import { i18n } from '@osd/i18n';
import { debounce } from '../../../../../core/public';
import { debounce, DEFAULT_NAV_GROUPS } from '../../../../../core/public';
import { WorkspaceAttribute } from '../../../../../core/public';
import { useOpenSearchDashboards } from '../../../../../plugins/opensearch_dashboards_react/public';
import { navigateToWorkspaceDetail } from '../utils/workspace';
Expand All @@ -26,7 +26,7 @@ import { WORKSPACE_CREATE_APP_ID } from '../../../common/constants';

import { cleanWorkspaceId } from '../../../../../core/public';
import { DeleteWorkspaceModal } from '../delete_workspace_modal';
import { getUseCaseFromFeatureConfig } from '../../utils';
import { getFirstUseCaseOfFeatureConfigs, getUseCaseFromFeatureConfig } from '../../utils';
import { WorkspaceUseCase } from '../../types';

const WORKSPACE_LIST_PAGE_DESCRIPTION = i18n.translate('workspace.list.description', {
Expand Down Expand Up @@ -108,17 +108,14 @@ export const WorkspaceList = ({ registeredUseCases$ }: WorkspaceListProps) => {
if (!features || features.length === 0) {
return '';
}
const results: string[] = [];
features.forEach((featureConfig) => {
const useCaseId = getUseCaseFromFeatureConfig(featureConfig);
if (useCaseId) {
const useCase = registeredUseCases?.find(({ id }) => id === useCaseId);
if (useCase) {
results.push(useCase.title);
}
}
});
return results.join(', ');
const useCaseId = getFirstUseCaseOfFeatureConfigs(features);
const useCase =
useCaseId === DEFAULT_NAV_GROUPS.all.id
? DEFAULT_NAV_GROUPS.all
: registeredUseCases?.find(({ id }) => id === useCaseId);
if (useCase) {
return useCase.title;
}
},
},
{
Expand Down
Loading

0 comments on commit 92fc98d

Please sign in to comment.