@startinblox/components-ds4go 2.3.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci.yml +8 -2
- package/AGENTS.md +516 -0
- package/biome.json +1 -1
- package/cypress/component/no-component-test.cy.ts +9 -0
- package/cypress/e2e/helpers/components/setupCacheInvalidation.cy.ts +512 -0
- package/cypress/e2e/helpers/components/setupCacheOnResourceReady.cy.ts +483 -0
- package/cypress/e2e/helpers/components/setupComponentSubscriptions.cy.ts +239 -0
- package/cypress/e2e/helpers/components/setupOnSaveReset.cy.ts +380 -0
- package/cypress/e2e/helpers/datas/checkValueInIntervalRecursive.cy.ts +563 -0
- package/cypress/e2e/helpers/datas/dataBuilder.cy.ts +508 -0
- package/cypress/e2e/helpers/datas/filterGenerator.cy.ts +285 -0
- package/cypress/e2e/helpers/datas/filterObjectByDateAfter.cy.ts +389 -0
- package/cypress/e2e/helpers/datas/filterObjectByDateInterval.cy.ts +613 -0
- package/cypress/e2e/helpers/datas/filterObjectById.cy.ts +276 -0
- package/cypress/e2e/helpers/datas/filterObjectByInterval.cy.ts +237 -0
- package/cypress/e2e/helpers/datas/filterObjectByNamedValue.cy.ts +299 -0
- package/cypress/e2e/helpers/datas/filterObjectByType.cy.ts +307 -0
- package/cypress/e2e/helpers/datas/filterObjectByValue.cy.ts +375 -0
- package/cypress/e2e/helpers/datas/sort.cy.ts +293 -0
- package/cypress/e2e/helpers/ui/formatDate.cy.ts +233 -0
- package/cypress/e2e/helpers/utils/requestNavigation.cy.ts +257 -0
- package/cypress/e2e/helpers/utils/uniq.cy.ts +160 -0
- package/cypress/support/e2e.ts +1 -0
- package/cypress.config.ts +2 -0
- package/dist/index.js +1113 -1004
- package/package.json +10 -10
- package/src/components/solid-boilerplate.ts +76 -0
- package/src/helpers/components/componentObjectHandler.ts +5 -7
- package/src/helpers/components/componentObjectsHandler.ts +8 -3
- package/src/helpers/components/orbitComponent.ts +87 -68
- package/src/helpers/components/orbitDspComponent.ts +14 -4
- package/src/helpers/components/setupCacheInvalidation.ts +50 -23
- package/src/helpers/components/setupCacheOnResourceReady.ts +42 -23
- package/src/helpers/components/setupComponentSubscriptions.ts +10 -9
- package/src/helpers/components/setupOnSaveReset.ts +27 -5
- package/src/helpers/datas/checkValueInIntervalRecursive.ts +66 -0
- package/src/helpers/datas/dataBuilder.ts +4 -4
- package/src/helpers/datas/filterGenerator.ts +13 -10
- package/src/helpers/datas/filterObjectByDateAfter.ts +3 -3
- package/src/helpers/datas/filterObjectByDateInterval.ts +44 -0
- package/src/helpers/datas/filterObjectById.ts +7 -6
- package/src/helpers/datas/filterObjectByInterval.ts +6 -110
- package/src/helpers/datas/filterObjectByNamedValue.ts +35 -33
- package/src/helpers/datas/filterObjectByType.ts +3 -3
- package/src/helpers/datas/filterObjectByValue.ts +17 -16
- package/src/helpers/datas/sort.ts +50 -23
- package/src/helpers/index.ts +2 -0
- package/src/helpers/ui/formatDate.ts +14 -1
- package/src/helpers/utils/requestNavigation.ts +5 -2
- package/src/helpers/utils/uniq.ts +1 -1
- package/cypress/component/solid-boilerplate.cy.ts +0 -9
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const getValueFromAnyKey = (obj: any, keys: string[]): any => {
|
|
2
2
|
let value = obj;
|
|
3
|
-
for (
|
|
4
|
-
if (value &&
|
|
5
|
-
value = value[
|
|
3
|
+
for (const key of keys) {
|
|
4
|
+
if (value && key in value) {
|
|
5
|
+
value = value[key];
|
|
6
6
|
} else {
|
|
7
|
-
|
|
7
|
+
return undefined;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
return value;
|
|
@@ -13,28 +13,55 @@ const getValueFromAnyKey = (obj: any, keys: string[]): any => {
|
|
|
13
13
|
type Sort = (arr: any[], k: string | string[], order?: "asc" | "desc") => any[];
|
|
14
14
|
|
|
15
15
|
const sort: Sort = (arr, k, order = "asc") => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
const keys = Array.isArray(k) ? k : [k];
|
|
17
|
+
const shouldReverse = order !== "asc";
|
|
18
|
+
|
|
19
|
+
const result = [...arr];
|
|
20
|
+
|
|
21
|
+
const getComparator = () => {
|
|
22
|
+
const sampleValue = getValueFromAnyKey(result[0], keys);
|
|
23
|
+
|
|
24
|
+
if (typeof sampleValue === "number") {
|
|
25
|
+
return (a: any, b: any) => {
|
|
26
|
+
const aN = getValueFromAnyKey(a, keys);
|
|
27
|
+
const bN = getValueFromAnyKey(b, keys);
|
|
28
|
+
if (aN == null) return bN == null ? 0 : 1;
|
|
29
|
+
if (bN == null) return -1;
|
|
30
|
+
return (aN as number) - (bN as number);
|
|
31
|
+
};
|
|
25
32
|
}
|
|
26
|
-
|
|
27
|
-
if (typeof
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
|
|
34
|
+
if (typeof sampleValue === "string") {
|
|
35
|
+
return (a: any, b: any) => {
|
|
36
|
+
const aN = getValueFromAnyKey(a, keys);
|
|
37
|
+
const bN = getValueFromAnyKey(b, keys);
|
|
38
|
+
if (aN == null) return bN == null ? 0 : 1;
|
|
39
|
+
if (bN == null) return -1;
|
|
40
|
+
return (aN as string).localeCompare(bN as string);
|
|
41
|
+
};
|
|
35
42
|
}
|
|
36
|
-
|
|
43
|
+
|
|
44
|
+
if (sampleValue instanceof Date) {
|
|
45
|
+
return (a: any, b: any) => {
|
|
46
|
+
const aN = getValueFromAnyKey(a, keys);
|
|
47
|
+
const bN = getValueFromAnyKey(b, keys);
|
|
48
|
+
if (aN == null) return bN == null ? 0 : 1;
|
|
49
|
+
if (bN == null) return -1;
|
|
50
|
+
return (aN as Date).getTime() - (bN as Date).getTime();
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
throw new TypeError(`Unsupported data type for key "${k}"`);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const comparator = getComparator();
|
|
58
|
+
|
|
59
|
+
result.sort((a, b) => {
|
|
60
|
+
const comparison = comparator(a, b);
|
|
61
|
+
return shouldReverse ? -comparison : comparison;
|
|
37
62
|
});
|
|
63
|
+
|
|
64
|
+
return result;
|
|
38
65
|
};
|
|
39
66
|
|
|
40
67
|
export default sort;
|
package/src/helpers/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import setupComponentSubscriptions from "@helpers/components/setupComponentSubsc
|
|
|
8
8
|
import setupOnSaveReset from "@helpers/components/setupOnSaveReset";
|
|
9
9
|
import filterGenerator from "@helpers/datas/filterGenerator";
|
|
10
10
|
import filterObjectByDateAfter from "@helpers/datas/filterObjectByDateAfter";
|
|
11
|
+
import filterObjectByDateInterval from "@helpers/datas/filterObjectByDateInterval";
|
|
11
12
|
import filterObjectById from "@helpers/datas/filterObjectById";
|
|
12
13
|
import filterObjectByInterval from "@helpers/datas/filterObjectByInterval";
|
|
13
14
|
import filterObjectByNamedValue from "@helpers/datas/filterObjectByNamedValue";
|
|
@@ -29,6 +30,7 @@ export {
|
|
|
29
30
|
filterObjectByNamedValue,
|
|
30
31
|
filterObjectByValue,
|
|
31
32
|
filterObjectByType,
|
|
33
|
+
filterObjectByDateInterval,
|
|
32
34
|
formatDate,
|
|
33
35
|
ComponentObjectHandler,
|
|
34
36
|
ComponentObjectsHandler,
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
const formatters = new Map<string, Intl.DateTimeFormat>();
|
|
2
|
+
|
|
3
|
+
const getFormatter = (format: Intl.DateTimeFormatOptions): Intl.DateTimeFormat => {
|
|
4
|
+
const key = JSON.stringify(format);
|
|
5
|
+
let formatter = formatters.get(key);
|
|
6
|
+
if (!formatter) {
|
|
7
|
+
formatter = new Intl.DateTimeFormat(undefined, format);
|
|
8
|
+
formatters.set(key, formatter);
|
|
9
|
+
}
|
|
10
|
+
return formatter;
|
|
11
|
+
};
|
|
12
|
+
|
|
1
13
|
const formatDate = (
|
|
2
14
|
originalDate: string | Date | undefined,
|
|
3
15
|
format: Intl.DateTimeFormatOptions = {
|
|
@@ -9,7 +21,8 @@ const formatDate = (
|
|
|
9
21
|
if (!originalDate) return "";
|
|
10
22
|
const date =
|
|
11
23
|
typeof originalDate === "string" ? new Date(originalDate) : originalDate;
|
|
12
|
-
const
|
|
24
|
+
const formatter = getFormatter(format);
|
|
25
|
+
const formattedDate = formatter.format(date);
|
|
13
26
|
if (typeof originalDate === "string" && formattedDate === "Invalid Date")
|
|
14
27
|
return originalDate;
|
|
15
28
|
return formattedDate;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
const requestNavigation = (
|
|
1
|
+
const requestNavigation = (
|
|
2
|
+
route: string,
|
|
3
|
+
resource: string | boolean = false,
|
|
4
|
+
) => {
|
|
2
5
|
window.dispatchEvent(
|
|
3
6
|
new CustomEvent("requestNavigation", {
|
|
4
7
|
detail: {
|
|
5
|
-
route
|
|
8
|
+
route,
|
|
6
9
|
resource: typeof resource === "string" ? { "@id": resource } : resource,
|
|
7
10
|
},
|
|
8
11
|
}),
|