Skip to content

Commit

Permalink
Migrate breadcrumbs into the page header component for the top level …
Browse files Browse the repository at this point in the history
…of all pages

Signed-off-by: Derek Ho <dxho@amazon.com>
  • Loading branch information
derek-ho committed Aug 9, 2024
1 parent 132001e commit 44983ad
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 71 deletions.
55 changes: 1 addition & 54 deletions public/apps/configuration/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { ResourceType } from '../../../common';
import { buildHashUrl, buildUrl } from './utils/url-builder';
import { CrossPageToast } from './cross-page-toast';
import { getDataSourceFromUrl, LocalCluster } from '../../utils/datasource-utils';
import { getBreadcrumbs } from './utils/resource-utils';

const LANDING_PAGE_URL = '/getstarted';

Expand Down Expand Up @@ -107,42 +108,6 @@ export const allNavPanelUrls = (multitenancyEnabled: boolean) =>
...(multitenancyEnabled ? [buildUrl(ResourceType.tenantsConfigureTab)] : []),
]);

export function getBreadcrumbs(
includeSecurityBase: boolean,
resourceType?: ResourceType,
pageTitle?: string,
subAction?: string
): EuiBreadcrumb[] {
const breadcrumbs: EuiBreadcrumb[] = includeSecurityBase
? [
{
text: 'Security',
href: buildHashUrl(),
},
]
: [];

if (resourceType) {
breadcrumbs.push({
text: ROUTE_MAP[resourceType].name,
href: buildHashUrl(resourceType),
});
}

if (pageTitle) {
breadcrumbs.push({
text: pageTitle,
});
}

if (subAction) {
breadcrumbs.push({
text: subAction,
});
}
return breadcrumbs;
}

function decodeParams(params: { [k: string]: string }): any {
return Object.keys(params).reduce((obj: { [k: string]: string }, key: string) => {
obj[key] = decodeURIComponent(params[key]);
Expand Down Expand Up @@ -223,14 +188,12 @@ export function AppRouter(props: AppDependencies) {
<Route
path={ROUTE_MAP.roles.href}
render={() => {
// setGlobalBreadcrumbs(includeSecurityBase, ResourceType.roles);
return <RoleList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.auth.href}
render={() => {
// setGlobalBreadcrumbs(includeSecurityBase, ResourceType.auth);
return <AuthView {...props} />;
}}
/>
Expand All @@ -250,58 +213,43 @@ export function AppRouter(props: AppDependencies) {
<Route
path={ROUTE_MAP.users.href}
render={() => {
// setGlobalBreadcrumbs(includeSecurityBase, ResourceType.users);
return <UserList {...props} />;
}}
/>
<Route
path={buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_GENERAL_SETTINGS_EDIT}
render={() => {
// setGlobalBreadcrumbs(
// includeSecurityBase,
// ResourceType.auditLogging,
// 'General settings'
// );
return <AuditLoggingEditSettings setting={'general'} {...props} />;
}}
/>
<Route
path={buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT}
render={() => {
// setGlobalBreadcrumbs(
// includeSecurityBase,
// ResourceType.auditLogging,
// 'Compliance settings'
// );
return <AuditLoggingEditSettings setting={'compliance'} {...props} />;
}}
/>
<Route
path={ROUTE_MAP.auditLogging.href + '/:fromType?'}
render={(match) => {
// setGlobalBreadcrumbs(includeSecurityBase, ResourceType.auditLogging);
return <AuditLogging {...{ ...props, ...match.match.params }} />;
}}
/>
<Route
path={ROUTE_MAP.permissions.href}
render={() => {
// setGlobalBreadcrumbs(includeSecurityBase, ResourceType.permissions);
return <PermissionList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.getStarted.href}
render={() => {
// setGlobalBreadcrumbs(includeSecurityBase);
return <GetStarted {...props} />;
}}
/>
{multitenancyEnabled && (
<Route
path={ROUTE_MAP.tenants.href}
render={() => {
// setGlobalBreadcrumbs(includeSecurityBase, ResourceType.tenants);
return <TenantList tabID={'Manage'} {...props} />;
}}
/>
Expand All @@ -310,7 +258,6 @@ export function AppRouter(props: AppDependencies) {
<Route
path={ROUTE_MAP.tenantsConfigureTab.href}
render={() => {
// setGlobalBreadcrumbs(includeSecurityBase, ResourceType.tenants);
return <TenantList tabID={'Configure'} {...props} />;
}}
/>
Expand Down
20 changes: 8 additions & 12 deletions public/apps/configuration/header/header-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ export const HeaderDescription = React.memo((props: DescriptionProps) => {
export const PageHeader = (props: HeaderProps & DescriptionProps & ControlProps) => {
const { HeaderControl } = props.navigation.ui; // need to get this from SecurityPluginStartDependencies
const useNewUx = props.coreStart.chrome.navGroup.getNavGroupEnabled();
flow(getBreadcrumbs, props.coreStart.chrome.setBreadcrumbs)(
!props.coreStart.uiSettings.get('home:useNewHomePage'),
props.resourceType,
props.pageTitle,
props.subAction,
props.count
);
if (useNewUx) {
flow(getBreadcrumbs, props.coreStart.chrome.setBreadcrumbs)(
!props.coreStart.uiSettings.get('home:useNewHomePage'),
props.resourceType,
props.pageTitle,
props.subAction
);

return (
<>
{props.descriptionControls ? (
Expand All @@ -97,12 +99,6 @@ export const PageHeader = (props: HeaderProps & DescriptionProps & ControlProps)
</>
);
} else {
flow(getBreadcrumbs, props.coreStart.chrome.setBreadcrumbs)(
!props.coreStart.uiSettings.get('home:useNewHomePage'),
props.resourceType,
props.pageTitle,
props.subAction
);
return props.fallBackComponent;
}
};
1 change: 1 addition & 0 deletions public/apps/configuration/header/header-props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface HeaderProps {
resourceType?: ResourceType;
pageTitle?: string;
subAction?: string;
count?: number;
}

export interface ControlProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ export function PermissionList(props: AppDependencies) {
</EuiPageHeader>
}
resourceType={ResourceType.permissions}
count={permissionList.length}
/>
{loading ? (
<EuiLoadingContent />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ exports[`Permission list page AccessError component should load access error co
},
}
}
count={0}
descriptionControls={
Array [
Object {
Expand Down
1 change: 1 addition & 0 deletions public/apps/configuration/panels/role-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ export function RoleList(props: AppDependencies) {
</EuiPageHeader>
}
resourceType={ResourceType.roles}
count={roleData.length}
/>
{loading ? (
<EuiLoadingContent />
Expand Down
3 changes: 1 addition & 2 deletions public/apps/configuration/panels/tenant-list/manage_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ import { PageId } from '../../types';
import { useDeleteConfirmState } from '../../utils/delete-confirm-modal-utils';
import { showTableStatusMessage } from '../../utils/loading-spinner-utils';
import { useContextMenuState } from '../../utils/context-menu';
import { generateResourceName } from '../../utils/resource-utils';
import { generateResourceName, getBreadcrumbs } from '../../utils/resource-utils';
import { DocLinks } from '../../constants';
import { TenantList } from './tenant-list';
import { getBreadcrumbs } from '../../app-router';
import { LocalCluster } from '../../../../utils/datasource-utils';
import { buildUrl } from '../../utils/url-builder';
import { CrossPageToast } from '../../cross-page-toast';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ exports[`Role list AccessError component should load access error component 1`]
},
}
}
count={0}
descriptionControls={
Array [
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ exports[`User list AccessError component should load access error component 1`]
},
}
}
count={0}
descriptionControls={
Array [
Object {
Expand Down
1 change: 1 addition & 0 deletions public/apps/configuration/panels/user-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export function UserList(props: AppDependencies) {
</EuiPageHeader>
}
resourceType={ResourceType.users}
count={userData.length}
/>
{loading ? (
<EuiLoadingContent />
Expand Down
8 changes: 5 additions & 3 deletions public/apps/configuration/utils/resource-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
*/

import { EuiBreadcrumb } from '@elastic/eui';
import { ResourceType } from 'plugins/security-dashboards-plugin/common';
import { ResourceType } from '../../../../common';
import { i18n } from '@osd/i18n';
import { buildHashUrl } from './url-builder';
import { ROUTE_MAP } from '../app-router';

Expand All @@ -37,7 +38,8 @@ export function getBreadcrumbs(
includeSecurityBase: boolean,
resourceType?: ResourceType,
pageTitle?: string,
subAction?: string
subAction?: string,
count?: number,
): EuiBreadcrumb[] {
const breadcrumbs: EuiBreadcrumb[] = includeSecurityBase
? [
Expand All @@ -56,7 +58,7 @@ export function getBreadcrumbs(
});
} else {
breadcrumbs.push({
text: ROUTE_MAP[resourceType].displayNameWithoutSecurityBase,
text: count ? `${ROUTE_MAP[resourceType].displayNameWithoutSecurityBase} (${count})` : ROUTE_MAP[resourceType].displayNameWithoutSecurityBase,
href: buildHashUrl(resourceType),
});
}
Expand Down

0 comments on commit 44983ad

Please sign in to comment.