Skip to content

Commit

Permalink
Unify NAVIGATION_EMBEDDABLE_TYPE and CONTENT_ID constants
Browse files Browse the repository at this point in the history
These equality of these constants are compared in the replaceEmbeddable function which errors because they were different.

It seems this happens in other plugins, too, but we don't see errors since the constants are identical. See `MAP_SAVED_OBJECT_TYPE` and `CONTENT_ID` in the maps plugin. 🙈
  • Loading branch information
nickpeihl committed Aug 8, 2023
1 parent c4d0dbc commit ff28220
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 18 deletions.
2 changes: 0 additions & 2 deletions src/plugins/navigation_embeddable/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export const LATEST_VERSION = 1;

export const CONTENT_ID = 'navigation_embeddable';

export const NAVIGATION_EMBEDDABLE_TYPE = 'navigation';

export const APP_ICON = 'link';

export const APP_NAME = i18n.translate('navigationEmbeddable.visTypeAlias.title', {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/navigation_embeddable/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* Side Public License, v 1.
*/

export { CONTENT_ID, LATEST_VERSION } from './constants';
export { APP_ICON, APP_NAME, CONTENT_ID, LATEST_VERSION } from './constants';
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { NavigationEmbeddableComponent } from '../components/navigation_embeddable_component';
import { NavigationEmbeddableInput, NavigationEmbeddableOutput } from './types';
import { NavigationEmbeddableAttributes } from '../../common/content_management';
import { NAVIGATION_EMBEDDABLE_TYPE } from '../../common/constants';
import { CONTENT_ID } from '../../common';

export const NavigationEmbeddableContext = createContext<NavigationEmbeddable | null>(null);
export const useNavigationEmbeddable = (): NavigationEmbeddable => {
Expand Down Expand Up @@ -55,7 +55,7 @@ export class NavigationEmbeddable
NavigationEmbeddableByReferenceInput
>
{
public readonly type = NAVIGATION_EMBEDDABLE_TYPE;
public readonly type = CONTENT_ID;
deferEmbeddableLoad = true;

private isDestroyed?: boolean;
Expand Down Expand Up @@ -107,7 +107,7 @@ export class NavigationEmbeddable
}

private async initializeSavedLinks(input: NavigationEmbeddableInput) {
const { metaInfo, attributes } = await this.attributeService.unwrapAttributes(input);
const { attributes } = await this.attributeService.unwrapAttributes(input);
if (this.isDestroyed) return;

// TODO handle metaInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import type { NavigationEmbeddable } from './navigation_embeddable';
import { coreServices, untilPluginStartServicesReady } from '../services/kibana_services';
import { getNavigationEmbeddableAttributeService } from '../services/attribute_service';
import { APP_ICON, APP_NAME, CONTENT_ID, NAVIGATION_EMBEDDABLE_TYPE } from '../../common/constants';
import { APP_ICON, APP_NAME, CONTENT_ID } from '../../common';

export type NavigationEmbeddableFactory = EmbeddableFactory;

Expand All @@ -45,7 +45,7 @@ const getDefaultNavigationEmbeddableInput = (): Omit<NavigationEmbeddableByValue
export class NavigationEmbeddableFactoryDefinition
implements EmbeddableFactoryDefinition<NavigationEmbeddableInput>
{
public readonly type = NAVIGATION_EMBEDDABLE_TYPE;
public readonly type = CONTENT_ID;

public readonly isContainerType = false;

Expand All @@ -59,7 +59,7 @@ export class NavigationEmbeddableFactoryDefinition
// public inject: EmbeddablePersistableStateService['inject'];
// public extract: EmbeddablePersistableStateService['extract'];

constructor(private readonly persistableStateService: EmbeddablePersistableStateService) {
constructor(persistableStateService: EmbeddablePersistableStateService) {
// this.inject = createInject(this.persistableStateService);
// this.extract = createExtract(this.persistableStateService);
}
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/navigation_embeddable/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
import { DashboardStart } from '@kbn/dashboard-plugin/public';
import { EmbeddableSetup, EmbeddableStart } from '@kbn/embeddable-plugin/public';
import { NavigationEmbeddableFactoryDefinition } from './embeddable';
import { CONTENT_ID, LATEST_VERSION } from '../common/content_management';
import { APP_NAME, NAVIGATION_EMBEDDABLE_TYPE } from '../common/constants';
import { CONTENT_ID, LATEST_VERSION } from '../common';
import { APP_NAME } from '../common';
import { setKibanaServices } from './services/kibana_services';

export interface NavigationEmbeddableSetupDependencies {
Expand Down Expand Up @@ -46,7 +46,7 @@ export class NavigationEmbeddablePlugin
) {
core.getStartServices().then(([_, deps]) => {
plugins.embeddable.registerEmbeddableFactory(
NAVIGATION_EMBEDDABLE_TYPE,
CONTENT_ID,
new NavigationEmbeddableFactoryDefinition(deps.embeddable)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '../embeddable/types';
import { embeddableService } from './kibana_services';
import { checkForDuplicateTitle, navigationEmbeddableClient } from '../content_management';
import { NAVIGATION_EMBEDDABLE_TYPE } from '../../common/constants';
import { CONTENT_ID } from '../../common';

export type NavigationEmbeddableDocument = NavigationEmbeddableAttributes & {
references?: Reference[];
Expand All @@ -43,7 +43,7 @@ export function getNavigationEmbeddableAttributeService(): NavigationEmbeddableA
NavigationEmbeddableByValueInput,
NavigationEmbeddableByReferenceInput,
NavigationEmbeddableUnwrapMetaInfo
>(NAVIGATION_EMBEDDABLE_TYPE, {
>(CONTENT_ID, {
saveMethod: async (attributes: NavigationEmbeddableDocument, savedObjectId?: string) => {
// TODO extract references
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

import { SOContentStorage } from '@kbn/content-management-utils';
import type { NavigationEmbeddableCrudTypes } from '../../common/content_management';
import { CONTENT_ID } from '../../common';
import type { NavigationEmbeddableCrudTypes } from '../../common/content_management';
import { cmServicesDefinition } from '../../common/content_management/cm_services';

export class NavigationEmbeddableStorage extends SOContentStorage<NavigationEmbeddableCrudTypes> {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/navigation_embeddable/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import { CoreSetup, CoreStart, Plugin } from '@kbn/core/server';
import type { ContentManagementServerSetup } from '@kbn/content-management-plugin/server';
import { CONTENT_ID, LATEST_VERSION } from '../common';
import { NavigationEmbeddableAttributes } from '../common/content_management';
import { NavigationEmbeddableStorage } from './content_management';
import { navigationEmbeddableSavedObjectType } from './saved_objects';
import { NavigationEmbeddableAttributes } from '../common/content_management';

export class NavigationEmbeddableServerPlugin implements Plugin<object, object> {
public setup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import type { SavedObjectsType } from '@kbn/core/server';
import { ANALYTICS_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server';
import { CONTENT_ID } from '../../common';
import { APP_ICON } from '../../common/constants';
import { APP_ICON, CONTENT_ID } from '../../common';

export const navigationEmbeddableSavedObjectType: SavedObjectsType = {
name: CONTENT_ID,
Expand Down

0 comments on commit ff28220

Please sign in to comment.