@rxdrag/website-lib-core 0.0.83 → 0.0.85
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdrag/website-lib-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.85",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.ts"
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"@types/react-dom": "^19.1.0",
|
|
25
25
|
"eslint": "^7.32.0",
|
|
26
26
|
"typescript": "^5",
|
|
27
|
-
"@rxdrag/
|
|
27
|
+
"@rxdrag/tsconfig": "0.2.0",
|
|
28
28
|
"@rxdrag/eslint-config-custom": "0.2.12",
|
|
29
|
-
"@rxdrag/
|
|
29
|
+
"@rxdrag/slate-preview": "1.2.61"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@iconify/utils": "^3.0.2",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"lodash-es": "^4.17.21",
|
|
37
37
|
"react": "^19.1.0",
|
|
38
38
|
"react-dom": "^19.1.0",
|
|
39
|
-
"@rxdrag/
|
|
40
|
-
"@rxdrag/
|
|
39
|
+
"@rxdrag/rxcms-models": "0.3.94",
|
|
40
|
+
"@rxdrag/entify-lib": "0.0.23"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"astro": "^4.0.0 || ^5.0.0"
|
package/src/entify/Entify.ts
CHANGED
|
@@ -238,7 +238,7 @@ export class Entify implements IEntify {
|
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
public async getPostCategories() {
|
|
241
|
-
return
|
|
241
|
+
return await queryPostCategories(this.envVariables);
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
public async getPostCategoryBySlug(slug: string) {
|
|
@@ -433,7 +433,7 @@ export class Entify implements IEntify {
|
|
|
433
433
|
}
|
|
434
434
|
|
|
435
435
|
public async getProductCategories() {
|
|
436
|
-
return
|
|
436
|
+
return await queryProductCategories(this.envVariables);
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
public async getProductCategoryBySlug(slug: string) {
|
package/src/entify/lib/index.ts
CHANGED
|
@@ -27,4 +27,5 @@ export * from "./queryWebSiteSettings";
|
|
|
27
27
|
export * from "./upsertEntity";
|
|
28
28
|
export * from "./fulltextSearch";
|
|
29
29
|
export * from "./sendEmail";
|
|
30
|
-
export * from "./createUploadCredentials";
|
|
30
|
+
export * from "./createUploadCredentials";
|
|
31
|
+
export * from "./listToTree";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function listToTree<
|
|
2
|
+
T extends { id?: string | null; parent?: { id?: string | null } | null }
|
|
3
|
+
>(items: T[]): (T & { children: T[] })[] {
|
|
4
|
+
const nodeMap = new Map<string, T & { children: T[] }>();
|
|
5
|
+
|
|
6
|
+
items.forEach((item) => {
|
|
7
|
+
if (item.id) {
|
|
8
|
+
nodeMap.set(item.id, { ...item, children: [] });
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const tree: (T & { children: T[] })[] = [];
|
|
13
|
+
|
|
14
|
+
nodeMap.forEach((node) => {
|
|
15
|
+
if (node.parent?.id && nodeMap.has(node.parent.id)) {
|
|
16
|
+
nodeMap.get(node.parent.id)!.children.push(node);
|
|
17
|
+
} else {
|
|
18
|
+
tree.push(node);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return tree;
|
|
23
|
+
}
|
|
@@ -14,6 +14,7 @@ import { queryEntityList } from "./queryEntityList";
|
|
|
14
14
|
import { ListResult } from "@rxdrag/entify-lib";
|
|
15
15
|
import { EnvVariables } from "../types";
|
|
16
16
|
import { TPostCategory } from "../view-model";
|
|
17
|
+
import { listToTree } from "./listToTree";
|
|
17
18
|
|
|
18
19
|
export async function queryPostCategories(envVariables: EnvVariables) {
|
|
19
20
|
const result = await queryEntityList<
|
|
@@ -39,17 +40,28 @@ export async function queryPostCategories(envVariables: EnvVariables) {
|
|
|
39
40
|
},
|
|
40
41
|
orderBy: [{ [PostCategoryFields.seqValue]: "asc" }],
|
|
41
42
|
}
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
)
|
|
44
|
+
.parent()
|
|
45
|
+
.posts(
|
|
46
|
+
new PostQueryOptions(
|
|
47
|
+
[PostFields.id, PostFields.title, PostFields.slug],
|
|
48
|
+
{
|
|
49
|
+
where: {
|
|
50
|
+
[PostFields.status]: {
|
|
51
|
+
_eq: PublishableStatus.published,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
orderBy: [{ [ProductFields.seqValue]: "asc" }],
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
),
|
|
52
58
|
envVariables
|
|
53
59
|
);
|
|
54
|
-
|
|
60
|
+
const typedResult = result as ListResult<TPostCategory> | undefined;
|
|
61
|
+
|
|
62
|
+
if (!typedResult) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return listToTree(typedResult.items || []);
|
|
55
67
|
}
|
|
@@ -3,6 +3,7 @@ import { queryEntityList } from "./queryEntityList";
|
|
|
3
3
|
import { ListResult } from "@rxdrag/entify-lib";
|
|
4
4
|
import { EnvVariables } from "../types";
|
|
5
5
|
import { TProductCategory } from "../view-model";
|
|
6
|
+
import { listToTree } from "./listToTree";
|
|
6
7
|
|
|
7
8
|
export async function queryProductCategories(envVariables: EnvVariables) {
|
|
8
9
|
|
|
@@ -27,6 +28,7 @@ export async function queryProductCategories(envVariables: EnvVariables) {
|
|
|
27
28
|
]
|
|
28
29
|
}
|
|
29
30
|
)
|
|
31
|
+
.parent()
|
|
30
32
|
.products(
|
|
31
33
|
new ProductQueryOptions(
|
|
32
34
|
[ProductFields.id, ProductFields.title, ProductFields.slug],
|
|
@@ -47,5 +49,11 @@ export async function queryProductCategories(envVariables: EnvVariables) {
|
|
|
47
49
|
),
|
|
48
50
|
envVariables
|
|
49
51
|
);
|
|
50
|
-
|
|
52
|
+
const typedResult = result as ListResult<TProductCategory> | undefined;
|
|
53
|
+
|
|
54
|
+
if (!typedResult) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return listToTree(typedResult.items || []);
|
|
51
59
|
}
|