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

PageRegistration & BaseRegistry refactoring #1334

Merged
merged 15 commits into from Nov 12, 2020
Merged

Conversation

ixrock
Copy link
Member

@ixrock ixrock commented Nov 11, 2020

Changes:

  • Registering menu items (ClusterManager/Cluster) moved away to separated registry from PageRegistry
  • Refactored BaseRegistry so now all extension pages registered under /extension/:name route prefix
  • Refactored TabLayout

close #1258

Fix for hello-world example: https://github.com/lensapp/hello-world-extension

import { Component, Interface, LensRendererExtension } from "@k8slens/extensions";
import { ExampleIcon, ExamplePage } from "./page"
import React from "react"

export default class ExampleExtension extends LensRendererExtension {
  clusterPages = [
    {
      id: Symbol("example-extension"),
      components: {
        Page: () => <ExamplePage extension={this}/>,
      }
    }
  ]

  clusterPageMenus = [
    {
      id: this.clusterPages[0].id,
      title: "Hello World",
      components: {
        Icon: ExampleIcon
      }
    }
  ]
}

Signed-off-by: Roman <ixrock@gmail.com>
…_1258

# Conflicts:
#	src/extensions/lens-renderer-extension.ts
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
@ixrock ixrock requested review from jakolehm and a team November 11, 2020 15:43
@jakolehm jakolehm added area/extension Something to related to the extension api enhancement New feature or request labels Nov 11, 2020
@jakolehm jakolehm added this to the 4.0.0 milestone Nov 11, 2020
package.json Outdated
@@ -241,6 +241,7 @@
"openid-client": "^3.15.2",
"path-to-regexp": "^6.1.0",
"proper-lockfile": "^4.1.1",
"react-router": "^5.2.0",
Copy link
Member Author

@ixrock ixrock Nov 11, 2020

Choose a reason for hiding this comment

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

This is moved to normal dependencies since required in runtime (matchPath is used in page-registry.ts and page-menu-registry.ts)

Copy link
Member Author

Choose a reason for hiding this comment

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

react apparently also required internally in react-router when used in runtime

Signed-off-by: Roman <ixrock@gmail.com>
click() {
windowManager.navigate(supportPageURL());
click: () => {
windowManager.navigate(this.getPageUrl(pageUrl)); // todo: simplify
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you see my comment here? Maybe this is similar to what you are already planning...

Copy link
Member Author

@ixrock ixrock Nov 11, 2020

Choose a reason for hiding this comment

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

  1. Page registration doesn't have ID
  2. Registered page exists only in LensRendererExtension but access to URL might need from LensMainExtension as well (like from top-menu support item)
  3. If even this possible should be done in another PR

Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
@@ -20,9 +18,9 @@ export default class SupportPageRendererExtension extends LensRendererExtension
item: (
<div
className="flex align-center gaps hover-highlight"
onClick={() => Navigation.navigate(supportPageURL())}
onClick={() => Navigation.navigate(this.getPageUrl(pageUrl))}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you instead have a navigate() method on LensRendererExtension (or LensExtension?) then this could be

Suggested change
onClick={() => Navigation.navigate(this.getPageUrl(pageUrl))}
onClick={() => this.navigate(pageUrl)}

(the navigate() method would call this.getPageUrl(), no need to expose it. This aligns with what @jakolehm did in #1323

Copy link
Contributor

Choose a reason for hiding this comment

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

guess that didn't work out. Would be nice if it were possible ...

Copy link
Contributor

Choose a reason for hiding this comment

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

See #1345

Copy link
Member Author

Choose a reason for hiding this comment

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

Worked in dev/local build :/

…_1258

# Conflicts:
#	extensions/support-page/main.ts
#	src/extensions/renderer-api/navigation.ts
Signed-off-by: Roman <ixrock@gmail.com>
@@ -100,13 +100,22 @@ import { ExamplePage } from "./src/example-page"
export default class ExampleRendererExtension extends LensRendererExtension {
globalPages = [
{
path: "/example-route",
hideInMenu: true,
routePath: "/items/:id?",
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems cumbersome if the extension developer has to specify this. Can it default to this?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just an example. Now could be optional since we have route-prefix for all extensions.

path: "/extension-example",
title: "Example Extension",
routePath: "/extension-example",
exact: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

can default be true? So developer doesn't have to set it unless they want it false (which assumes they know what they are doing)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is optional. Could be default whatever we want :)

@@ -20,9 +18,9 @@ export default class SupportPageRendererExtension extends LensRendererExtension
item: (
<div
className="flex align-center gaps hover-highlight"
onClick={() => Navigation.navigate(supportPageURL())}
onClick={() => Navigation.navigate(this.getPageUrl(pageUrl))}
Copy link
Contributor

Choose a reason for hiding this comment

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

guess that didn't work out. Would be nice if it were possible ...

Comment on lines 9 to 13
async navigate(location: string, frameId?: number) {
await WindowManager.getInstance<WindowManager>().navigate(location, frameId)
const windowManager = WindowManager.getInstance<WindowManager>();
const url = this.getPageUrl(location);
await windowManager.navigate(url, frameId)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this a lot but @jakolehm couldn't get it to work?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this a lot but @jakolehm couldn't get it to work?

It works on main extension.

@@ -98,108 +97,100 @@ export class Sidebar extends React.Component<Props> {
</div>
<div className="sidebar-nav flex column box grow-fixed">
<SidebarNavItem
id="cluster"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the integration tests rely on these ids

Copy link
Contributor

Choose a reason for hiding this comment

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

@ixrock pls revert removal of ids.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is bad.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes it's bad, but let's fix that in separate PR

@@ -98,108 +97,100 @@ export class Sidebar extends React.Component<Props> {
</div>
<div className="sidebar-nav flex column box grow-fixed">
<SidebarNavItem
id="cluster"
Copy link
Contributor

Choose a reason for hiding this comment

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

@ixrock pls revert removal of ids.

})
remove(items: T[], key: LensExtension = null) {
const storedItems = this.items.get(key);
if (storedItems) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could be also be

if (!storedItems) return;

…_1258

# Conflicts:
#	src/extensions/lens-renderer-extension.ts
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
…_1258

# Conflicts:
#	extensions/support-page/renderer.tsx
subPages?: (PageRegistration & TabRoute)[];
export interface PageRegistration extends BaseRegistryItem {
routePath?: string; // additional (suffix) route path to base extension's route: "/extension/:name"
exact?: boolean; // route matching flag, see: https://reactrouter.com/web/api/NavLink/exact-bool
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit mystery flag ... when does it needs to be set?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was hoping provided url from comment will explain this.. but.. it's about strict matching route:
e.g. if you have route like /page with exact: true it will match only this, but not /page/sub-page

Signed-off-by: Roman <ixrock@gmail.com>
@nevalla
Copy link
Contributor

nevalla commented Nov 12, 2020

Something is off with the support icon/extension. Cannot click it.
image

@ixrock
Copy link
Member Author

ixrock commented Nov 12, 2020

@nevalla you should recompile support-page extension (also got this after master-merge)
This is comes from #1331

@jakolehm jakolehm merged commit faa1cef into master Nov 12, 2020
@jakolehm jakolehm deleted the page_registry_issue_1258 branch November 12, 2020 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/extension Something to related to the extension api enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move navigation/menus registration from PageRegistration to own registry
4 participants