Skip to content

Commit

Permalink
Change wizard to vis_builder in file names and paths (opensearch-proj…
Browse files Browse the repository at this point in the history
…ect#2587)

Change all wizard reference in file names and paths to vis_builder

Signed-off-by: abbyhu2000 <[email protected]>

Signed-off-by: abbyhu2000 <[email protected]>
(cherry picked from commit f29f734)
  • Loading branch information
abbyhu2000 committed Oct 31, 2022
1 parent df1c722 commit 0e4164d
Show file tree
Hide file tree
Showing 130 changed files with 231 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/plugins/saved_objects_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import { i18n } from '@osd/i18n';
import { CoreSetup, CoreStart, Plugin } from 'src/core/public';

import { WizardStart } from '../../wizard/public';
import { WizardStart } from '../../vis_builder/public';
import { ManagementSetup } from '../../management/public';
import { DataPublicPluginStart } from '../../data/public';
import { DashboardStart } from '../../dashboard/public';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ export const PLUGIN_NAME = 'Wizard';
export const VISUALIZE_ID = 'visualize';
export const EDIT_PATH = '/edit';

export { WizardSavedObjectAttributes, WIZARD_SAVED_OBJECT } from './wizard_saved_object_attributes';
export {
WizardSavedObjectAttributes,
WIZARD_SAVED_OBJECT,
} from './vis_builder_saved_object_attributes';
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { WizardServices } from '../../types';
import { getOnSave } from './get_top_nav_config';
import { createWizardServicesMock } from './mocks';

describe('getOnSave', () => {
let savedWizardVis: any;
let originatingApp: string | undefined;
let visualizationIdFromUrl: string;
let dispatch: any;
let mockServices: jest.Mocked<WizardServices>;
let onSaveProps: {
newTitle: string;
newCopyOnSave: boolean;
isTitleDuplicateConfirmed: boolean;
onTitleDuplicate: any;
newDescription: string;
returnToOrigin: boolean;
};

beforeEach(() => {
savedWizardVis = {
id: '1',
title: 'save wizard wiz title',
description: '',
visualizationState: '',
styleState: '',
version: 0,
copyOnSave: true,
searchSourceFields: {},
save: jest.fn().mockReturnValue('1'),
};
originatingApp = '';
visualizationIdFromUrl = '';
dispatch = jest.fn();
mockServices = createWizardServicesMock();

onSaveProps = {
newTitle: 'new title',
newCopyOnSave: false,
isTitleDuplicateConfirmed: false,
onTitleDuplicate: jest.fn(),
newDescription: 'new description',
returnToOrigin: true,
};
});

test('return undefined when savedWizardVis is null', async () => {
savedWizardVis = null;
const onSave = getOnSave(
savedWizardVis,
originatingApp,
visualizationIdFromUrl,
dispatch,
mockServices
);
const onSaveResult = await onSave(onSaveProps);

expect(onSaveResult).toBeUndefined();
});

test('savedWizardVis get saved correctly', async () => {
const onSave = getOnSave(
savedWizardVis,
originatingApp,
visualizationIdFromUrl,
dispatch,
mockServices
);
const onSaveReturn = await onSave(onSaveProps);
expect(savedWizardVis).toMatchInlineSnapshot(`
Object {
"copyOnSave": false,
"description": "new description",
"id": "1",
"save": [MockFunction] {
"calls": Array [
Array [
Object {
"confirmOverwrite": false,
"isTitleDuplicateConfirmed": false,
"onTitleDuplicate": [MockFunction],
"returnToOrigin": true,
},
],
],
"results": Array [
Object {
"type": "return",
"value": "1",
},
],
},
"searchSourceFields": Object {},
"styleState": "",
"title": "new title",
"version": 0,
"visualizationState": "",
}
`);
expect(onSaveReturn?.id).toBe('1');
});

test('savedWizardVis does not change title with a null id', async () => {
savedWizardVis.save = jest.fn().mockReturnValue(null);
const onSave = getOnSave(
savedWizardVis,
originatingApp,
visualizationIdFromUrl,
dispatch,
mockServices
);
const onSaveResult = await onSave(onSaveProps);
expect(savedWizardVis.title).toBe('save wizard wiz title');
expect(onSaveResult?.id).toBeNull();
});

test('create a new wizard from dashboard', async () => {
savedWizardVis.id = undefined;
savedWizardVis.save = jest.fn().mockReturnValue('2');
originatingApp = 'dashboard';
onSaveProps.returnToOrigin = true;

const onSave = getOnSave(
savedWizardVis,
originatingApp,
visualizationIdFromUrl,
dispatch,
mockServices
);
const onSaveResult = await onSave(onSaveProps);
expect(onSaveResult?.id).toBe('2');
expect(dispatch).toBeCalledTimes(0);
});

test('edit an exising wizard from dashboard', async () => {
savedWizardVis.copyOnSave = false;
onSaveProps.newDescription = 'new description after editing';
originatingApp = 'dashboard';
onSaveProps.returnToOrigin = true;
const onSave = getOnSave(
savedWizardVis,
originatingApp,
visualizationIdFromUrl,
dispatch,
mockServices
);
const onSaveResult = await onSave(onSaveProps);
expect(onSaveResult?.id).toBe('1');
expect(mockServices.application.navigateToApp).toBeCalledTimes(1);
expect(savedWizardVis.description).toBe('new description after editing');
});
});
45 changes: 45 additions & 0 deletions src/plugins/vis_builder/public/application/utils/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { ScopedHistory } from '../../../../../core/public';
import { coreMock, scopedHistoryMock } from '../../../../../core/public/mocks';
import { dataPluginMock } from '../../../../data/public/mocks';
import { embeddablePluginMock } from '../../../../embeddable/public/mocks';
import { expressionsPluginMock } from '../../../../expressions/public/mocks';
import { navigationPluginMock } from '../../../../navigation/public/mocks';
import { WizardServices } from '../../types';

export const createWizardServicesMock = () => {
const coreStartMock = coreMock.createStart();
const toastNotifications = coreStartMock.notifications.toasts;
const applicationMock = coreStartMock.application;
const i18nContextMock = coreStartMock.i18n.Context;
const indexPatternMock = dataPluginMock.createStartContract().indexPatterns;
const embeddableMock = embeddablePluginMock.createStartContract();
const navigationMock = navigationPluginMock.createStartContract();
const expressionMock = expressionsPluginMock.createStartContract();

const wizardServicesMock = {
...coreStartMock,
navigation: navigationMock,
expression: expressionMock,
savedWizardLoader: {
get: jest.fn(),
} as any,
setHeaderActionMenu: () => {},
applicationMock,
history: {
push: jest.fn(),
location: { pathname: '' },
},
toastNotifications,
i18n: i18nContextMock,
data: indexPatternMock,
embeddable: embeddableMock,
scopedHistory: (scopedHistoryMock.create() as unknown) as ScopedHistory,
};

return (wizardServicesMock as unknown) as jest.Mocked<WizardServices>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

export { useVisualizationType } from './use_visualization_type';
export { useIndexPatterns } from './use_index_pattern';
export { useSavedWizardVis } from './use_saved_wizard_vis';
export { useSavedWizardVis } from './use_saved_vis_builder_vis';
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { EDIT_PATH, PLUGIN_ID } from '../../../../common';
import { WizardServices } from '../../../types';
import { MetricOptionsDefaults } from '../../../visualizations/metric/metric_viz_type';
import { getCreateBreadcrumbs, getEditBreadcrumbs } from '../breadcrumbs';
import { getSavedWizardVis } from '../get_saved_wizard_vis';
import { getSavedWizardVis } from '../get_saved_vis_builder_vis';
import {
useTypedDispatch,
setStyleState,
Expand All @@ -24,7 +24,7 @@ import {
} from '../state_management';
import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public';
import { setEditorState } from '../state_management/metadata_slice';
import { validateWizardState } from '../wizard_state_validation';
import { validateWizardState } from '../vis_builder_state_validation';

// This function can be used when instantiating a saved vis or creating a new one
// using url parameters, embedding and destroying it in DOM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { validateWizardState } from './wizard_state_validation';
import { validateWizardState } from './vis_builder_state_validation';

describe('wizard state validation', () => {
const validStyleState = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ReactDOM from 'react-dom';
import { Embeddable, EmbeddableOutput } from '../../../embeddable/public';

import { DisabledVisualization } from './disabled_visualization';
import { WizardInput, WIZARD_EMBEDDABLE } from './wizard_embeddable';
import { WizardInput, WIZARD_EMBEDDABLE } from './vis_builder_embeddable';

export class DisabledEmbeddable extends Embeddable<WizardInput, EmbeddableOutput> {
private domNode?: HTMLElement;
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/vis_builder/public/embeddable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export * from './vis_builder_embeddable';
export * from './vis_builder_embeddable_factory';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react';

import { SavedObjectEmbeddableInput, withEmbeddableSubscription } from '../../../embeddable/public';
import { WizardEmbeddable, WizardOutput } from './wizard_embeddable';
import { WizardEmbeddable, WizardOutput } from './vis_builder_embeddable';
import { getReactExpressionRenderer } from '../plugin_services';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
WIZARD_SAVED_OBJECT,
} from '../../common';
import { DisabledEmbeddable } from './disabled_embeddable';
import { WizardEmbeddable, WizardOutput, WIZARD_EMBEDDABLE } from './wizard_embeddable';
import { WizardEmbeddable, WizardOutput, WIZARD_EMBEDDABLE } from './vis_builder_embeddable';
import wizardIcon from '../assets/wizard_icon.svg';
import { getHttp, getSavedWizardLoader, getTimeFilter, getUISettings } from '../plugin_services';

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*/

import { coreMock, savedObjectsServiceMock } from '../../../core/public/mocks';
import { dashboardPluginMock } from '../../../plugins/dashboard/public/mocks';
import { dataPluginMock } from '../../../plugins/data/public/mocks';
import { embeddablePluginMock } from '../../../plugins/embeddable/public/mocks';
import { navigationPluginMock } from '../../../plugins/navigation/public/mocks';
import { visualizationsPluginMock } from '../../../plugins/visualizations/public/mocks';
import { dashboardPluginMock } from '../../dashboard/public/mocks';
import { dataPluginMock } from '../../data/public/mocks';
import { embeddablePluginMock } from '../../embeddable/public/mocks';
import { navigationPluginMock } from '../../navigation/public/mocks';
import { visualizationsPluginMock } from '../../visualizations/public/mocks';
import { PLUGIN_ID, PLUGIN_NAME } from '../common';
import { WizardPlugin } from './plugin';

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { coreMock } from '../../../../core/public/mocks';
import { getStubIndexPattern } from '../../../../plugins/data/public/test_utils';
import { getStubIndexPattern } from '../../../data/public/test_utils';
import { IndexPattern } from '../../../data/public';
import { RootState } from '../application/utils/state_management';
import { WizardVisSavedObject } from '../types';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* SPDX-License-Identifier: Apache-2.0
*/

export { wizardSavedObjectType } from './wizard_app';
export { wizardSavedObjectType } from './vis_builder_app';
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
WizardSavedObjectAttributes,
WIZARD_SAVED_OBJECT,
} from '../../common';
import { wizardSavedObjectTypeMigrations } from './wizard_migration';
import { wizardSavedObjectTypeMigrations } from './vis_builder_migration';

export const wizardSavedObjectType: SavedObjectsType = {
name: WIZARD_SAVED_OBJECT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { SavedObjectMigrationFn, SavedObjectMigrationContext } from '../../../../core/server';
import { wizardSavedObjectTypeMigrations } from './wizard_migration';
import { wizardSavedObjectTypeMigrations } from './vis_builder_migration';

const savedObjectMigrationContext = (null as unknown) as SavedObjectMigrationContext;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"baseUrl": "./src/plugins/wizard",
"baseUrl": "./src/plugins/vis_builder",
"paths": {
// Allows for importing from `opensearch-dashboards` package for the exported types.
"opensearch-dashboards": ["./opensearch_dashboards"],
Expand Down
7 changes: 0 additions & 7 deletions src/plugins/wizard/public/embeddable/index.ts

This file was deleted.

0 comments on commit 0e4164d

Please sign in to comment.