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