From 19917d48b5b73a18583a4e03496c89be76a25774 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 29 Jul 2021 16:54:02 +0300 Subject: [PATCH] Moved getId back to canvas and removed from pres_util. --- .../utils => expression_shape/common/lib}/get_id.ts | 0 src/plugins/expression_shape/common/lib/index.ts | 1 + .../components/progress/progress_component.tsx | 3 ++- .../presentation_util/common/lib/utils/index.ts | 1 - .../public/components/asset_manager/asset_manager.ts | 3 ++- .../canvas/public/components/function_form/index.js | 2 +- .../components/home/hooks/use_clone_workpad.ts | 2 +- .../components/home/hooks/use_upload_workpad.ts | 3 ++- .../keyboard_shortcuts_doc.tsx | 2 +- .../canvas/public/components/tag_list/tag_list.tsx | 2 +- .../element_menu/element_menu.component.tsx | 2 +- .../public/lib/aeroelastic/layout_functions.js | 3 ++- x-pack/plugins/canvas/public/lib/clone_subgraphs.ts | 2 +- .../canvas/public/lib/element_handler_creators.ts | 2 +- x-pack/plugins/canvas/public/lib/get_id.ts | 12 ++++++++++++ x-pack/plugins/canvas/public/lib/template.js | 2 +- .../canvas/public/services/storybook/workpad.ts | 3 +-- x-pack/plugins/canvas/public/state/defaults.js | 2 +- .../plugins/canvas/public/state/reducers/assets.js | 2 +- x-pack/plugins/canvas/public/state/reducers/pages.js | 2 +- .../plugins/canvas/server/routes/workpad/create.ts | 2 +- 21 files changed, 34 insertions(+), 19 deletions(-) rename src/plugins/{presentation_util/common/lib/utils => expression_shape/common/lib}/get_id.ts (100%) create mode 100644 x-pack/plugins/canvas/public/lib/get_id.ts diff --git a/src/plugins/presentation_util/common/lib/utils/get_id.ts b/src/plugins/expression_shape/common/lib/get_id.ts similarity index 100% rename from src/plugins/presentation_util/common/lib/utils/get_id.ts rename to src/plugins/expression_shape/common/lib/get_id.ts diff --git a/src/plugins/expression_shape/common/lib/index.ts b/src/plugins/expression_shape/common/lib/index.ts index d62a0d96078be..726d63929ebd8 100644 --- a/src/plugins/expression_shape/common/lib/index.ts +++ b/src/plugins/expression_shape/common/lib/index.ts @@ -8,3 +8,4 @@ export * from './view_box'; export * from './available_shapes'; +export * from './get_id'; diff --git a/src/plugins/expression_shape/public/components/progress/progress_component.tsx b/src/plugins/expression_shape/public/components/progress/progress_component.tsx index 2be6e9e95a262..e9c71753e8ff6 100644 --- a/src/plugins/expression_shape/public/components/progress/progress_component.tsx +++ b/src/plugins/expression_shape/public/components/progress/progress_component.tsx @@ -12,8 +12,9 @@ import { IInterpreterRenderHandlers } from '../../../../expressions'; import { NodeDimensions, ProgressRendererConfig } from '../../../common/types'; import { ShapeRef, SvgConfig, SvgTextAttributes } from '../reusable/types'; import { getShapeContentElement } from '../reusable/shape_factory'; -import { getId, withSuspense } from '../../../../presentation_util/public'; +import { withSuspense } from '../../../../presentation_util/public'; import { getTextAttributes, getViewBox } from './utils'; +import { getId } from '../../../common/lib'; import { getDefaultShapeData } from '../reusable'; import { LazyProgressDrawer } from '../..'; diff --git a/src/plugins/presentation_util/common/lib/utils/index.ts b/src/plugins/presentation_util/common/lib/utils/index.ts index 9cca971e22d91..232ec09cf8b06 100644 --- a/src/plugins/presentation_util/common/lib/utils/index.ts +++ b/src/plugins/presentation_util/common/lib/utils/index.ts @@ -10,7 +10,6 @@ export * from './dataurl'; export * from './httpurl'; export * from './resolve_dataurl'; export * from './url'; -export * from './get_id'; export async function getElasticLogo() { return await import('./elastic_logo'); diff --git a/x-pack/plugins/canvas/public/components/asset_manager/asset_manager.ts b/x-pack/plugins/canvas/public/components/asset_manager/asset_manager.ts index e0fc914f8a6e8..6c658f728e73c 100644 --- a/x-pack/plugins/canvas/public/components/asset_manager/asset_manager.ts +++ b/x-pack/plugins/canvas/public/components/asset_manager/asset_manager.ts @@ -11,7 +11,8 @@ import { get } from 'lodash'; // @ts-expect-error untyped local import { findExistingAsset } from '../../lib/find_existing_asset'; import { VALID_IMAGE_TYPES } from '../../../common/lib/constants'; -import { encode, getId } from '../../../../../../src/plugins/presentation_util/public'; +import { encode } from '../../../../../../src/plugins/presentation_util/public'; +import { getId } from '../../lib/get_id'; // @ts-expect-error untyped local import { elementsRegistry } from '../../lib/elements_registry'; // @ts-expect-error untyped local diff --git a/x-pack/plugins/canvas/public/components/function_form/index.js b/x-pack/plugins/canvas/public/components/function_form/index.js index b77da8c617b8a..76eb23d800b00 100644 --- a/x-pack/plugins/canvas/public/components/function_form/index.js +++ b/x-pack/plugins/canvas/public/components/function_form/index.js @@ -8,7 +8,7 @@ import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { findExpressionType } from '../../lib/find_expression_type'; -import { getId } from '../../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from '../../lib/get_id'; import { createAsset } from '../../state/actions/assets'; import { fetchContext, diff --git a/x-pack/plugins/canvas/public/components/home/hooks/use_clone_workpad.ts b/x-pack/plugins/canvas/public/components/home/hooks/use_clone_workpad.ts index 7b3c490778171..001a711a58a72 100644 --- a/x-pack/plugins/canvas/public/components/home/hooks/use_clone_workpad.ts +++ b/x-pack/plugins/canvas/public/components/home/hooks/use_clone_workpad.ts @@ -10,7 +10,7 @@ import { useHistory } from 'react-router-dom'; import { i18n } from '@kbn/i18n'; import { useNotifyService, useWorkpadService } from '../../../services'; -import { getId } from '../../../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from '../../../lib/get_id'; export const useCloneWorkpad = () => { const workpadService = useWorkpadService(); diff --git a/x-pack/plugins/canvas/public/components/home/hooks/use_upload_workpad.ts b/x-pack/plugins/canvas/public/components/home/hooks/use_upload_workpad.ts index 8b087479f5529..caec30e083d40 100644 --- a/x-pack/plugins/canvas/public/components/home/hooks/use_upload_workpad.ts +++ b/x-pack/plugins/canvas/public/components/home/hooks/use_upload_workpad.ts @@ -11,7 +11,8 @@ import { i18n } from '@kbn/i18n'; import { CANVAS, JSON as JSONString } from '../../../../i18n/constants'; import { useNotifyService } from '../../../services'; -import { getId } from '../../../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from '../../../lib/get_id'; + import { useCreateWorkpad } from './use_create_workpad'; import type { CanvasWorkpad } from '../../../../types'; diff --git a/x-pack/plugins/canvas/public/components/keyboard_shortcuts_doc/keyboard_shortcuts_doc.tsx b/x-pack/plugins/canvas/public/components/keyboard_shortcuts_doc/keyboard_shortcuts_doc.tsx index 50d0d76e8c241..a71976006d51c 100644 --- a/x-pack/plugins/canvas/public/components/keyboard_shortcuts_doc/keyboard_shortcuts_doc.tsx +++ b/x-pack/plugins/canvas/public/components/keyboard_shortcuts_doc/keyboard_shortcuts_doc.tsx @@ -22,7 +22,7 @@ import { i18n } from '@kbn/i18n'; import { keymap } from '../../lib/keymap'; import { ShortcutMap, ShortcutNameSpace } from '../../../types/shortcuts'; import { getClientPlatform } from '../../lib/get_client_platform'; -import { getId } from '../../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from '../../lib/get_id'; import { getPrettyShortcut } from '../../lib/get_pretty_shortcut'; const strings = { diff --git a/x-pack/plugins/canvas/public/components/tag_list/tag_list.tsx b/x-pack/plugins/canvas/public/components/tag_list/tag_list.tsx index 99bfbfb41e1da..8b35e39ce692c 100644 --- a/x-pack/plugins/canvas/public/components/tag_list/tag_list.tsx +++ b/x-pack/plugins/canvas/public/components/tag_list/tag_list.tsx @@ -7,7 +7,7 @@ import React, { Fragment, FunctionComponent } from 'react'; import PropTypes from 'prop-types'; -import { getId } from '../../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from '../../lib/get_id'; import { Tag } from '../tag'; import { TagSpec } from '../../lib/tag'; diff --git a/x-pack/plugins/canvas/public/components/workpad_header/element_menu/element_menu.component.tsx b/x-pack/plugins/canvas/public/components/workpad_header/element_menu/element_menu.component.tsx index 2aca6c192a571..937912570b77f 100644 --- a/x-pack/plugins/canvas/public/components/workpad_header/element_menu/element_menu.component.tsx +++ b/x-pack/plugins/canvas/public/components/workpad_header/element_menu/element_menu.component.tsx @@ -15,7 +15,7 @@ import { EuiContextMenuPanelItemDescriptor, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { getId } from '../../../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from '../../../lib/get_id'; import { Popover, ClosePopoverFn } from '../../popover'; import { CONTEXT_MENU_TOP_BORDER_CLASSNAME } from '../../../../common/lib'; import { ElementSpec } from '../../../../types'; diff --git a/x-pack/plugins/canvas/public/lib/aeroelastic/layout_functions.js b/x-pack/plugins/canvas/public/lib/aeroelastic/layout_functions.js index 40276e20228bc..f620de03bea4c 100644 --- a/x-pack/plugins/canvas/public/lib/aeroelastic/layout_functions.js +++ b/x-pack/plugins/canvas/public/lib/aeroelastic/layout_functions.js @@ -5,7 +5,8 @@ * 2.0. */ -import { getId as rawGetId } from '../../../../../../src/plugins/presentation_util/common/lib'; +import { getId as rawGetId } from '../get_id'; + import { insideAABB, landmarkPoint, shapesAt } from './geometry'; import { diff --git a/x-pack/plugins/canvas/public/lib/clone_subgraphs.ts b/x-pack/plugins/canvas/public/lib/clone_subgraphs.ts index 5f5ee3742a21d..7281a83953f15 100644 --- a/x-pack/plugins/canvas/public/lib/clone_subgraphs.ts +++ b/x-pack/plugins/canvas/public/lib/clone_subgraphs.ts @@ -7,7 +7,7 @@ // @ts-expect-error untyped local import { arrayToMap } from './aeroelastic/functional'; -import { getId } from '../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from './get_id'; import { PositionedElement } from '../../types'; export const cloneSubgraphs = (nodes: PositionedElement[]) => { diff --git a/x-pack/plugins/canvas/public/lib/element_handler_creators.ts b/x-pack/plugins/canvas/public/lib/element_handler_creators.ts index e0ebc916af172..a46252081e672 100644 --- a/x-pack/plugins/canvas/public/lib/element_handler_creators.ts +++ b/x-pack/plugins/canvas/public/lib/element_handler_creators.ts @@ -10,7 +10,7 @@ import { getClipboardData, setClipboardData } from './clipboard'; import { cloneSubgraphs } from './clone_subgraphs'; import { pluginServices } from '../services'; import * as customElementService from './custom_element_service'; -import { getId } from '../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from './get_id'; import { PositionedElement } from '../../types'; import { ELEMENT_NUDGE_OFFSET, ELEMENT_SHIFT_OFFSET } from '../../common/lib/constants'; diff --git a/x-pack/plugins/canvas/public/lib/get_id.ts b/x-pack/plugins/canvas/public/lib/get_id.ts new file mode 100644 index 0000000000000..56f7e69d82539 --- /dev/null +++ b/x-pack/plugins/canvas/public/lib/get_id.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import uuid from 'uuid/v4'; + +export function getId(type: string): string { + return `${type}-${uuid()}`; +} diff --git a/x-pack/plugins/canvas/public/lib/template.js b/x-pack/plugins/canvas/public/lib/template.js index 2af67267f39e2..55ee6ff6e89d0 100644 --- a/x-pack/plugins/canvas/public/lib/template.js +++ b/x-pack/plugins/canvas/public/lib/template.js @@ -7,7 +7,7 @@ import { tagsRegistry } from '../lib/tags_registry'; import { getDefaultWorkpad } from '../state/defaults'; -import { getId } from '../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from './get_id'; const defaultWorkpad = getDefaultWorkpad(); diff --git a/x-pack/plugins/canvas/public/services/storybook/workpad.ts b/x-pack/plugins/canvas/public/services/storybook/workpad.ts index b7ab18c47323b..3ecac4b49310e 100644 --- a/x-pack/plugins/canvas/public/services/storybook/workpad.ts +++ b/x-pack/plugins/canvas/public/services/storybook/workpad.ts @@ -9,8 +9,7 @@ import moment from 'moment'; import { action } from '@storybook/addon-actions'; import { PluginServiceFactory } from '../../../../../../src/plugins/presentation_util/public'; - -import { getId } from '../../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from '../../lib/get_id'; // @ts-expect-error import { getDefaultWorkpad } from '../../state/defaults'; diff --git a/x-pack/plugins/canvas/public/state/defaults.js b/x-pack/plugins/canvas/public/state/defaults.js index fa4f6a978d46b..a245d515a32d9 100644 --- a/x-pack/plugins/canvas/public/state/defaults.js +++ b/x-pack/plugins/canvas/public/state/defaults.js @@ -5,7 +5,7 @@ * 2.0. */ -import { getId } from '../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from '../lib/get_id'; import { DEFAULT_WORKPAD_CSS } from '../../common/lib/constants'; export const getDefaultElement = () => { diff --git a/x-pack/plugins/canvas/public/state/reducers/assets.js b/x-pack/plugins/canvas/public/state/reducers/assets.js index adf2e05d54b2c..0b5fdaa06fa78 100644 --- a/x-pack/plugins/canvas/public/state/reducers/assets.js +++ b/x-pack/plugins/canvas/public/state/reducers/assets.js @@ -9,7 +9,7 @@ import { handleActions, combineActions } from 'redux-actions'; import immutable from 'object-path-immutable'; import { get } from 'lodash'; import { createAsset, setAssetValue, removeAsset, setAssets, resetAssets } from '../actions/assets'; -import { getId } from '../../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from '../../lib/get_id'; const { set, assign, del } = immutable; diff --git a/x-pack/plugins/canvas/public/state/reducers/pages.js b/x-pack/plugins/canvas/public/state/reducers/pages.js index 1ace2f6cf7025..78ec0addd970e 100644 --- a/x-pack/plugins/canvas/public/state/reducers/pages.js +++ b/x-pack/plugins/canvas/public/state/reducers/pages.js @@ -8,7 +8,7 @@ import { handleActions } from 'redux-actions'; import immutable from 'object-path-immutable'; import { cloneSubgraphs } from '../../lib/clone_subgraphs'; -import { getId } from '../../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from '../../lib/get_id'; import { getDefaultPage } from '../defaults'; import * as actions from '../actions/pages'; import { getSelectedPageIndex } from '../selectors/workpad'; diff --git a/x-pack/plugins/canvas/server/routes/workpad/create.ts b/x-pack/plugins/canvas/server/routes/workpad/create.ts index deaba0150ad79..1fa8ab4412aca 100644 --- a/x-pack/plugins/canvas/server/routes/workpad/create.ts +++ b/x-pack/plugins/canvas/server/routes/workpad/create.ts @@ -9,7 +9,7 @@ import { schema } from '@kbn/config-schema'; import { RouteInitializerDeps } from '../'; import { CANVAS_TYPE, API_ROUTE_WORKPAD, TEMPLATE_TYPE } from '../../../common/lib/constants'; import { CanvasWorkpad } from '../../../types'; -import { getId } from '../../../../../../src/plugins/presentation_util/common/lib'; +import { getId } from '../../../common/lib/get_id'; import { WorkpadAttributes } from './workpad_attributes'; import { WorkpadSchema } from './workpad_schema'; import { okResponse } from '../ok_response';