Skip to content

Commit

Permalink
Improve nav item extensibility
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechszocs committed May 20, 2019
1 parent 67d474a commit ed7595e
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 288 deletions.
36 changes: 25 additions & 11 deletions frontend/packages/console-demo-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import {
Plugin,
ModelFeatureFlag,
HrefNavItem,
ResourceNSNavItem,
ResourceClusterNavItem,
ResourceListPage,
ResourceDetailPage,
ModelFeatureFlag,
} from '@console/plugin-sdk';

// TODO(vojtech): internal code needed by plugins should be moved to console-shared package
import { PodModel } from '@console/internal/models';
import { FLAGS } from '@console/internal/const';

type ConsumedExtensions =
| ModelFeatureFlag
| HrefNavItem
| ResourceNSNavItem
| ResourceClusterNavItem
| ResourceListPage
| ResourceDetailPage
| ModelFeatureFlag;
| ResourceDetailPage;

const plugin: Plugin<ConsumedExtensions> = [
{
type: 'FeatureFlag/Model',
properties: {
model: PodModel,
flag: 'TEST_MODEL_FLAG',
},
},
{
type: 'NavItem/Href',
properties: {
Expand All @@ -32,7 +42,7 @@ const plugin: Plugin<ConsumedExtensions> = [
{
type: 'NavItem/ResourceNS',
properties: {
section: 'Workloads',
section: 'Home',
componentProps: {
name: 'Test ResourceNS Link',
resource: 'pods',
Expand All @@ -41,24 +51,28 @@ const plugin: Plugin<ConsumedExtensions> = [
},
},
{
type: 'ResourcePage/List',
type: 'NavItem/ResourceCluster',
properties: {
model: PodModel,
loader: () => import('@console/internal/components/pod' /* webpackChunkName: "pod" */).then(m => m.PodsPage),
section: 'Home',
componentProps: {
name: 'Test ResourceCluster Link',
resource: 'projects',
required: [FLAGS.OPENSHIFT, 'TEST_MODEL_FLAG'],
},
},
},
{
type: 'ResourcePage/Detail',
type: 'ResourcePage/List',
properties: {
model: PodModel,
loader: () => import('@console/internal/components/pod' /* webpackChunkName: "pod" */).then(m => m.PodsDetailsPage),
loader: () => import('@console/internal/components/pod' /* webpackChunkName: "pod" */).then(m => m.PodsPage),
},
},
{
type: 'FeatureFlag/Model',
type: 'ResourcePage/Detail',
properties: {
model: PodModel,
flag: 'TEST_MODEL_FLAG',
loader: () => import('@console/internal/components/pod' /* webpackChunkName: "pod" */).then(m => m.PodsDetailsPage),
},
},
];
Expand Down
46 changes: 26 additions & 20 deletions frontend/packages/console-plugin-sdk/src/typings/nav.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import { Extension } from '.';
import { K8sKind } from '@console/internal/module/k8s';
import { NavSectionTitle } from '@console/internal/components/nav/section';

import {
NavLinkProps,
HrefLinkProps,
ResourceNSLinkProps,
ResourceClusterLinkProps,
} from '@console/internal/components/nav/items';

namespace ExtensionProperties {
interface NavItem {
// TODO(vojtech): link to existing nav sections by value
section: 'Home' | 'Workloads';
componentProps: {
name: string;
required?: string;
disallowed?: string;
startsWith?: string[];
}
section: NavSectionTitle;
componentProps: Pick<NavLinkProps, 'name' | 'required' | 'disallowed' | 'startsWith'>;
}

export interface HrefNavItem extends NavItem {
componentProps: NavItem['componentProps'] & {
href: string;
activePath?: string;
}
componentProps: NavItem['componentProps'] & Pick<HrefLinkProps, 'href' | 'activePath'>;
}

export interface ResourceNSNavItem extends NavItem {
componentProps: NavItem['componentProps'] & {
resource: string;
model?: K8sKind;
}
componentProps: NavItem['componentProps'] & Pick<ResourceNSLinkProps, 'resource' | 'model'>;
}

export interface ResourceClusterNavItem extends NavItem {
componentProps: NavItem['componentProps'] & Pick<ResourceClusterLinkProps, 'resource' | 'model'>;
}
}

Expand All @@ -36,8 +35,11 @@ export interface ResourceNSNavItem extends Extension<ExtensionProperties.Resourc
type: 'NavItem/ResourceNS';
}

// TODO(vojtech): add ResourceClusterNavItem
export type NavItem = HrefNavItem | ResourceNSNavItem;
export interface ResourceClusterNavItem extends Extension<ExtensionProperties.ResourceClusterNavItem> {
type: 'NavItem/ResourceCluster';
}

export type NavItem = HrefNavItem | ResourceNSNavItem | ResourceClusterNavItem;

export function isHrefNavItem(e: Extension<any>): e is HrefNavItem {
return e.type === 'NavItem/Href';
Expand All @@ -47,6 +49,10 @@ export function isResourceNSNavItem(e: Extension<any>): e is ResourceNSNavItem {
return e.type === 'NavItem/ResourceNS';
}

export function isResourceClusterNavItem(e: Extension<any>): e is ResourceClusterNavItem {
return e.type === 'NavItem/ResourceCluster';
}

export function isNavItem(e: Extension<any>): e is NavItem {
return isHrefNavItem(e) || isResourceNSNavItem(e);
return isHrefNavItem(e) || isResourceNSNavItem(e) || isResourceClusterNavItem(e);
}
Loading

0 comments on commit ed7595e

Please sign in to comment.