@headless-adminapp/app 0.0.17-alpha.41 → 0.0.17-alpha.45

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.
Files changed (37) hide show
  1. package/board/BoardColumnDataResolver.d.ts +1 -0
  2. package/board/BoardColumnDataResolver.js +64 -0
  3. package/board/BoardColumnProvider.d.ts +7 -0
  4. package/board/BoardColumnProvider.js +36 -0
  5. package/board/context.d.ts +19 -0
  6. package/board/context.js +6 -0
  7. package/board/hooks/index.d.ts +6 -0
  8. package/board/hooks/index.js +15 -0
  9. package/board/hooks/useBoardColumnConfig.d.ts +2 -0
  10. package/board/hooks/useBoardColumnConfig.js +8 -0
  11. package/board/hooks/useBoardColumnData.d.ts +1 -0
  12. package/board/hooks/useBoardColumnData.js +9 -0
  13. package/board/hooks/useBoardColumnDataState.d.ts +5 -0
  14. package/board/hooks/useBoardColumnDataState.js +9 -0
  15. package/board/hooks/useBoardConfig.d.ts +3 -0
  16. package/board/hooks/useBoardConfig.js +8 -0
  17. package/board/hooks/useBoardSchema.d.ts +2 -0
  18. package/board/hooks/useBoardSchema.js +7 -0
  19. package/board/hooks/useSearchText.d.ts +1 -0
  20. package/board/hooks/useSearchText.js +14 -0
  21. package/board/types.d.ts +47 -0
  22. package/board/types.js +2 -0
  23. package/board/utils.d.ts +3 -0
  24. package/board/utils.js +6 -0
  25. package/components/ScrollbarWithMoreDataRequest/index.d.ts +9 -0
  26. package/components/ScrollbarWithMoreDataRequest/index.js +33 -0
  27. package/dataform/hooks/index.d.ts +1 -0
  28. package/dataform/hooks/index.js +1 -0
  29. package/dataform/hooks/useProcessFlowSteps.d.ts +1 -0
  30. package/dataform/hooks/useProcessFlowSteps.js +44 -0
  31. package/datagrid/DataGridProvider/DataResolver.js +18 -102
  32. package/package.json +2 -2
  33. package/transport/hooks/useRetriveRecords.d.ts +32 -0
  34. package/transport/hooks/useRetriveRecords.js +120 -0
  35. package/utils/color.d.ts +1 -0
  36. package/utils/color.js +14 -0
  37. package/utils/getAttributeFormattedValue.js +1 -1
@@ -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>>>;
@@ -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,2 @@
1
+ import { BoardColumnConfig } from '../types';
2
+ export declare function useBoardColumnConfig(): BoardColumnConfig;
@@ -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,5 @@
1
+ export declare function useBoardColumnDataState(): {
2
+ isFetching: boolean;
3
+ hasNextPage: boolean;
4
+ isFetchingNextPage: boolean;
5
+ };
@@ -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,3 @@
1
+ import { SchemaAttributes } from '@headless-adminapp/core/schema';
2
+ import { BoardConfig } from '../types';
3
+ export declare function useBoardConfig<S extends SchemaAttributes = SchemaAttributes>(): BoardConfig<S>;
@@ -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,2 @@
1
+ import { SchemaAttributes } from '@headless-adminapp/core/schema';
2
+ export declare function useBoardSchema<S extends SchemaAttributes = SchemaAttributes>(): import("@headless-adminapp/core/schema").Schema<S>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useBoardSchema = useBoardSchema;
4
+ const useBoardConfig_1 = require("./useBoardConfig");
5
+ function useBoardSchema() {
6
+ return (0, useBoardConfig_1.useBoardConfig)().schema;
7
+ }
@@ -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
+ }
@@ -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
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import { SchemaAttributes } from '@headless-adminapp/core/schema';
2
+ import { BoardConfig } from './types';
3
+ export declare function defineBoardConfig<S extends SchemaAttributes = SchemaAttributes>(config: BoardConfig<S>): BoardConfig<S>;
package/board/utils.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineBoardConfig = defineBoardConfig;
4
+ function defineBoardConfig(config) {
5
+ return config;
6
+ }
@@ -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;
@@ -10,3 +10,4 @@ export * from './useRecordId';
10
10
  export * from './useRecordTitle';
11
11
  export * from './useSelectedForm';
12
12
  export * from './useLoadFormGridPage';
13
+ export * from './useProcessFlowSteps';
@@ -26,3 +26,4 @@ __exportStar(require("./useRecordId"), exports);
26
26
  __exportStar(require("./useRecordTitle"), exports);
27
27
  __exportStar(require("./useSelectedForm"), exports);
28
28
  __exportStar(require("./useLoadFormGridPage"), exports);
29
+ __exportStar(require("./useProcessFlowSteps"), exports);
@@ -0,0 +1 @@
1
+ export declare function useProcessFlowSteps(): import("@headless-adminapp/core/experience/form/ProcessFlowInfo").ProcessFlowStep[] | undefined;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useProcessFlowSteps = useProcessFlowSteps;
4
+ const command_1 = require("@headless-adminapp/app/command");
5
+ const context_1 = require("../../mutable/context");
6
+ const context_2 = require("../context");
7
+ const useFormInstance_1 = require("./useFormInstance");
8
+ const useFormIsReadonly_1 = require("./useFormIsReadonly");
9
+ const useFormRecord_1 = require("./useFormRecord");
10
+ const useFormSchema_1 = require("./useFormSchema");
11
+ const useRecordId_1 = require("./useRecordId");
12
+ const useSelectedForm_1 = require("./useSelectedForm");
13
+ function useFormControlContext() {
14
+ var _a;
15
+ const schema = (0, useFormSchema_1.useDataFormSchema)();
16
+ const form = (0, context_1.useContextSelector)(context_2.DataFormContext, (state) => state.form);
17
+ const originalData = (0, useFormRecord_1.useFormRecord)();
18
+ const recordId = (0, useRecordId_1.useRecordId)();
19
+ const formInstance = (0, useFormInstance_1.useFormInstance)();
20
+ const readonly = (_a = (0, useFormIsReadonly_1.useFormIsReadonly)()) !== null && _a !== void 0 ? _a : false;
21
+ const data = formInstance.watch();
22
+ return {
23
+ data,
24
+ logicalName: schema.logicalName,
25
+ schema,
26
+ form,
27
+ formId: form.id,
28
+ originalData: originalData !== null && originalData !== void 0 ? originalData : null,
29
+ recordId,
30
+ readonly,
31
+ };
32
+ }
33
+ function useProcessFlowInfoContext() {
34
+ const primaryControl = useFormControlContext();
35
+ const baseHandlerContext = (0, command_1.useBaseCommandHandlerContext)();
36
+ return Object.assign(Object.assign({}, baseHandlerContext), { primaryControl });
37
+ }
38
+ function useProcessFlowSteps() {
39
+ var _a;
40
+ const formConfig = (0, useSelectedForm_1.useSelectedForm)();
41
+ const context = useProcessFlowInfoContext();
42
+ const steps = (_a = formConfig.experience.processFlow) === null || _a === void 0 ? void 0 : _a.getSteps(context);
43
+ return steps;
44
+ }
@@ -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 react_query_1 = require("@tanstack/react-query");
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 queryKey = (0, react_1.useMemo)(() => [
47
- 'data',
48
- 'retriveRecords',
49
- schema.logicalName,
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
- columnFilters,
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
- extraFilter,
63
- schema.logicalName,
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
- var _a, _b, _c, _d;
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 finalData = {
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: finalData,
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.41",
3
+ "version": "0.0.17-alpha.45",
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": "2feaed5c73b0732b74518d37af5b5f26925e89d8"
42
+ "gitHead": "7538074665d8fa6f67ca2a91e62ea32d09570a31"
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 | string[] | Filter | Partial<Record<string, string[]>> | SortingState<S> | 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
+ }
@@ -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
+ }
@@ -50,7 +50,7 @@ function getAttributeFormattedValue(attribute, value, options) {
50
50
  })
51
51
  .join(', ');
52
52
  case 'date':
53
- if (attribute.format === 'date') {
53
+ if (attribute.format === 'datetime') {
54
54
  return (0, dayjs_1.default)(value)
55
55
  .tz(options === null || options === void 0 ? void 0 : options.timezone)
56
56
  .format(dateFormat + ' ' + timeFormat);