Skip to content

Commit

Permalink
[Upgrade Assistant] Refactor external links to use locators (#110435)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba authored Aug 30, 2021
1 parent 3e84d05 commit efdc7d5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ import { breadcrumbService } from '../../../public/application/lib/breadcrumbs';
// We'll mock these values to avoid testing the locators themselves.
const idToUrlMap = {
SNAPSHOT_RESTORE_LOCATOR: 'snapshotAndRestoreUrl',
DISCOVER_APP_LOCATOR: 'discoverUrl',
};

const shareMock = sharePluginMock.createSetupContract();
shareMock.url.locators.get = (id) => ({
// @ts-expect-error This object is missing some properties that we're not using in the UI
useUrl: (): string | undefined => idToUrlMap[id],
// @ts-expect-error This object is missing some properties that we're not using in the UI
getUrl: (): string | undefined => idToUrlMap[id],
});

export const getAppContextMock = (mockHttpClient: HttpSetup) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,9 @@
*/

import { dataPluginMock } from '../../../../../../src/plugins/data/public/mocks';
import { discoverPluginMock } from '../../../../../../src/plugins/discover/public/mocks';
import { applicationServiceMock } from '../../../../../../src/core/public/application/application_service.mock';

const discoverMock = discoverPluginMock.createStartContract();

export const kibanaContextMock = {
data: dataPluginMock.createStartContract(),
application: applicationServiceMock.createStartContract(),
discover: {
...discoverMock,
locator: {
...discoverMock.locator,
getLocation: jest.fn(() =>
Promise.resolve({
app: '/discover',
path: 'logs',
state: {},
})
),
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,15 @@ describe('Overview - Fix deprecation logs step', () => {

test('Has a link to see logs in discover app', async () => {
await act(async () => {
testBed = await setupOverviewPage({
getUrlForApp: jest.fn((app, options) => {
return `${app}/${options.path}`;
}),
});
testBed = await setupOverviewPage();
});

const { exists, component, find } = testBed;

component.update();

expect(exists('viewDiscoverLogs')).toBe(true);
expect(find('viewDiscoverLogs').props().href).toBe('/discover/logs');
expect(find('viewDiscoverLogs').props().href).toBe('discoverUrl');
});
});

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/upgrade_assistant/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"githubTeam": "kibana-stack-management"
},
"configPath": ["xpack", "upgrade_assistant"],
"requiredPlugins": ["management", "discover", "data", "licensing", "features", "infra", "share"],
"requiredPlugins": ["management", "data", "licensing", "features", "infra", "share"],
"optionalPlugins": ["usageCollection", "cloud"],
"requiredBundles": ["esUiShared", "kibanaReact", "kibanaUtils"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,26 @@ const getDeprecationIndexPatternId = async (dataService: DataPublicPluginStart)
};

const DiscoverAppLink: FunctionComponent = () => {
const { getUrlForApp } = useAppContext();
const { data: dataService, discover: discoverService } = useKibana().services;
const { share } = useAppContext();
const { data: dataService } = useKibana().services;

const [discoveryUrl, setDiscoveryUrl] = useState<string | undefined>();

useEffect(() => {
const getDiscoveryUrl = async () => {
const indexPatternId = await getDeprecationIndexPatternId(dataService);
const appLocation = await discoverService?.locator?.getLocation({ indexPatternId });
const locator = share.url.locators.get('DISCOVER_APP_LOCATOR');

const result = getUrlForApp(appLocation?.app as string, {
path: appLocation?.path,
});
setDiscoveryUrl(result);
if (!locator) {
return;
}

const url = await locator.getUrl({ indexPatternId });
setDiscoveryUrl(url);
};

getDiscoveryUrl();
}, [dataService, discoverService, getUrlForApp]);
}, [dataService, share.url.locators]);

return (
<EuiLink href={discoveryUrl} target="_blank" data-test-subj="viewDiscoverLogs">
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/upgrade_assistant/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class UpgradeAssistantUIPlugin
title: pluginName,
order: 1,
async mount(params) {
const [coreStart, { discover, data }] = await coreSetup.getStartServices();
const services: AppServicesContext = { discover, data, cloud };
const [coreStart, { data }] = await coreSetup.getStartServices();
const services: AppServicesContext = { data, cloud };

const {
chrome: { docTitle },
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/upgrade_assistant/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { CloudSetup } from '../../cloud/public';
import { LicensingPluginStart } from '../../licensing/public';

export interface AppServicesContext {
discover: DiscoverStart;
data: DataPublicPluginStart;
cloud?: CloudSetup;
}
Expand Down

0 comments on commit efdc7d5

Please sign in to comment.