Skip to content

Commit

Permalink
Use app id instead of pluginId to generate navlink from legacy apps (#…
Browse files Browse the repository at this point in the history
…57542)

* properly use app id instead of pluginId to generate navlink

* extract convertToNavLink, add more tests

* use distinct mapping methods

* fix linkToLastSubUrl default value

* nits & doc
  • Loading branch information
pgayvallet authored Feb 14, 2020
1 parent 1aadf3e commit f87053e
Show file tree
Hide file tree
Showing 6 changed files with 437 additions and 76 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 2 additions & 66 deletions src/core/server/legacy/plugins/find_legacy_plugin_specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,72 +30,8 @@ import { collectUiExports as collectLegacyUiExports } from '../../../../legacy/u

import { LoggerFactory } from '../../logging';
import { PackageInfo } from '../../config';

import {
LegacyUiExports,
LegacyNavLink,
LegacyPluginSpec,
LegacyPluginPack,
LegacyConfig,
} from '../types';

const REMOVE_FROM_ARRAY: LegacyNavLink[] = [];

function getUiAppsNavLinks({ uiAppSpecs = [] }: LegacyUiExports, pluginSpecs: LegacyPluginSpec[]) {
return uiAppSpecs.flatMap(spec => {
if (!spec) {
return REMOVE_FROM_ARRAY;
}

const id = spec.pluginId || spec.id;

if (!id) {
throw new Error('Every app must specify an id');
}

if (spec.pluginId && !pluginSpecs.some(plugin => plugin.getId() === spec.pluginId)) {
throw new Error(`Unknown plugin id "${spec.pluginId}"`);
}

const listed = typeof spec.listed === 'boolean' ? spec.listed : true;

if (spec.hidden || !listed) {
return REMOVE_FROM_ARRAY;
}

return {
id,
category: spec.category,
title: spec.title,
order: typeof spec.order === 'number' ? spec.order : 0,
icon: spec.icon,
euiIconType: spec.euiIconType,
url: spec.url || `/app/${id}`,
linkToLastSubUrl: spec.linkToLastSubUrl,
};
});
}

function getNavLinks(uiExports: LegacyUiExports, pluginSpecs: LegacyPluginSpec[]) {
return (uiExports.navLinkSpecs || [])
.map<LegacyNavLink>(spec => ({
id: spec.id,
category: spec.category,
title: spec.title,
order: typeof spec.order === 'number' ? spec.order : 0,
url: spec.url,
subUrlBase: spec.subUrlBase || spec.url,
disableSubUrlTracking: spec.disableSubUrlTracking,
icon: spec.icon,
euiIconType: spec.euiIconType,
linkToLastSub: 'linkToLastSubUrl' in spec ? spec.linkToLastSubUrl : false,
hidden: 'hidden' in spec ? spec.hidden : false,
disabled: 'disabled' in spec ? spec.disabled : false,
tooltip: spec.tooltip || '',
}))
.concat(getUiAppsNavLinks(uiExports, pluginSpecs))
.sort((a, b) => a.order - b.order);
}
import { LegacyPluginSpec, LegacyPluginPack, LegacyConfig } from '../types';
import { getNavLinks } from './get_nav_links';

export async function findLegacyPluginSpecs(
settings: unknown,
Expand Down
Loading

0 comments on commit f87053e

Please sign in to comment.