Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds page headers for updated UX #2083

Merged
merged 27 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
de18a7c
Adds initial commit to add header components and modifies get started…
DarshitChanpura Aug 7, 2024
a773c6a
Updates auth-view page
DarshitChanpura Aug 7, 2024
128d15c
Updates user edit and create pages
DarshitChanpura Aug 7, 2024
cfc9299
Updates user permissions page
DarshitChanpura Aug 7, 2024
baea892
Updates dashboards tenancy page
DarshitChanpura Aug 7, 2024
451e957
Updates dashboards audit logs page
DarshitChanpura Aug 7, 2024
d4e5da3
Updates roles and related pages
DarshitChanpura Aug 7, 2024
f4f6278
Updates variable name and fixes indentation
DarshitChanpura Aug 7, 2024
67c4f24
Push logic into new component
derek-ho Aug 7, 2024
8309c66
Lint
derek-ho Aug 7, 2024
9f8b026
Migrate audit logging and tenant tabs to new page header
derek-ho Aug 7, 2024
0b4b9e8
Migrate all tabs to new component
derek-ho Aug 7, 2024
f3f2caf
Remove prop and fix some test failures
derek-ho Aug 7, 2024
2174a3b
fix most tests
derek-ho Aug 8, 2024
6bf5b8e
Fix existing tests
derek-ho Aug 8, 2024
132001e
Push breadcrumb population into child components
derek-ho Aug 9, 2024
44983ad
Migrate breadcrumbs into the page header component for the top level …
derek-ho Aug 9, 2024
a09d643
Lint
derek-ho Aug 9, 2024
9b74854
Update all instances of breadcrumbs to new component and all existing…
derek-ho Aug 9, 2024
ff7b043
Fixes target _blank redirects
DarshitChanpura Aug 9, 2024
d4ed1df
Fixes unit tests
DarshitChanpura Aug 9, 2024
6ccede6
Add tests for new component and breadcrumb function
derek-ho Aug 12, 2024
053c450
Merge branch 'main' into feature/page-header
DarshitChanpura Aug 13, 2024
46f6416
Merge branch 'main' into feature/page-header
DarshitChanpura Aug 15, 2024
8c4d56e
Merge branch 'main' into feature/page-header
derek-ho Aug 16, 2024
442f525
Address PR feedback
derek-ho Aug 19, 2024
040bc3e
Update tests and snapshots
derek-ho Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 16 additions & 62 deletions public/apps/configuration/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* permissions and limitations under the License.
*/

import { EuiBreadcrumb, EuiPage, EuiPageBody, EuiPageSideBar } from '@elastic/eui';
import { flow, partial } from 'lodash';
import { EuiPage, EuiPageBody, EuiPageSideBar } from '@elastic/eui';
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
import { flow } from 'lodash';
import React, { createContext, useState } from 'react';
import { HashRouter as Router, Route, Switch, Redirect } from 'react-router-dom';
import { DataSourceOption } from 'src/plugins/data_source_management/public/components/data_source_menu/types';
Expand All @@ -38,31 +38,37 @@
import { UserList } from './panels/user-list';
import { Action, RouteItem, SubAction } from './types';
import { ResourceType } from '../../../common';
import { buildHashUrl, buildUrl } from './utils/url-builder';
import { buildUrl } from './utils/url-builder';
import { CrossPageToast } from './cross-page-toast';
import { getDataSourceFromUrl, LocalCluster } from '../../utils/datasource-utils';
import { getBreadcrumbs } from './utils/resource-utils';
derek-ho marked this conversation as resolved.
Show resolved Hide resolved

const LANDING_PAGE_URL = '/getstarted';

export const ROUTE_MAP: { [key: string]: RouteItem } = {
getStarted: {
name: 'Get Started',
displayNameWithoutSecurityBase: 'Get started with access control',
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
href: LANDING_PAGE_URL,
},
[ResourceType.roles]: {
name: 'Roles',
displayNameWithoutSecurityBase: 'Roles',
href: buildUrl(ResourceType.roles),
},
[ResourceType.users]: {
name: 'Internal users',
displayNameWithoutSecurityBase: 'Internal users',
href: buildUrl(ResourceType.users),
},
[ResourceType.permissions]: {
name: 'Permissions',
displayNameWithoutSecurityBase: 'Permissions',
href: buildUrl(ResourceType.permissions),
},
[ResourceType.tenants]: {
name: 'Tenants',
displayNameWithoutSecurityBase: 'Dashboard multi-tenancy',
href: buildUrl(ResourceType.tenants),
},
[ResourceType.tenantsConfigureTab]: {
Expand All @@ -71,10 +77,12 @@
},
[ResourceType.auth]: {
name: 'Authentication',
displayNameWithoutSecurityBase: 'Authentication and authorization',
href: buildUrl(ResourceType.auth),
},
[ResourceType.auditLogging]: {
name: 'Audit logs',
displayNameWithoutSecurityBase: 'Audit logs',
href: buildUrl(ResourceType.auditLogging),
},
};
Expand All @@ -100,39 +108,6 @@
...(multitenancyEnabled ? [buildUrl(ResourceType.tenantsConfigureTab)] : []),
]);

export function getBreadcrumbs(
resourceType?: ResourceType,
pageTitle?: string,
subAction?: string
): EuiBreadcrumb[] {
const breadcrumbs: EuiBreadcrumb[] = [
{
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 All @@ -154,6 +129,7 @@
const dataSourceFromUrl = dataSourceEnabled ? getDataSourceFromUrl() : LocalCluster;

const [dataSource, setDataSource] = useState<DataSourceOption>(dataSourceFromUrl);
const includeSecurityBase = !props.coreStart.uiSettings.get('home:useNewHomePage');

return (
<DataSourceContext.Provider value={{ dataSource, setDataSource }}>
Expand All @@ -173,100 +149,79 @@
<Route
path={buildUrl(ResourceType.roles, Action.edit) + '/:roleName/' + SubAction.mapuser}
render={(match) => (
<RoleEditMappedUser
buildBreadcrumbs={partial(setGlobalBreadcrumbs, ResourceType.roles)}
{...{ ...props, ...decodeParams(match.match.params) }}
/>
<RoleEditMappedUser {...{ ...props, ...decodeParams(match.match.params) }} />

Check warning on line 152 in public/apps/configuration/app-router.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/app-router.tsx#L152

Added line #L152 was not covered by tests
)}
/>
<Route
path={buildUrl(ResourceType.roles, Action.view) + '/:roleName/:prevAction?'}
render={(match) => (
<RoleView
buildBreadcrumbs={partial(setGlobalBreadcrumbs, ResourceType.roles)}
{...{ ...props, ...decodeParams(match.match.params) }}
/>
<RoleView {...{ ...props, ...decodeParams(match.match.params) }} />

Check warning on line 158 in public/apps/configuration/app-router.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/app-router.tsx#L158

Added line #L158 was not covered by tests
)}
/>
<Route
path={buildUrl(ResourceType.roles) + '/:action/:sourceRoleName?'}
render={(match) => (
<RoleEdit
buildBreadcrumbs={partial(setGlobalBreadcrumbs, ResourceType.roles)}
{...{ ...props, ...decodeParams(match.match.params) }}
/>
<RoleEdit {...{ ...props, ...decodeParams(match.match.params) }} />

Check warning on line 164 in public/apps/configuration/app-router.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/app-router.tsx#L164

Added line #L164 was not covered by tests
)}
/>
<Route
path={ROUTE_MAP.roles.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.roles);
return <RoleList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.auth.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.auth);
return <AuthView {...props} />;
}}
/>
<Route
path={buildUrl(ResourceType.users) + '/:action/:sourceUserName?'}
render={(match) => (
<InternalUserEdit
buildBreadcrumbs={partial(setGlobalBreadcrumbs, ResourceType.users)}
{...{ ...props, ...decodeParams(match.match.params) }}
/>
<InternalUserEdit {...{ ...props, ...decodeParams(match.match.params) }} />

Check warning on line 182 in public/apps/configuration/app-router.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/app-router.tsx#L182

Added line #L182 was not covered by tests
)}
/>
<Route
path={ROUTE_MAP.users.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.users);
return <UserList {...props} />;
}}
/>
<Route
path={buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_GENERAL_SETTINGS_EDIT}
render={() => {
setGlobalBreadcrumbs(ResourceType.auditLogging, 'General settings');
return <AuditLoggingEditSettings setting={'general'} {...props} />;
}}
/>
<Route
path={buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT}
render={() => {
setGlobalBreadcrumbs(ResourceType.auditLogging, 'Compliance settings');
return <AuditLoggingEditSettings setting={'compliance'} {...props} />;
}}
/>
<Route
path={ROUTE_MAP.auditLogging.href + '/:fromType?'}
render={(match) => {
setGlobalBreadcrumbs(ResourceType.auditLogging);
return <AuditLogging {...{ ...props, ...match.match.params }} />;
}}
/>
<Route
path={ROUTE_MAP.permissions.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.permissions);
return <PermissionList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.getStarted.href}
render={() => {
setGlobalBreadcrumbs();
return <GetStarted {...props} />;
}}
/>
{multitenancyEnabled && (
<Route
path={ROUTE_MAP.tenants.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Manage'} {...props} />;
}}
/>
Expand All @@ -275,7 +230,6 @@
<Route
path={ROUTE_MAP.tenantsConfigureTab.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Configure'} {...props} />;
}}
/>
Expand Down
65 changes: 65 additions & 0 deletions public/apps/configuration/header/header-components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import React from 'react';
import { flow } from 'lodash';
import { ControlProps, DescriptionProps, HeaderProps } from './header-props';
import { getBreadcrumbs } from '../utils/resource-utils';

// controlType should be one of: https://github.com/AMoo-Miki/OpenSearch-Dashboards/blob/header-collective/src/plugins/navigation/public/top_nav_menu/top_nav_control_data.tsx#L91
derek-ho marked this conversation as resolved.
Show resolved Hide resolved

export const HeaderButtonOrLink = React.memo((props: ControlProps) => {
const { HeaderControl } = props.navigation.ui;

Check warning on line 24 in public/apps/configuration/header/header-components.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/header/header-components.tsx#L24

Added line #L24 was not covered by tests

return (

Check warning on line 26 in public/apps/configuration/header/header-components.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/header/header-components.tsx#L26

Added line #L26 was not covered by tests
<HeaderControl
setMountPoint={props.application.setAppRightControls}
controls={props.controls}
className={props.className}
/>
);
});

export const PageHeader = (props: HeaderProps & DescriptionProps & ControlProps) => {
const { HeaderControl } = props.navigation.ui; // need to get this from SecurityPluginStartDependencies
const useNewUx = props.coreStart.uiSettings.get('home:useNewHomePage');
flow(getBreadcrumbs, props.coreStart.chrome.setBreadcrumbs)(
!useNewUx,
props.resourceType,
props.pageTitle,
props.subAction,
props.count
);
if (useNewUx) {
return (
<>
{props.descriptionControls ? (
<HeaderControl
setMountPoint={props.coreStart.application.setAppDescriptionControls}
controls={props.descriptionControls}
/>
) : null}
{props.controlControls ? (
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
<HeaderControl
setMountPoint={props.coreStart.application.setAppRightControls}
controls={props.controlControls}
/>
) : null}
</>
);
} else {
return props.fallBackComponent;
}
};
37 changes: 37 additions & 0 deletions public/apps/configuration/header/header-props.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import { CoreStart } from 'opensearch-dashboards/public';
import { NavigationPublicPluginStart } from 'src/plugins/navigation/public';
import { TopNavControlData } from 'src/plugins/navigation/public/top_nav_menu/top_nav_control_data';
import { ResourceType } from '../../../../common';

export interface HeaderProps {
navigation: NavigationPublicPluginStart;
coreStart: CoreStart;
fallBackComponent: JSX.Element;
resourceType?: ResourceType;
pageTitle?: string;
subAction?: string;
count?: number;
}

export interface ControlProps {
controlControls?: TopNavControlData[];
}

export interface DescriptionProps {
descriptionControls?: TopNavControlData[];
}
Loading
Loading