lint fixes, revert tests

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman committed 2020-12-03 20:43:50 +02:00
1 parent cd7f906afc
commit 39fc5a7f84
9 files changed
+60 -30

No files matched your search

+3
View File
@@ -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;
}
+11 -1
View File
@@ -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 "";
}