mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
1 parent
cd7f906afc
commit
39fc5a7f84
9 files changed
+60
-30
No files matched your search
@@ -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 "";
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user