mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
lint fixes, revert tests
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
cd7f906afc
commit
39fc5a7f84
@ -26,6 +26,7 @@ export class ExamplePage extends React.Component<{ extension: LensRendererExtens
|
|||||||
const doodleStyle = {
|
const doodleStyle = {
|
||||||
width: "200px"
|
width: "200px"
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex column gaps align-flex-start" style={{ padding: 24 }}>
|
<div className="flex column gaps align-flex-start" style={{ padding: 24 }}>
|
||||||
<div style={doodleStyle}><CoffeeDoodle accent="#3d90ce"/></div>
|
<div style={doodleStyle}><CoffeeDoodle accent="#3d90ce"/></div>
|
||||||
|
|||||||
@ -70,31 +70,31 @@ describe("globalPageRegistry", () => {
|
|||||||
], ext);
|
], ext);
|
||||||
});
|
});
|
||||||
|
|
||||||
// describe("getByPageMenuTarget", () => {
|
describe("getByPageMenuTarget", () => {
|
||||||
// it("matching to first registered page without id", () => {
|
it("matching to first registered page without id", () => {
|
||||||
// const page = globalPageRegistry.getByPageMenuTarget({ extensionId: ext.name });
|
const page = globalPageRegistry.getByPageTarget({ extensionId: ext.name });
|
||||||
//
|
|
||||||
// expect(page.id).toEqual(undefined);
|
expect(page.id).toEqual(undefined);
|
||||||
// expect(page.extensionId).toEqual(ext.name);
|
expect(page.extensionId).toEqual(ext.name);
|
||||||
// expect(page.url).toEqual(getExtensionPageUrl({ extensionId: ext.name }));
|
expect(page.url).toEqual(getExtensionPageUrl({ extensionId: ext.name }));
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
// it("returns matching page", () => {
|
it("returns matching page", () => {
|
||||||
// const page = globalPageRegistry.getByPageMenuTarget({
|
const page = globalPageRegistry.getByPageTarget({
|
||||||
// pageId: "test-page",
|
pageId: "test-page",
|
||||||
// extensionId: ext.name
|
extensionId: ext.name
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
// expect(page.id).toEqual("test-page");
|
expect(page.id).toEqual("test-page");
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
// it("returns null if target not found", () => {
|
it("returns null if target not found", () => {
|
||||||
// const page = globalPageRegistry.getByPageMenuTarget({
|
const page = globalPageRegistry.getByPageTarget({
|
||||||
// pageId: "wrong-page",
|
pageId: "wrong-page",
|
||||||
// extensionId: ext.name
|
extensionId: ext.name
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
// expect(page).toBeNull();
|
expect(page).toBeNull();
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -37,12 +37,13 @@ export interface RegisteredPage extends PageRegistration {
|
|||||||
url: string; // registered extension's page URL (without page params)
|
url: string; // registered extension's page URL (without page params)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getExtensionPageUrl<P extends object>(target: PageTarget): string {
|
export function getExtensionPageUrl(target: PageTarget): string {
|
||||||
const { extensionId, pageId = "", params: targetParams = {} } = target;
|
const { extensionId, pageId = "", params: targetParams = {} } = target;
|
||||||
let stringifiedParams = "";
|
let stringifiedParams = "";
|
||||||
|
|
||||||
// stringify params to matched target page
|
// stringify params to matched target page
|
||||||
const page = globalPageRegistry.getByPageTarget(target) || clusterPageRegistry.getByPageTarget(target);
|
const page = globalPageRegistry.getByPageTarget(target) || clusterPageRegistry.getByPageTarget(target);
|
||||||
|
|
||||||
if (page?.params) {
|
if (page?.params) {
|
||||||
const searchParams = page.params.map(urlParam => {
|
const searchParams = page.params.map(urlParam => {
|
||||||
return urlParam.toSearchString({
|
return urlParam.toSearchString({
|
||||||
@ -51,6 +52,7 @@ export function getExtensionPageUrl<P extends object>(target: PageTarget): strin
|
|||||||
withPrefix: false,
|
withPrefix: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (searchParams.length > 0) {
|
if (searchParams.length > 0) {
|
||||||
stringifiedParams = `?${searchParams.join("&")}`;
|
stringifiedParams = `?${searchParams.join("&")}`;
|
||||||
}
|
}
|
||||||
@ -64,6 +66,7 @@ export class PageRegistry extends BaseRegistry<RegisteredPage> {
|
|||||||
add(pages: PageRegistration | PageRegistration[], extension: LensExtension) {
|
add(pages: PageRegistration | PageRegistration[], extension: LensExtension) {
|
||||||
try {
|
try {
|
||||||
const items = [pages].flat().map(page => this.registerPage(page, extension));
|
const items = [pages].flat().map(page => this.registerPage(page, extension));
|
||||||
|
|
||||||
return super.add(items);
|
return super.add(items);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return Function; // no-op
|
return Function; // no-op
|
||||||
@ -74,6 +77,7 @@ export class PageRegistry extends BaseRegistry<RegisteredPage> {
|
|||||||
try {
|
try {
|
||||||
const { id: pageId } = page;
|
const { id: pageId } = page;
|
||||||
const extensionId = ext.name;
|
const extensionId = ext.name;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...page,
|
...page,
|
||||||
extensionId,
|
extensionId,
|
||||||
@ -85,7 +89,7 @@ export class PageRegistry extends BaseRegistry<RegisteredPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getByPageTarget(target: PageTarget): RegisteredPage | null {
|
getByPageTarget(target: PageTarget): RegisteredPage | null {
|
||||||
return this.getItems().find(page => page.extensionId === target.extensionId && page.id === target.pageId);
|
return this.getItems().find(page => page.extensionId === target.extensionId && page.id === target.pageId) || null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,6 +36,7 @@ export class CrdList extends React.Component {
|
|||||||
|
|
||||||
onSelectGroup(group: string) {
|
onSelectGroup(group: string) {
|
||||||
const groups = new Set(this.groups);
|
const groups = new Set(this.groups);
|
||||||
|
|
||||||
if (groups.has(group)) {
|
if (groups.has(group)) {
|
||||||
groups.delete(group); // toggle selection
|
groups.delete(group); // toggle selection
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -159,11 +159,13 @@ export class ClustersMenu extends React.Component<Props> {
|
|||||||
<div className="extensions">
|
<div className="extensions">
|
||||||
{globalPageMenuRegistry.getItems().map(({ title, target, components: { Icon } }) => {
|
{globalPageMenuRegistry.getItems().map(({ title, target, components: { Icon } }) => {
|
||||||
const registeredPage = globalPageRegistry.getByPageTarget(target);
|
const registeredPage = globalPageRegistry.getByPageTarget(target);
|
||||||
|
|
||||||
if (!registeredPage){
|
if (!registeredPage){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const pageUrl = getExtensionPageUrl(target);
|
const pageUrl = getExtensionPageUrl(target);
|
||||||
const isActive = isActiveRoute(registeredPage.url);
|
const isActive = isActiveRoute(registeredPage.url);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Icon
|
<Icon
|
||||||
key={pageUrl}
|
key={pageUrl}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ export const kubeSelectedUrlParam = createUrlParam({
|
|||||||
|
|
||||||
export function showDetails(details = "", resetSelected = true) {
|
export function showDetails(details = "", resetSelected = true) {
|
||||||
const detailsUrl = getDetailsUrl(details, resetSelected);
|
const detailsUrl = getDetailsUrl(details, resetSelected);
|
||||||
|
|
||||||
navigation.merge({ search: detailsUrl });
|
navigation.merge({ search: detailsUrl });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,11 +39,15 @@ export function hideDetails() {
|
|||||||
|
|
||||||
export function getDetailsUrl(details: string, resetSelected = false) {
|
export function getDetailsUrl(details: string, resetSelected = false) {
|
||||||
const detailsUrl = kubeDetailsUrlParam.toSearchString({ value: details });
|
const detailsUrl = kubeDetailsUrlParam.toSearchString({ value: details });
|
||||||
|
|
||||||
if (resetSelected) {
|
if (resetSelected) {
|
||||||
const params = new URLSearchParams(detailsUrl);
|
const params = new URLSearchParams(detailsUrl);
|
||||||
|
|
||||||
params.delete(kubeSelectedUrlParam.name);
|
params.delete(kubeSelectedUrlParam.name);
|
||||||
|
|
||||||
return `?${params.toString()}`;
|
return `?${params.toString()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return detailsUrl;
|
return detailsUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -80,14 +80,17 @@ export class Sidebar extends React.Component<Props> {
|
|||||||
|
|
||||||
getTabLayoutRoutes(menu: ClusterPageMenuRegistration): TabLayoutRoute[] {
|
getTabLayoutRoutes(menu: ClusterPageMenuRegistration): TabLayoutRoute[] {
|
||||||
const routes: TabLayoutRoute[] = [];
|
const routes: TabLayoutRoute[] = [];
|
||||||
|
|
||||||
if (!menu.id) {
|
if (!menu.id) {
|
||||||
return routes;
|
return routes;
|
||||||
}
|
}
|
||||||
|
|
||||||
clusterPageMenuRegistry.getSubItems(menu).forEach((subMenu) => {
|
clusterPageMenuRegistry.getSubItems(menu).forEach((subMenu) => {
|
||||||
const subPage = clusterPageRegistry.getByPageTarget(subMenu.target);
|
const subPage = clusterPageRegistry.getByPageTarget(subMenu.target);
|
||||||
|
|
||||||
if (subPage) {
|
if (subPage) {
|
||||||
const { extensionId, id: pageId } = subPage;
|
const { extensionId, id: pageId } = subPage;
|
||||||
|
|
||||||
routes.push({
|
routes.push({
|
||||||
routePath: subPage.url,
|
routePath: subPage.url,
|
||||||
url: getExtensionPageUrl({ extensionId, pageId, params: subMenu.target.params }),
|
url: getExtensionPageUrl({ extensionId, pageId, params: subMenu.target.params }),
|
||||||
@ -103,6 +106,7 @@ export class Sidebar extends React.Component<Props> {
|
|||||||
renderRegisteredMenus() {
|
renderRegisteredMenus() {
|
||||||
return clusterPageMenuRegistry.getRootItems().map((menuItem) => {
|
return clusterPageMenuRegistry.getRootItems().map((menuItem) => {
|
||||||
const registeredPage = clusterPageRegistry.getByPageTarget(menuItem.target);
|
const registeredPage = clusterPageRegistry.getByPageTarget(menuItem.target);
|
||||||
|
|
||||||
if (!registeredPage) {
|
if (!registeredPage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,9 @@ import { navigation } from "./index";
|
|||||||
|
|
||||||
export function navigate(location: LocationDescriptor) {
|
export function navigate(location: LocationDescriptor) {
|
||||||
const currentLocation = navigation.getPath();
|
const currentLocation = navigation.getPath();
|
||||||
|
|
||||||
navigation.push(location);
|
navigation.push(location);
|
||||||
|
|
||||||
if (currentLocation === navigation.getPath()) {
|
if (currentLocation === navigation.getPath()) {
|
||||||
navigation.goBack(); // prevent sequences of same url in history
|
navigation.goBack(); // prevent sequences of same url in history
|
||||||
}
|
}
|
||||||
@ -26,5 +28,6 @@ export function getMatchedClusterId(): string {
|
|||||||
exact: true,
|
exact: true,
|
||||||
path: clusterViewRoute.path
|
path: clusterViewRoute.path
|
||||||
});
|
});
|
||||||
|
|
||||||
return matched?.params.clusterId;
|
return matched?.params.clusterId;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,21 +34,27 @@ export class UrlParam<V = any | any[]> {
|
|||||||
|
|
||||||
parse(values: string[]): V {
|
parse(values: string[]): V {
|
||||||
const { parse, multiValues } = this.init;
|
const { parse, multiValues } = this.init;
|
||||||
|
|
||||||
if (!multiValues) values.splice(1); // reduce values to single item
|
if (!multiValues) values.splice(1); // reduce values to single item
|
||||||
const parsedValues = [parse ? parse(values) : values].flat();
|
const parsedValues = [parse ? parse(values) : values].flat();
|
||||||
|
|
||||||
return multiValues ? parsedValues : parsedValues[0] as any;
|
return multiValues ? parsedValues : parsedValues[0] as any;
|
||||||
}
|
}
|
||||||
|
|
||||||
stringify(value: V = this.get()): string {
|
stringify(value: V = this.get()): string {
|
||||||
const { stringify, multiValues, multiValueSep, skipEmpty } = this.init;
|
const { stringify, multiValues, multiValueSep, skipEmpty } = this.init;
|
||||||
|
|
||||||
if (skipEmpty && this.isEmpty(value)) {
|
if (skipEmpty && this.isEmpty(value)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (multiValues) {
|
if (multiValues) {
|
||||||
const values = [value].flat();
|
const values = [value].flat();
|
||||||
const stringValues = [stringify ? stringify(value) : values.map(String)].flat();
|
const stringValues = [stringify ? stringify(value) : values.map(String)].flat();
|
||||||
|
|
||||||
return stringValues.join(multiValueSep);
|
return stringValues.join(multiValueSep);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [stringify ? stringify(value) : String(value)].flat()[0];
|
return [stringify ? stringify(value) : String(value)].flat()[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,11 +66,13 @@ export class UrlParam<V = any | any[]> {
|
|||||||
if (skipEmpty && this.isEmpty(value)) {
|
if (skipEmpty && this.isEmpty(value)) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
set(value: V, { mergeGlobals = true, replaceHistory = false } = {}) {
|
set(value: V, { mergeGlobals = true, replaceHistory = false } = {}) {
|
||||||
const search = this.toSearchString({ mergeGlobals, value });
|
const search = this.toSearchString({ mergeGlobals, value });
|
||||||
|
|
||||||
this.history.merge({ search }, replaceHistory);
|
this.history.merge({ search }, replaceHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,11 +97,13 @@ export class UrlParam<V = any | any[]> {
|
|||||||
if (skipEmpty) {
|
if (skipEmpty) {
|
||||||
searchParams.forEach((value: any, paramName) => {
|
searchParams.forEach((value: any, paramName) => {
|
||||||
if (this.isEmpty(value)) searchParams.delete(paramName);
|
if (this.isEmpty(value)) searchParams.delete(paramName);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.from(searchParams).length > 0) {
|
if (Array.from(searchParams).length > 0) {
|
||||||
return `${withPrefix ? "?" : ""}${searchParams}`;
|
return `${withPrefix ? "?" : ""}${searchParams}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user