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

Improve nav item extensions #1584

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for moving this extension up in the list is to highlight that each plugin should start with adding its own feature flag(s).

Other extensions like nav items should be gated by those feature flags.

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'],
Copy link
Contributor Author

@vojtechszocs vojtechszocs May 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link is equivalent to

<ResourceClusterLink
  resource="projects"
  name="Test ResourceCluster Link"
  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