Skip to content

Commit

Permalink
feat: filter applications according to categories (#103)
Browse files Browse the repository at this point in the history
* add features for public workspace

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* change default header name

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* remove recently visited category in management workspace

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* change default header name

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* change icon and title for workspace overview

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* add overview to management workspace featuer

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* bug fix: only show recently visited if the workspace has no feature

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* add recently visited when workspace disabled

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* change default value from null to undefined

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

---------

Signed-off-by: yuye-aws <yuyezhu@amazon.com>
  • Loading branch information
yuye-aws authored and SuZhou-Joe committed Aug 31, 2023
1 parent 82dbf0d commit acca4b2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/core/public/chrome/nav_links/nav_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ type LinksUpdater = (navLinks: Map<string, NavLinkWrapper>) => Map<string, NavLi

export class NavLinksService {
private readonly stop$ = new ReplaySubject(1);
private filteredNavLinks$ = new BehaviorSubject<ReadonlyMap<string, ChromeNavLink>>(new Map());
private filteredNavLinks$ = new BehaviorSubject<ReadonlyMap<string, ChromeNavLink> | undefined>(
undefined
);

public start({ application, http }: StartDeps): ChromeNavLinks {
const appLinks$ = application.applications$.pipe(
Expand Down Expand Up @@ -169,7 +171,9 @@ export class NavLinksService {
getFilteredNavLinks$: () => {
return combineLatest([navLinks$, this.filteredNavLinks$]).pipe(
map(([navLinks, filteredNavLinks]) =>
filteredNavLinks.size ? sortChromeNavLinks(filteredNavLinks) : sortNavLinks(navLinks)
filteredNavLinks === undefined
? sortNavLinks(navLinks)
: sortChromeNavLinks(filteredNavLinks)
),
takeUntil(this.stop$)
);
Expand Down
19 changes: 13 additions & 6 deletions src/core/public/chrome/ui/header/collapsible_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
} from './nav_link';
import { ChromeBranding } from '../../chrome_service';
import { CollapsibleNavHeader } from './collapsible_nav_header';
import { MANAGEMENT_WORKSPACE_ID } from '../../../utils';

function getAllCategories(allCategorizedLinks: Record<string, CollapsibleNavLink[]>) {
const allCategories = {} as Record<string, AppCategory | undefined>;
Expand Down Expand Up @@ -153,14 +154,20 @@ export function CollapsibleNav({
}: Props) {
const navLinks = useObservable(observables.navLinks$, []).filter((link) => !link.hidden);
const recentlyAccessed = useObservable(observables.recentlyAccessed$, []);
const workspaceEnabled = useObservable(workspaces.workspaceEnabled$, false);
const currentWorkspaceId = useObservable(workspaces.currentWorkspaceId$, '');
const allNavLinks: CollapsibleNavLink[] = [...navLinks];
if (recentlyAccessed.length) {
allNavLinks.push(
...recentlyAccessed.map((link) => createRecentChromeNavLink(link, navLinks, basePath))
);
} else {
allNavLinks.push(emptyRecentlyVisited);
if (!workspaceEnabled || currentWorkspaceId !== MANAGEMENT_WORKSPACE_ID) {
// no recently visited in management workspace
if (recentlyAccessed.length) {
allNavLinks.push(
...recentlyAccessed.map((link) => createRecentChromeNavLink(link, navLinks, basePath))
);
} else {
allNavLinks.push(emptyRecentlyVisited);
}
}

const appId = useObservable(observables.appId$, '');
const lockRef = useRef<HTMLButtonElement>(null);
const groupedNavLinks = groupBy(allNavLinks, (link) => link?.category?.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function CollapsibleNavHeader({ workspaces }: Props) {
const defaultHeaderName = i18n.translate(
'core.ui.primaryNav.workspacePickerMenu.defaultHeaderName',
{
defaultMessage: 'OpenSearch Analytics',
defaultMessage: 'OpenSearch Dashboards',
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const WorkspaceMenu = ({ basePath, getUrlForApp, observables }: Props) =>
const defaultHeaderName = i18n.translate(
'core.ui.primaryNav.workspacePickerMenu.defaultHeaderName',
{
defaultMessage: 'OpenSearch Analytics',
defaultMessage: 'OpenSearch Dashboards',
}
);
const managementWorkspaceName =
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps>
core.application.register({
id: WORKSPACE_OVERVIEW_APP_ID,
title: i18n.translate('workspace.settings.workspaceOverview', {
defaultMessage: 'Home',
defaultMessage: 'Overview',
}),
order: 0,
euiIconType: 'home',
euiIconType: 'grid',
navLinkStatus: AppNavLinkStatus.default,
async mount(params: AppMountParameters) {
const { renderOverviewApp } = await import('./application');
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/workspace/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { WorkspaceClientWithSavedObject } from './workspace_client';
import { WorkspaceSavedObjectsClientWrapper } from './saved_objects';
import { registerRoutes } from './routes';
import { ConfigSchema } from '../config';
import { WORKSPACE_OVERVIEW_APP_ID } from '../common/constants';

export class WorkspacePlugin implements Plugin<{}, {}> {
private readonly logger: Logger;
Expand Down Expand Up @@ -150,7 +151,7 @@ export class WorkspacePlugin implements Plugin<{}, {}> {
name: i18n.translate('workspaces.management.workspace.default.name', {
defaultMessage: 'Management',
}),
features: [`@${DEFAULT_APP_CATEGORIES.management.id}`],
features: [`@${DEFAULT_APP_CATEGORIES.management.id}`, WORKSPACE_OVERVIEW_APP_ID],
},
managementWorkspaceACL.getPermissions()
),
Expand Down

0 comments on commit acca4b2

Please sign in to comment.