Skip to content

Commit

Permalink
Fixes from review: kuery param, getPath cleanup, use chrome.docTitle,…
Browse files Browse the repository at this point in the history
… and teardown breadcrumb and doc title
  • Loading branch information
jen-huang committed May 14, 2020
1 parent 7a09c91 commit 2950370
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export type StaticPage =
| 'configurations'
| 'configurations_list'
| 'fleet'
| 'fleet_agent_list'
| 'fleet_enrollment_tokens'
| 'data_streams';

Expand All @@ -22,6 +21,7 @@ export type DynamicPage =
| 'add_datasource_from_configuration'
| 'add_datasource_from_integration'
| 'edit_datasource'
| 'fleet_agent_list'
| 'fleet_agent_details';

export type Page = StaticPage | DynamicPage;
Expand Down Expand Up @@ -77,7 +77,7 @@ export const pagePathGetters: {
edit_datasource: ({ configId, datasourceId }) =>
`/configs/${configId}/edit-datasource/${datasourceId}`,
fleet: () => '/fleet',
fleet_agent_list: () => '/fleet/agents',
fleet_agent_list: ({ kuery }) => `/fleet/agents${kuery ? `?kuery=${kuery}` : ''}`,
fleet_agent_details: ({ agentId, tabId }) =>
`/fleet/agents/${agentId}${tabId ? `/${tabId}` : ''}`,
fleet_enrollment_tokens: () => '/fleet/enrollment-tokens',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ export function useBreadcrumbs(page: Page, values: DynamicPagePathValues = {}) {
...breadcrumb,
href: breadcrumb.href ? http.basePath.prepend(`${BASE_PATH}#${breadcrumb.href}`) : undefined,
}));
document.title = [...breadcrumbs]
const docTitle: string[] = [...breadcrumbs]
.reverse()
.map(breadcrumb => breadcrumb.text)
.join(' - ');
.map(breadcrumb => breadcrumb.text as string);
chrome.docTitle.change(docTitle);
chrome.setBreadcrumbs(breadcrumbs);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ import {
} from '../constants';
import { useCore } from './';

const getPath = (page: StaticPage | DynamicPage, values?: DynamicPagePathValues): string => {
const getPath = (page: StaticPage | DynamicPage, values: DynamicPagePathValues = {}): string => {
return values ? pagePathGetters[page](values) : pagePathGetters[page as StaticPage]();
};

export const useLink = () => {
const core = useCore();
return {
getPath: (page: StaticPage | DynamicPage, values?: DynamicPagePathValues) => {
return getPath(page, values);
},
getPath,
getHref: (page: StaticPage | DynamicPage, values?: DynamicPagePathValues) => {
const path = getPath(page, values);
return core.http.basePath.prepend(`${BASE_PATH}#${path}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,8 @@ export function renderApp(
ReactDOM.unmountComponentAtNode(element);
};
}

export const teardownIngestManager = (coreStart: CoreStart) => {
coreStart.chrome.docTitle.reset();
coreStart.chrome.setBreadcrumbs([]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export const LinkedAgentCount = memo<{ count: number; agentConfigId: string }>(
);
return count > 0 ? (
<EuiLink
href={`${getHref(
'fleet_agent_list'
)}?kuery=${AGENT_SAVED_OBJECT_TYPE}.config_id : ${agentConfigId}`}
href={getHref('fleet_agent_list', {
kuery: `${AGENT_SAVED_OBJECT_TYPE}.config_id : ${agentConfigId}`,
})}
>
{displayValue}
</EuiLink>
Expand Down
9 changes: 7 additions & 2 deletions x-pack/plugins/ingest_manager/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ export class IngestManagerPlugin
IngestManagerStartDeps,
IngestManagerStart
];
const { renderApp } = await import('./applications/ingest_manager');
return renderApp(coreStart, params, deps, startDeps, config);
const { renderApp, teardownIngestManager } = await import('./applications/ingest_manager');
const unmount = renderApp(coreStart, params, deps, startDeps, config);

return () => {

This comment has been minimized.

Copy link
@jfsiii

jfsiii May 14, 2020

Contributor

My initial reaction was that this would go in the stop lifecycle, but after looking at it

I am not so sure.

It isn't given any of the core services, or any params, so I am not sure how we would access the chrome apis. Does @elastic/kibana-platform have any suggestions?

This comment has been minimized.

Copy link
@jen-huang

jen-huang May 14, 2020

Author Contributor

Followed up with you on Slack about this 🙂

This comment has been minimized.

Copy link
@jen-huang

jen-huang May 14, 2020

Author Contributor

For prosperity, info about stop() lifecycle method:

  • In the browser, stop() is called when user navigates away from Kibana (source)
  • Teardown actions when user leaves the plugin should be returned from AppMount method (source)

The code here is modeled after this example.

unmount();
teardownIngestManager(coreStart);
};
},
});
}
Expand Down

0 comments on commit 2950370

Please sign in to comment.