@headless-adminapp/app 0.0.17-alpha.40 → 0.0.17-alpha.42
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/board/BoardColumnDataResolver.d.ts +1 -0
- package/board/BoardColumnDataResolver.js +64 -0
- package/board/BoardColumnProvider.d.ts +7 -0
- package/board/BoardColumnProvider.js +36 -0
- package/board/context.d.ts +19 -0
- package/board/context.js +6 -0
- package/board/hooks/index.d.ts +6 -0
- package/board/hooks/index.js +15 -0
- package/board/hooks/useBoardColumnConfig.d.ts +2 -0
- package/board/hooks/useBoardColumnConfig.js +8 -0
- package/board/hooks/useBoardColumnData.d.ts +1 -0
- package/board/hooks/useBoardColumnData.js +9 -0
- package/board/hooks/useBoardColumnDataState.d.ts +5 -0
- package/board/hooks/useBoardColumnDataState.js +9 -0
- package/board/hooks/useBoardConfig.d.ts +3 -0
- package/board/hooks/useBoardConfig.js +8 -0
- package/board/hooks/useBoardSchema.d.ts +2 -0
- package/board/hooks/useBoardSchema.js +7 -0
- package/board/hooks/useSearchText.d.ts +1 -0
- package/board/hooks/useSearchText.js +14 -0
- package/board/types.d.ts +47 -0
- package/board/types.js +2 -0
- package/board/utils.d.ts +3 -0
- package/board/utils.js +6 -0
- package/components/ScrollbarWithMoreDataRequest/index.d.ts +9 -0
- package/components/ScrollbarWithMoreDataRequest/index.js +33 -0
- package/datagrid/DataGridProvider/DataResolver.js +18 -102
- package/package.json +2 -2
- package/transport/hooks/useRetriveRecords.d.ts +32 -0
- package/transport/hooks/useRetriveRecords.js +120 -0
- package/utils/color.d.ts +1 -0
- package/utils/color.js +14 -0
- package/utils/getAttributeFormattedValue.d.ts +1 -0
- package/utils/getAttributeFormattedValue.js +21 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function DataResolver(): null;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataResolver = DataResolver;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const hooks_1 = require("../hooks");
|
|
6
|
+
const mutable_1 = require("../mutable");
|
|
7
|
+
const useRetriveRecords_1 = require("../transport/hooks/useRetriveRecords");
|
|
8
|
+
const context_1 = require("./context");
|
|
9
|
+
const useBoardColumnConfig_1 = require("./hooks/useBoardColumnConfig");
|
|
10
|
+
const useBoardConfig_1 = require("./hooks/useBoardConfig");
|
|
11
|
+
const useSearchText_1 = require("./hooks/useSearchText");
|
|
12
|
+
const MAX_RECORDS = 10000;
|
|
13
|
+
function DataResolver() {
|
|
14
|
+
const { schema, sorting, projection: { columns, expand }, } = (0, useBoardConfig_1.useBoardConfig)();
|
|
15
|
+
const [searchText] = (0, useSearchText_1.useSearchText)();
|
|
16
|
+
const { filter, maxRecords = MAX_RECORDS } = (0, useBoardColumnConfig_1.useBoardColumnConfig)();
|
|
17
|
+
const setState = (0, mutable_1.useContextSetValue)(context_1.BoardColumnContext);
|
|
18
|
+
const [search] = (0, hooks_1.useDebouncedValue)(searchText, 500);
|
|
19
|
+
const queryKey = (0, useRetriveRecords_1.useRetrieveRecordsKey)({
|
|
20
|
+
columns,
|
|
21
|
+
expand,
|
|
22
|
+
filter,
|
|
23
|
+
maxRecords,
|
|
24
|
+
schema,
|
|
25
|
+
search,
|
|
26
|
+
sorting,
|
|
27
|
+
});
|
|
28
|
+
(0, useRetriveRecords_1.useClearDataExceptFirstPage)(queryKey);
|
|
29
|
+
const { fetchNextPage, data, hasNextPage, isFetching, isFetchingNextPage } = (0, useRetriveRecords_1.useRetriveRecords)(queryKey, {
|
|
30
|
+
columns,
|
|
31
|
+
expand,
|
|
32
|
+
filter,
|
|
33
|
+
maxRecords,
|
|
34
|
+
schema,
|
|
35
|
+
search,
|
|
36
|
+
sorting,
|
|
37
|
+
});
|
|
38
|
+
(0, react_1.useEffect)(() => {
|
|
39
|
+
setState({
|
|
40
|
+
fetchNextPage: fetchNextPage,
|
|
41
|
+
});
|
|
42
|
+
}, [fetchNextPage, setState]);
|
|
43
|
+
(0, react_1.useEffect)(() => {
|
|
44
|
+
if (!data) {
|
|
45
|
+
setState({
|
|
46
|
+
data: null,
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
setState({
|
|
51
|
+
data,
|
|
52
|
+
});
|
|
53
|
+
}, [data, setState, schema.idAttribute]);
|
|
54
|
+
(0, react_1.useEffect)(() => {
|
|
55
|
+
setState({
|
|
56
|
+
dataState: {
|
|
57
|
+
isFetching,
|
|
58
|
+
hasNextPage,
|
|
59
|
+
isFetchingNextPage,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}, [hasNextPage, isFetching, isFetchingNextPage, setState]);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { BoardColumnConfig } from './types';
|
|
3
|
+
export declare function invertValueMapping(value: Record<string, string[]>): Record<string, string[]>;
|
|
4
|
+
export interface BoardColumnProviderProps {
|
|
5
|
+
config: BoardColumnConfig;
|
|
6
|
+
}
|
|
7
|
+
export declare function BoardColumnProvider(props: PropsWithChildren<BoardColumnProviderProps>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.invertValueMapping = invertValueMapping;
|
|
4
|
+
exports.BoardColumnProvider = BoardColumnProvider;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const mutable_1 = require("../mutable");
|
|
7
|
+
const BoardColumnDataResolver_1 = require("./BoardColumnDataResolver");
|
|
8
|
+
const context_1 = require("./context");
|
|
9
|
+
const useBoardConfig_1 = require("./hooks/useBoardConfig");
|
|
10
|
+
function invertValueMapping(value) {
|
|
11
|
+
return Object.keys(value).reduce((acc, key) => {
|
|
12
|
+
const toKeys = value[key];
|
|
13
|
+
toKeys.forEach((toKey) => {
|
|
14
|
+
acc[toKey] = [...(acc[toKey] || []), key];
|
|
15
|
+
});
|
|
16
|
+
return acc;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
function BoardColumnProvider(props) {
|
|
20
|
+
const { schema } = (0, useBoardConfig_1.useBoardConfig)();
|
|
21
|
+
const contextValue = (0, mutable_1.useCreateContextStore)({
|
|
22
|
+
config: props.config,
|
|
23
|
+
data: {
|
|
24
|
+
logicalName: schema.logicalName,
|
|
25
|
+
records: [],
|
|
26
|
+
count: 0,
|
|
27
|
+
},
|
|
28
|
+
dataState: {
|
|
29
|
+
hasNextPage: false,
|
|
30
|
+
isFetching: false,
|
|
31
|
+
isFetchingNextPage: false,
|
|
32
|
+
},
|
|
33
|
+
fetchNextPage: () => { },
|
|
34
|
+
});
|
|
35
|
+
return ((0, jsx_runtime_1.jsxs)(context_1.BoardColumnContext.Provider, { value: contextValue, children: [(0, jsx_runtime_1.jsx)(BoardColumnDataResolver_1.DataResolver, {}), props.children] }));
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { InferredSchemaType, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
2
|
+
import { RetriveRecordsResult } from '@headless-adminapp/core/transport';
|
|
3
|
+
import { BoardColumnConfig, BoardConfig } from './types';
|
|
4
|
+
export interface BoardContextState<S extends SchemaAttributes = SchemaAttributes> {
|
|
5
|
+
config: BoardConfig<S>;
|
|
6
|
+
searchText: string;
|
|
7
|
+
}
|
|
8
|
+
export interface BoardColumnContextState<S extends SchemaAttributes = SchemaAttributes> {
|
|
9
|
+
config: BoardColumnConfig;
|
|
10
|
+
data: RetriveRecordsResult<InferredSchemaType<S>> | null;
|
|
11
|
+
dataState: {
|
|
12
|
+
isFetching: boolean;
|
|
13
|
+
hasNextPage: boolean;
|
|
14
|
+
isFetchingNextPage: boolean;
|
|
15
|
+
};
|
|
16
|
+
fetchNextPage: () => void;
|
|
17
|
+
}
|
|
18
|
+
export declare const BoardContext: import("react").Context<import("../mutable").ContextValue<BoardContextState<SchemaAttributes>>>;
|
|
19
|
+
export declare const BoardColumnContext: import("react").Context<import("../mutable").ContextValue<BoardColumnContextState<SchemaAttributes>>>;
|
package/board/context.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BoardColumnContext = exports.BoardContext = void 0;
|
|
4
|
+
const mutable_1 = require("../mutable");
|
|
5
|
+
exports.BoardContext = (0, mutable_1.createContext)();
|
|
6
|
+
exports.BoardColumnContext = (0, mutable_1.createContext)();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { useBoardColumnConfig } from './useBoardColumnConfig';
|
|
2
|
+
export { useBoardColumnData } from './useBoardColumnData';
|
|
3
|
+
export { useBoardColumnDataState } from './useBoardColumnDataState';
|
|
4
|
+
export { useBoardConfig } from './useBoardConfig';
|
|
5
|
+
export { useBoardSchema } from './useBoardSchema';
|
|
6
|
+
export { useSearchText } from './useSearchText';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSearchText = exports.useBoardSchema = exports.useBoardConfig = exports.useBoardColumnDataState = exports.useBoardColumnData = exports.useBoardColumnConfig = void 0;
|
|
4
|
+
var useBoardColumnConfig_1 = require("./useBoardColumnConfig");
|
|
5
|
+
Object.defineProperty(exports, "useBoardColumnConfig", { enumerable: true, get: function () { return useBoardColumnConfig_1.useBoardColumnConfig; } });
|
|
6
|
+
var useBoardColumnData_1 = require("./useBoardColumnData");
|
|
7
|
+
Object.defineProperty(exports, "useBoardColumnData", { enumerable: true, get: function () { return useBoardColumnData_1.useBoardColumnData; } });
|
|
8
|
+
var useBoardColumnDataState_1 = require("./useBoardColumnDataState");
|
|
9
|
+
Object.defineProperty(exports, "useBoardColumnDataState", { enumerable: true, get: function () { return useBoardColumnDataState_1.useBoardColumnDataState; } });
|
|
10
|
+
var useBoardConfig_1 = require("./useBoardConfig");
|
|
11
|
+
Object.defineProperty(exports, "useBoardConfig", { enumerable: true, get: function () { return useBoardConfig_1.useBoardConfig; } });
|
|
12
|
+
var useBoardSchema_1 = require("./useBoardSchema");
|
|
13
|
+
Object.defineProperty(exports, "useBoardSchema", { enumerable: true, get: function () { return useBoardSchema_1.useBoardSchema; } });
|
|
14
|
+
var useSearchText_1 = require("./useSearchText");
|
|
15
|
+
Object.defineProperty(exports, "useSearchText", { enumerable: true, get: function () { return useSearchText_1.useSearchText; } });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useBoardColumnConfig = useBoardColumnConfig;
|
|
4
|
+
const context_1 = require("@headless-adminapp/app/mutable/context");
|
|
5
|
+
const context_2 = require("../context");
|
|
6
|
+
function useBoardColumnConfig() {
|
|
7
|
+
return (0, context_1.useContextSelector)(context_2.BoardColumnContext, (context) => context.config);
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useBoardColumnData(): import("@headless-adminapp/core/transport").RetriveRecordsResult<import("@headless-adminapp/core/schema").InferredSchemaType<import("@headless-adminapp/core/schema").SchemaAttributes>> | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useBoardColumnData = useBoardColumnData;
|
|
4
|
+
const context_1 = require("@headless-adminapp/app/mutable/context");
|
|
5
|
+
const context_2 = require("../context");
|
|
6
|
+
function useBoardColumnData() {
|
|
7
|
+
const data = (0, context_1.useContextSelector)(context_2.BoardColumnContext, (state) => state.data);
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useBoardColumnDataState = useBoardColumnDataState;
|
|
4
|
+
const context_1 = require("@headless-adminapp/app/mutable/context");
|
|
5
|
+
const context_2 = require("../context");
|
|
6
|
+
function useBoardColumnDataState() {
|
|
7
|
+
const data = (0, context_1.useContextSelector)(context_2.BoardColumnContext, (state) => state.dataState);
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useBoardConfig = useBoardConfig;
|
|
4
|
+
const context_1 = require("@headless-adminapp/app/mutable/context");
|
|
5
|
+
const context_2 = require("../context");
|
|
6
|
+
function useBoardConfig() {
|
|
7
|
+
return (0, context_1.useContextSelector)(context_2.BoardContext, (context) => context.config);
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useSearchText(): readonly [string, (value: string) => void];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSearchText = useSearchText;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
const context_2 = require("@headless-adminapp/app/mutable/context");
|
|
7
|
+
function useSearchText() {
|
|
8
|
+
const searchText = (0, context_2.useContextSelector)(context_1.BoardContext, (context) => context.searchText);
|
|
9
|
+
const setValue = (0, context_2.useContextSetValue)(context_1.BoardContext);
|
|
10
|
+
const setSearchText = (0, react_1.useCallback)((value) => {
|
|
11
|
+
setValue({ searchText: value });
|
|
12
|
+
}, [setValue]);
|
|
13
|
+
return [searchText, setSearchText];
|
|
14
|
+
}
|
package/board/types.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CommandContextBase } from '@headless-adminapp/core/experience/command';
|
|
2
|
+
import { SortingState, View } from '@headless-adminapp/core/experience/view';
|
|
3
|
+
import { Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
4
|
+
import { Filter } from '@headless-adminapp/core/transport';
|
|
5
|
+
import { FC } from 'react';
|
|
6
|
+
import { UtilityContextState } from '../command';
|
|
7
|
+
export interface ItemUpdateContext extends CommandContextBase {
|
|
8
|
+
primaryControl: {
|
|
9
|
+
logicalName: string;
|
|
10
|
+
id: string;
|
|
11
|
+
schema: Schema;
|
|
12
|
+
};
|
|
13
|
+
utility: UtilityContextState;
|
|
14
|
+
}
|
|
15
|
+
export interface Column {
|
|
16
|
+
view: View<SchemaAttributes>;
|
|
17
|
+
accept: string[];
|
|
18
|
+
update?: (context: ItemUpdateContext) => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export type BoardColumnCardPreviewFC = FC<{
|
|
21
|
+
record: any;
|
|
22
|
+
}>;
|
|
23
|
+
export interface DragItem {
|
|
24
|
+
id: string;
|
|
25
|
+
columnId: string;
|
|
26
|
+
record: any;
|
|
27
|
+
}
|
|
28
|
+
export interface BoardColumnConfig {
|
|
29
|
+
columnId: string;
|
|
30
|
+
title: string;
|
|
31
|
+
maxRecords?: number;
|
|
32
|
+
filter: Filter;
|
|
33
|
+
acceptSourceIds: string[];
|
|
34
|
+
updateFn: (context: ItemUpdateContext) => Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export interface BoardConfig<S extends SchemaAttributes = SchemaAttributes> {
|
|
37
|
+
title: string;
|
|
38
|
+
description: string;
|
|
39
|
+
schema: Schema<S>;
|
|
40
|
+
sorting: SortingState<S>;
|
|
41
|
+
projection: {
|
|
42
|
+
columns: Array<keyof S>;
|
|
43
|
+
expand?: Partial<Record<keyof S, string[]>>;
|
|
44
|
+
};
|
|
45
|
+
columnConfigs: BoardColumnConfig[];
|
|
46
|
+
PreviewComponent: BoardColumnCardPreviewFC;
|
|
47
|
+
}
|
package/board/types.js
ADDED
package/board/utils.d.ts
ADDED
package/board/utils.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
interface ScrollbarWithMoreDataRequest {
|
|
3
|
+
data: any;
|
|
4
|
+
hasMore: boolean;
|
|
5
|
+
onRequestMore: () => void;
|
|
6
|
+
rtl?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const ScrollbarWithMoreDataRequest: FC<PropsWithChildren<ScrollbarWithMoreDataRequest>>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScrollbarWithMoreDataRequest = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const ScrollView_1 = require("../ScrollView");
|
|
7
|
+
function getReaminingSpace(div) {
|
|
8
|
+
return div.scrollHeight - div.scrollTop - div.clientHeight;
|
|
9
|
+
}
|
|
10
|
+
const ScrollbarWithMoreDataRequest = ({ data, onRequestMore, hasMore, children, rtl }) => {
|
|
11
|
+
const divRef = (0, react_1.useRef)(null);
|
|
12
|
+
const onRequestMoreRef = (0, react_1.useRef)(onRequestMore);
|
|
13
|
+
onRequestMoreRef.current = onRequestMore;
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
var _a;
|
|
16
|
+
const div = (_a = divRef.current) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
17
|
+
if (!div) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const remainingSpace = getReaminingSpace(div);
|
|
21
|
+
if (remainingSpace <= 0 && hasMore) {
|
|
22
|
+
onRequestMoreRef.current();
|
|
23
|
+
}
|
|
24
|
+
}, [data, hasMore]);
|
|
25
|
+
return ((0, jsx_runtime_1.jsx)(ScrollView_1.ScrollView, { autoHide: true, rtl: rtl, onScroll: (e) => {
|
|
26
|
+
const div = e.target;
|
|
27
|
+
const remainingSpace = getReaminingSpace(div);
|
|
28
|
+
if (remainingSpace <= 0 && hasMore) {
|
|
29
|
+
onRequestMoreRef.current();
|
|
30
|
+
}
|
|
31
|
+
}, children: (0, jsx_runtime_1.jsx)("div", { ref: divRef, children: children }) }));
|
|
32
|
+
};
|
|
33
|
+
exports.ScrollbarWithMoreDataRequest = ScrollbarWithMoreDataRequest;
|
|
@@ -1,31 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.DataResolver = DataResolver;
|
|
13
|
-
const
|
|
4
|
+
const useRetriveRecords_1 = require("@headless-adminapp/app/transport/hooks/useRetriveRecords");
|
|
14
5
|
const react_1 = require("react");
|
|
15
6
|
const useDebouncedValue_1 = require("../../hooks/useDebouncedValue");
|
|
16
7
|
const useMetadata_1 = require("../../metadata/hooks/useMetadata");
|
|
17
8
|
const context_1 = require("../../mutable/context");
|
|
18
|
-
const transport_1 = require("../../transport");
|
|
19
9
|
const context_2 = require("../context");
|
|
20
10
|
const hooks_1 = require("../hooks");
|
|
21
11
|
const utils_1 = require("./utils");
|
|
22
|
-
const ROWS_PER_PAGE = 100;
|
|
23
12
|
const MAX_RECORDS = 10000;
|
|
24
13
|
function DataResolver() {
|
|
25
14
|
var _a;
|
|
26
15
|
const schema = (0, hooks_1.useDataGridSchema)();
|
|
27
16
|
const view = (0, hooks_1.useSelectedView)();
|
|
28
|
-
const dataService = (0, transport_1.useDataService)();
|
|
29
17
|
const [sorting] = (0, hooks_1.useGridSorting)();
|
|
30
18
|
const [searchText] = (0, hooks_1.useSearchText)();
|
|
31
19
|
const extraFilter = (0, hooks_1.useGridExtraFilter)();
|
|
@@ -43,93 +31,27 @@ function DataResolver() {
|
|
|
43
31
|
schema.primaryAttribute,
|
|
44
32
|
])), [gridColumns, schema.primaryAttribute]);
|
|
45
33
|
const expand = (0, react_1.useMemo)(() => (0, utils_1.collectExpandedKeys)(gridColumns), [gridColumns]);
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
search,
|
|
51
|
-
view.experience.filter,
|
|
52
|
-
extraFilter,
|
|
53
|
-
sorting,
|
|
54
|
-
columnFilters,
|
|
34
|
+
const filter = (0, react_1.useMemo)(() => {
|
|
35
|
+
return (0, utils_1.mergeConditions)(schema, view.experience.filter, extraFilter, columnFilters, schemaStore);
|
|
36
|
+
}, [columnFilters, extraFilter, schema, schemaStore, view.experience.filter]);
|
|
37
|
+
const queryKey = (0, useRetriveRecords_1.useRetrieveRecordsKey)({
|
|
55
38
|
columns,
|
|
56
39
|
expand,
|
|
40
|
+
filter,
|
|
57
41
|
maxRecords,
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
schema,
|
|
43
|
+
search,
|
|
44
|
+
sorting,
|
|
45
|
+
});
|
|
46
|
+
(0, useRetriveRecords_1.useClearDataExceptFirstPage)(queryKey);
|
|
47
|
+
const { fetchNextPage, data, hasNextPage, isFetching, isFetchingNextPage } = (0, useRetriveRecords_1.useRetriveRecords)(queryKey, {
|
|
60
48
|
columns,
|
|
61
49
|
expand,
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
filter,
|
|
51
|
+
maxRecords,
|
|
52
|
+
schema,
|
|
64
53
|
search,
|
|
65
54
|
sorting,
|
|
66
|
-
view.experience.filter,
|
|
67
|
-
maxRecords,
|
|
68
|
-
]);
|
|
69
|
-
const queryClient = (0, react_query_1.useQueryClient)();
|
|
70
|
-
(0, react_1.useEffect)(() => {
|
|
71
|
-
return () => {
|
|
72
|
-
// Clear all pages except the first one when the component is unmounted
|
|
73
|
-
queryClient.setQueryData(queryKey, (oldData) => {
|
|
74
|
-
if (!oldData) {
|
|
75
|
-
return oldData;
|
|
76
|
-
}
|
|
77
|
-
if (!oldData.pageParams.length || !oldData.pages.length) {
|
|
78
|
-
return oldData;
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
pageParams: [oldData.pageParams[0]],
|
|
82
|
-
pages: [oldData.pages[0]],
|
|
83
|
-
};
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
}, [queryClient, queryKey]);
|
|
87
|
-
const { data, isFetching, hasNextPage, fetchNextPage, isFetchingNextPage } = (0, react_query_1.useInfiniteQuery)({
|
|
88
|
-
queryKey: queryKey,
|
|
89
|
-
queryFn: (queryContext) => __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
var _a;
|
|
91
|
-
const params = (_a = queryContext.pageParam) !== null && _a !== void 0 ? _a : {
|
|
92
|
-
pageIndex: 0,
|
|
93
|
-
};
|
|
94
|
-
const skip = params.pageIndex * ROWS_PER_PAGE;
|
|
95
|
-
const limit = Math.min(ROWS_PER_PAGE, Math.max(0, maxRecords - skip));
|
|
96
|
-
if (limit <= 0) {
|
|
97
|
-
return {
|
|
98
|
-
params: params,
|
|
99
|
-
data: {
|
|
100
|
-
logicalName: schema.logicalName,
|
|
101
|
-
count: 0,
|
|
102
|
-
records: [],
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
const result = yield dataService.retriveRecords({
|
|
107
|
-
logicalName: schema.logicalName,
|
|
108
|
-
search,
|
|
109
|
-
columns: columns,
|
|
110
|
-
expand,
|
|
111
|
-
filter: (0, utils_1.mergeConditions)(schema, view.experience.filter, extraFilter, columnFilters, schemaStore),
|
|
112
|
-
skip,
|
|
113
|
-
limit,
|
|
114
|
-
sort: sorting,
|
|
115
|
-
});
|
|
116
|
-
return {
|
|
117
|
-
params: params,
|
|
118
|
-
data: result,
|
|
119
|
-
};
|
|
120
|
-
}),
|
|
121
|
-
getNextPageParam: (lastPage) => {
|
|
122
|
-
if (lastPage.data.count <
|
|
123
|
-
ROWS_PER_PAGE * (lastPage.params.pageIndex + 1)) {
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
pageIndex: lastPage.params.pageIndex + 1,
|
|
128
|
-
};
|
|
129
|
-
},
|
|
130
|
-
initialPageParam: {
|
|
131
|
-
pageIndex: 0,
|
|
132
|
-
},
|
|
133
55
|
});
|
|
134
56
|
(0, react_1.useEffect)(() => {
|
|
135
57
|
setState({
|
|
@@ -137,21 +59,15 @@ function DataResolver() {
|
|
|
137
59
|
});
|
|
138
60
|
}, [fetchNextPage, setState]);
|
|
139
61
|
(0, react_1.useEffect)(() => {
|
|
140
|
-
|
|
141
|
-
if (!(data === null || data === void 0 ? void 0 : data.pages.length)) {
|
|
62
|
+
if (!data) {
|
|
142
63
|
setState({
|
|
143
64
|
data: null,
|
|
144
65
|
});
|
|
145
66
|
return;
|
|
146
67
|
}
|
|
147
|
-
const
|
|
148
|
-
logicalName: (_a = data === null || data === void 0 ? void 0 : data.pages) === null || _a === void 0 ? void 0 : _a[0].data.logicalName,
|
|
149
|
-
count: (_c = (_b = data === null || data === void 0 ? void 0 : data.pages) === null || _b === void 0 ? void 0 : _b[0].data.count) !== null && _c !== void 0 ? _c : 0,
|
|
150
|
-
records: (_d = data === null || data === void 0 ? void 0 : data.pages.map((x) => x.data.records).flat()) !== null && _d !== void 0 ? _d : [],
|
|
151
|
-
};
|
|
152
|
-
const selectedIds = selectedIdsRef.current.filter((x) => finalData.records.some((y) => y[schema.idAttribute] === x));
|
|
68
|
+
const selectedIds = selectedIdsRef.current.filter((x) => data.records.some((y) => y[schema.idAttribute] === x));
|
|
153
69
|
setState({
|
|
154
|
-
data
|
|
70
|
+
data,
|
|
155
71
|
selectedIds,
|
|
156
72
|
});
|
|
157
73
|
}, [data, setState, schema.idAttribute]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/app",
|
|
3
|
-
"version": "0.0.17-alpha.
|
|
3
|
+
"version": "0.0.17-alpha.42",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"react-hook-form": "7.52.2",
|
|
40
40
|
"yup": "^1.4.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "c5b091139a9d3cf973f69f848b5df0a8ee8c63e7"
|
|
43
43
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SortingState } from '@headless-adminapp/core/experience/view';
|
|
2
|
+
import { InferredSchemaType, Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
|
+
import { Filter } from '@headless-adminapp/core/transport';
|
|
4
|
+
import { QueryKey } from '@tanstack/react-query';
|
|
5
|
+
interface UseRetriveRecordProps<S extends SchemaAttributes = SchemaAttributes> {
|
|
6
|
+
schema: Schema<S>;
|
|
7
|
+
search: string;
|
|
8
|
+
filter: Filter | null;
|
|
9
|
+
sorting: SortingState<S>;
|
|
10
|
+
columns: string[];
|
|
11
|
+
expand?: Partial<Record<string, string[]>>;
|
|
12
|
+
maxRecords: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function useRetrieveRecordsKey<S extends SchemaAttributes = SchemaAttributes>({ schema, search, filter, sorting, columns, expand, maxRecords, }: UseRetriveRecordProps<S>): (string | number | Filter | SortingState<S> | string[] | Partial<Record<string, string[]>> | null | undefined)[];
|
|
15
|
+
export declare function useClearDataExceptFirstPage(queryKey: QueryKey): void;
|
|
16
|
+
export declare function useRetriveRecords<S extends SchemaAttributes = SchemaAttributes>(queryKey: QueryKey, { columns, expand, filter, maxRecords, schema, search, sorting, }: UseRetriveRecordProps): {
|
|
17
|
+
data: {
|
|
18
|
+
logicalName: string;
|
|
19
|
+
count: number;
|
|
20
|
+
records: import("@headless-adminapp/core/transport").Data<InferredSchemaType<S>>[];
|
|
21
|
+
} | null;
|
|
22
|
+
isFetching: boolean;
|
|
23
|
+
hasNextPage: boolean;
|
|
24
|
+
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<import("@tanstack/react-query").InfiniteData<{
|
|
25
|
+
params: {
|
|
26
|
+
pageIndex: number;
|
|
27
|
+
};
|
|
28
|
+
data: import("@headless-adminapp/core/transport").RetriveRecordsResult<InferredSchemaType<S>>;
|
|
29
|
+
}, unknown>, Error>>;
|
|
30
|
+
isFetchingNextPage: boolean;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.useRetrieveRecordsKey = useRetrieveRecordsKey;
|
|
13
|
+
exports.useClearDataExceptFirstPage = useClearDataExceptFirstPage;
|
|
14
|
+
exports.useRetriveRecords = useRetriveRecords;
|
|
15
|
+
const transport_1 = require("@headless-adminapp/app/transport");
|
|
16
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
17
|
+
const react_1 = require("react");
|
|
18
|
+
const ROWS_PER_PAGE = 100;
|
|
19
|
+
function useRetrieveRecordsKey({ schema, search, filter, sorting, columns, expand, maxRecords, }) {
|
|
20
|
+
const queryKey = (0, react_1.useMemo)(() => [
|
|
21
|
+
'data',
|
|
22
|
+
'retriveRecords',
|
|
23
|
+
schema.logicalName,
|
|
24
|
+
search,
|
|
25
|
+
filter,
|
|
26
|
+
sorting,
|
|
27
|
+
columns,
|
|
28
|
+
expand,
|
|
29
|
+
maxRecords,
|
|
30
|
+
], [schema.logicalName, search, filter, sorting, columns, expand, maxRecords]);
|
|
31
|
+
return queryKey;
|
|
32
|
+
}
|
|
33
|
+
function useClearDataExceptFirstPage(queryKey) {
|
|
34
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
35
|
+
(0, react_1.useEffect)(() => {
|
|
36
|
+
return () => {
|
|
37
|
+
// Clear all pages except the first one when the component is unmounted
|
|
38
|
+
queryClient.setQueryData(queryKey, (oldData) => {
|
|
39
|
+
if (!oldData) {
|
|
40
|
+
return oldData;
|
|
41
|
+
}
|
|
42
|
+
if (!oldData.pageParams.length || !oldData.pages.length) {
|
|
43
|
+
return oldData;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
pageParams: [oldData.pageParams[0]],
|
|
47
|
+
pages: [oldData.pages[0]],
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
}, [queryClient, queryKey]);
|
|
52
|
+
}
|
|
53
|
+
function useRetriveRecords(queryKey, { columns, expand, filter, maxRecords, schema, search, sorting, }) {
|
|
54
|
+
const dataService = (0, transport_1.useDataService)();
|
|
55
|
+
const { data, isFetching, hasNextPage, fetchNextPage, isFetchingNextPage } = (0, react_query_1.useInfiniteQuery)({
|
|
56
|
+
queryKey: queryKey,
|
|
57
|
+
queryFn: (queryContext) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
var _a;
|
|
59
|
+
const params = (_a = queryContext.pageParam) !== null && _a !== void 0 ? _a : {
|
|
60
|
+
pageIndex: 0,
|
|
61
|
+
};
|
|
62
|
+
const skip = params.pageIndex * ROWS_PER_PAGE;
|
|
63
|
+
const limit = Math.min(ROWS_PER_PAGE, Math.max(0, maxRecords - skip));
|
|
64
|
+
if (limit <= 0) {
|
|
65
|
+
return {
|
|
66
|
+
params: params,
|
|
67
|
+
data: {
|
|
68
|
+
logicalName: schema.logicalName,
|
|
69
|
+
count: 0,
|
|
70
|
+
records: [],
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const result = yield dataService.retriveRecords({
|
|
75
|
+
logicalName: schema.logicalName,
|
|
76
|
+
search,
|
|
77
|
+
columns: columns,
|
|
78
|
+
expand,
|
|
79
|
+
filter,
|
|
80
|
+
skip,
|
|
81
|
+
limit,
|
|
82
|
+
sort: sorting,
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
params: params,
|
|
86
|
+
data: result,
|
|
87
|
+
};
|
|
88
|
+
}),
|
|
89
|
+
getNextPageParam: (lastPage) => {
|
|
90
|
+
if (lastPage.data.count <
|
|
91
|
+
ROWS_PER_PAGE * (lastPage.params.pageIndex + 1)) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
pageIndex: lastPage.params.pageIndex + 1,
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
initialPageParam: {
|
|
99
|
+
pageIndex: 0,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
const finalData = (0, react_1.useMemo)(() => {
|
|
103
|
+
var _a, _b, _c, _d;
|
|
104
|
+
if (!(data === null || data === void 0 ? void 0 : data.pages.length)) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
logicalName: (_a = data === null || data === void 0 ? void 0 : data.pages) === null || _a === void 0 ? void 0 : _a[0].data.logicalName,
|
|
109
|
+
count: (_c = (_b = data === null || data === void 0 ? void 0 : data.pages) === null || _b === void 0 ? void 0 : _b[0].data.count) !== null && _c !== void 0 ? _c : 0,
|
|
110
|
+
records: (_d = data === null || data === void 0 ? void 0 : data.pages.map((x) => x.data.records).flat()) !== null && _d !== void 0 ? _d : [],
|
|
111
|
+
};
|
|
112
|
+
}, [data]);
|
|
113
|
+
return {
|
|
114
|
+
data: finalData,
|
|
115
|
+
isFetching,
|
|
116
|
+
hasNextPage,
|
|
117
|
+
fetchNextPage,
|
|
118
|
+
isFetchingNextPage,
|
|
119
|
+
};
|
|
120
|
+
}
|
package/utils/color.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isColorDark(color: string): boolean;
|
package/utils/color.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isColorDark = isColorDark;
|
|
4
|
+
function isColorDark(color) {
|
|
5
|
+
if (color.startsWith('#')) {
|
|
6
|
+
color = color.substring(1);
|
|
7
|
+
}
|
|
8
|
+
const rgb = parseInt(color, 16);
|
|
9
|
+
const r = (rgb >> 16) & 0xff;
|
|
10
|
+
const g = (rgb >> 8) & 0xff;
|
|
11
|
+
const b = (rgb >> 0) & 0xff;
|
|
12
|
+
const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
13
|
+
return luma < 128;
|
|
14
|
+
}
|
|
@@ -7,6 +7,7 @@ export declare function getAttributeFormattedValue<A extends Attribute = Attribu
|
|
|
7
7
|
maxCount?: number;
|
|
8
8
|
strings?: AttributeFormattedValueStringsSet;
|
|
9
9
|
dateFormat?: string;
|
|
10
|
+
timeFormat?: string;
|
|
10
11
|
locale?: string;
|
|
11
12
|
currency?: string;
|
|
12
13
|
currencySign?: 'accounting' | 'standard';
|
|
@@ -14,28 +14,30 @@ const defaultAttributeFormattedValueStrings = {
|
|
|
14
14
|
no: 'No',
|
|
15
15
|
};
|
|
16
16
|
const defaultDateFormat = 'YYYY-MM-DD';
|
|
17
|
+
const defaultTimeFormat = 'HH:mm';
|
|
17
18
|
const defaultLocale = 'en-US';
|
|
18
19
|
const defaultCurrency = 'USD';
|
|
19
20
|
const defaultCurrencySign = 'accounting';
|
|
20
21
|
const defaultCurrencyDisplay = 'symbol';
|
|
21
22
|
function getAttributeFormattedValue(attribute, value, options) {
|
|
22
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
23
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
23
24
|
if (value === null || value === undefined) {
|
|
24
25
|
return null;
|
|
25
26
|
}
|
|
26
27
|
const strings = (_a = options === null || options === void 0 ? void 0 : options.strings) !== null && _a !== void 0 ? _a : defaultAttributeFormattedValueStrings;
|
|
27
28
|
const dateFormat = (_b = options === null || options === void 0 ? void 0 : options.dateFormat) !== null && _b !== void 0 ? _b : defaultDateFormat;
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
29
|
+
const timeFormat = (_c = options === null || options === void 0 ? void 0 : options.timeFormat) !== null && _c !== void 0 ? _c : defaultTimeFormat;
|
|
30
|
+
const locale = (_d = options === null || options === void 0 ? void 0 : options.locale) !== null && _d !== void 0 ? _d : defaultLocale;
|
|
31
|
+
const currency = (_e = options === null || options === void 0 ? void 0 : options.currency) !== null && _e !== void 0 ? _e : defaultCurrency;
|
|
32
|
+
const currencySign = (_f = options === null || options === void 0 ? void 0 : options.currencySign) !== null && _f !== void 0 ? _f : defaultCurrencySign;
|
|
33
|
+
const currencyDisplay = (_g = options === null || options === void 0 ? void 0 : options.currencyDisplay) !== null && _g !== void 0 ? _g : defaultCurrencyDisplay;
|
|
32
34
|
switch (attribute.type) {
|
|
33
35
|
case 'boolean':
|
|
34
36
|
return value
|
|
35
|
-
? (
|
|
36
|
-
: (
|
|
37
|
+
? (_h = attribute.trueLabel) !== null && _h !== void 0 ? _h : strings.yes
|
|
38
|
+
: (_j = attribute.falseLabel) !== null && _j !== void 0 ? _j : strings.no;
|
|
37
39
|
case 'choice':
|
|
38
|
-
return ((
|
|
40
|
+
return ((_k = attribute.options.find((option) => option.value === value)) !== null && _k !== void 0 ? _k : {
|
|
39
41
|
label: '',
|
|
40
42
|
}).label;
|
|
41
43
|
case 'choices':
|
|
@@ -48,9 +50,16 @@ function getAttributeFormattedValue(attribute, value, options) {
|
|
|
48
50
|
})
|
|
49
51
|
.join(', ');
|
|
50
52
|
case 'date':
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
if (attribute.format === 'datetime') {
|
|
54
|
+
return (0, dayjs_1.default)(value)
|
|
55
|
+
.tz(options === null || options === void 0 ? void 0 : options.timezone)
|
|
56
|
+
.format(dateFormat + ' ' + timeFormat);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return (0, dayjs_1.default)(value)
|
|
60
|
+
.tz(options === null || options === void 0 ? void 0 : options.timezone)
|
|
61
|
+
.format(dateFormat);
|
|
62
|
+
}
|
|
54
63
|
case 'daterange':
|
|
55
64
|
if (!value)
|
|
56
65
|
return null;
|
|
@@ -92,7 +101,7 @@ function getAttributeFormattedValue(attribute, value, options) {
|
|
|
92
101
|
case 'number':
|
|
93
102
|
return new Intl.NumberFormat(locale).format(value);
|
|
94
103
|
case 'attachment':
|
|
95
|
-
return (
|
|
104
|
+
return (_l = value === null || value === void 0 ? void 0 : value.url) !== null && _l !== void 0 ? _l : null;
|
|
96
105
|
default:
|
|
97
106
|
return typeof value === 'object'
|
|
98
107
|
? JSON.stringify(value)
|