@uxf/data-grid 10.0.7 → 11.0.0-beta.2

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 (203) hide show
  1. package/_store/reducer.d.ts +8 -0
  2. package/{store → _store}/reducer.js +33 -19
  3. package/_story-utils/data.d.ts +12 -0
  4. package/_story-utils/data.js +115 -0
  5. package/_story-utils/grid-type.d.ts +22 -0
  6. package/_story-utils/grid-type.js +2 -0
  7. package/_story-utils/loader.d.ts +2 -0
  8. package/_story-utils/loader.js +36 -0
  9. package/_story-utils/schema.d.ts +3 -0
  10. package/_story-utils/schema.js +53 -0
  11. package/{tailwindui/body-cell → body-cell}/body-cell-boolean.d.ts +1 -1
  12. package/{tailwindui/body-cell → body-cell}/body-cell-date.d.ts +1 -1
  13. package/{tailwindui/body-cell → body-cell}/body-cell-datetime.d.ts +1 -1
  14. package/{tailwindui/body-cell → body-cell}/body-cell-default.d.ts +1 -1
  15. package/{tailwindui/body-cell → body-cell}/body-cell-email.d.ts +1 -1
  16. package/{tailwindui/body-cell → body-cell}/body-cell-phone.d.ts +1 -1
  17. package/{tailwindui/body-cell → body-cell}/body-cell-to-many.d.ts +1 -1
  18. package/{tailwindui/body-cell → body-cell}/body-cell-to-one.d.ts +1 -1
  19. package/{tailwindui/body-cell → body-cell}/body-cell-url.d.ts +1 -1
  20. package/{tailwindui/body-cell → body-cell}/index.d.ts +1 -1
  21. package/data-grid.d.ts +1 -1
  22. package/data-grid.js +34 -120
  23. package/data-grid.stories.d.ts +0 -5
  24. package/data-grid.stories.js +14 -216
  25. package/export-button/export-button.d.ts +10 -0
  26. package/export-button/export-button.js +15 -0
  27. package/export-button/export-button.stories.d.ts +2 -0
  28. package/export-button/export-button.stories.js +18 -0
  29. package/export-button/index.d.ts +1 -0
  30. package/{tailwindui → export-button}/index.js +1 -3
  31. package/{tailwindui/filter-handler → filter-handler}/bool-filter.d.ts +1 -1
  32. package/{tailwindui/filter-handler → filter-handler}/boolean-filter.d.ts +1 -1
  33. package/filter-handler/index.d.ts +4 -0
  34. package/{tailwindui/filter-handler → filter-handler}/index.js +15 -0
  35. package/{tailwindui/filter-handler → filter-handler}/interval-filter.d.ts +1 -1
  36. package/{tailwindui/filter-handler → filter-handler}/interval-filter.js +2 -2
  37. package/{tailwindui/filter-handler → filter-handler}/select-filter.d.ts +1 -1
  38. package/{tailwindui/filter-handler → filter-handler}/text-filter.d.ts +1 -1
  39. package/filter-handler/types.d.ts +8 -0
  40. package/filter-handler/types.js +2 -0
  41. package/filter-list/filter-list.d.ts +11 -0
  42. package/{tailwindui/components → filter-list}/filter-list.js +7 -6
  43. package/filter-list/filter-list.stories.d.ts +2 -0
  44. package/filter-list/filter-list.stories.js +19 -0
  45. package/filter-list/index.d.ts +1 -0
  46. package/filter-list/index.js +17 -0
  47. package/filters/filters.d.ts +11 -0
  48. package/filters/filters.js +25 -0
  49. package/filters/filters.stories.d.ts +2 -0
  50. package/filters/filters.stories.js +19 -0
  51. package/filters/index.d.ts +1 -0
  52. package/filters/index.js +17 -0
  53. package/filters-button/filters-button.d.ts +11 -0
  54. package/{tailwindui/show.js → filters-button/filters-button.js} +15 -6
  55. package/filters-button/filters-button.stories.d.ts +2 -0
  56. package/filters-button/filters-button.stories.js +19 -0
  57. package/filters-button/index.d.ts +1 -0
  58. package/filters-button/index.js +17 -0
  59. package/fulltext-input/fulltext-input.d.ts +5 -0
  60. package/fulltext-input/fulltext-input.js +13 -0
  61. package/fulltext-input/fulltext-input.stories.d.ts +2 -0
  62. package/fulltext-input/fulltext-input.stories.js +18 -0
  63. package/fulltext-input/index.d.ts +1 -0
  64. package/fulltext-input/index.js +17 -0
  65. package/hidden-columns/hidden-columns.d.ts +8 -0
  66. package/hidden-columns/hidden-columns.js +17 -0
  67. package/hidden-columns/hidden-columns.stories.d.ts +2 -0
  68. package/hidden-columns/hidden-columns.stories.js +18 -0
  69. package/hidden-columns/index.d.ts +1 -0
  70. package/hidden-columns/index.js +17 -0
  71. package/hidden-columns-button/hidden-columns-button.d.ts +8 -0
  72. package/{tailwindui/data-grid.js → hidden-columns-button/hidden-columns-button.js} +14 -10
  73. package/hidden-columns-button/hidden-columns-button.stories.d.ts +2 -0
  74. package/hidden-columns-button/hidden-columns-button.stories.js +18 -0
  75. package/hidden-columns-button/index.d.ts +1 -0
  76. package/hidden-columns-button/index.js +17 -0
  77. package/linear-progress/index.d.ts +1 -0
  78. package/linear-progress/index.js +17 -0
  79. package/linear-progress/linear-progress.d.ts +5 -0
  80. package/{tailwindui/components → linear-progress}/linear-progress.js +4 -4
  81. package/package.json +1 -1
  82. package/pagination/index.d.ts +1 -0
  83. package/pagination/index.js +17 -0
  84. package/pagination/pagination.d.ts +8 -0
  85. package/pagination/pagination.js +16 -0
  86. package/pagination/pagination.stories.d.ts +2 -0
  87. package/pagination/pagination.stories.js +18 -0
  88. package/row-counts/index.d.ts +1 -0
  89. package/row-counts/index.js +17 -0
  90. package/row-counts/row-counts.d.ts +7 -0
  91. package/row-counts/row-counts.js +18 -0
  92. package/row-counts/row-counts.stories.d.ts +2 -0
  93. package/row-counts/row-counts.stories.js +15 -0
  94. package/rows-per-page-select/index.d.ts +1 -0
  95. package/rows-per-page-select/index.js +17 -0
  96. package/rows-per-page-select/rows-per-page-select.d.ts +3 -0
  97. package/{tailwindui/components/pagination-rows-per-page-select.js → rows-per-page-select/rows-per-page-select.js} +5 -5
  98. package/rows-per-page-select/rows-per-page-select.stories.d.ts +2 -0
  99. package/rows-per-page-select/rows-per-page-select.stories.js +18 -0
  100. package/selected-rows-toolbar/index.d.ts +1 -0
  101. package/selected-rows-toolbar/index.js +17 -0
  102. package/selected-rows-toolbar/selected-rows-toolbar.d.ts +11 -0
  103. package/{tailwindui/components → selected-rows-toolbar}/selected-rows-toolbar.js +9 -6
  104. package/selected-rows-toolbar/selected-rows-toolbar.stories.d.ts +2 -0
  105. package/{tailwindui/components/select-row-checkbox.js → selected-rows-toolbar/selected-rows-toolbar.stories.js} +15 -14
  106. package/table/components/select-row-checkbox.d.ts +3 -0
  107. package/table/components/select-row-checkbox.js +20 -0
  108. package/table/hooks/use-react-data-grid-columns.d.ts +3 -0
  109. package/table/hooks/use-react-data-grid-columns.js +92 -0
  110. package/table/index.d.ts +1 -0
  111. package/table/index.js +17 -0
  112. package/table/no-rows-fallback.d.ts +7 -0
  113. package/{tailwindui/components → table}/no-rows-fallback.js +4 -4
  114. package/table/table.d.ts +3 -0
  115. package/table/table.js +80 -0
  116. package/table/table.stories.d.ts +2 -0
  117. package/table/table.stories.js +20 -0
  118. package/table/types.d.ts +26 -0
  119. package/table/types.js +2 -0
  120. package/toolbar-control/index.d.ts +1 -0
  121. package/toolbar-control/index.js +17 -0
  122. package/toolbar-control/toolbar-control.d.ts +13 -0
  123. package/toolbar-control/toolbar-control.js +22 -0
  124. package/toolbar-control/toolbar-control.stories.d.ts +2 -0
  125. package/toolbar-control/toolbar-control.stories.js +20 -0
  126. package/toolbar-customs/index.d.ts +1 -0
  127. package/toolbar-customs/index.js +17 -0
  128. package/toolbar-customs/toolbar-customs.d.ts +10 -0
  129. package/{tailwindui/components → toolbar-customs}/toolbar-customs.js +2 -2
  130. package/toolbar-customs/toolbar-customs.stories.d.ts +2 -0
  131. package/toolbar-customs/toolbar-customs.stories.js +16 -0
  132. package/toolbar-tabs/index.d.ts +1 -0
  133. package/toolbar-tabs/index.js +17 -0
  134. package/toolbar-tabs/toolbar-tabs.d.ts +7 -0
  135. package/{tailwindui/components → toolbar-tabs}/toolbar-tabs.js +10 -10
  136. package/toolbar-tabs/toolbar-tabs.stories.d.ts +2 -0
  137. package/toolbar-tabs/toolbar-tabs.stories.js +18 -0
  138. package/types/components.d.ts +5 -160
  139. package/types/data-grid-props.d.ts +16 -23
  140. package/types/state.d.ts +7 -3
  141. package/types/ui-components.d.ts +7 -16
  142. package/use-data-grid-control/actions-factory.d.ts +14 -0
  143. package/use-data-grid-control/actions-factory.js +18 -0
  144. package/use-data-grid-control/index.d.ts +1 -0
  145. package/use-data-grid-control/index.js +17 -0
  146. package/use-data-grid-control/use-data-grid-control.d.ts +25 -0
  147. package/use-data-grid-control/use-data-grid-control.js +12 -0
  148. package/use-data-grid-fetching/index.d.ts +1 -0
  149. package/use-data-grid-fetching/index.js +17 -0
  150. package/use-data-grid-fetching/use-data-grid-fetching.d.ts +16 -0
  151. package/use-data-grid-fetching/use-data-grid-fetching.js +37 -0
  152. package/utils/classes.d.ts +1 -0
  153. package/utils/classes.js +4 -0
  154. package/utils.d.ts +4 -5
  155. package/utils.js +9 -60
  156. package/hooks/useColumns.d.ts +0 -3
  157. package/hooks/useColumns.js +0 -97
  158. package/store/reducer.d.ts +0 -5
  159. package/tailwindui/components/container.d.ts +0 -2
  160. package/tailwindui/components/container.js +0 -13
  161. package/tailwindui/components/filter-list.d.ts +0 -2
  162. package/tailwindui/components/footer.d.ts +0 -2
  163. package/tailwindui/components/footer.js +0 -12
  164. package/tailwindui/components/linear-progress.d.ts +0 -2
  165. package/tailwindui/components/no-rows-fallback.d.ts +0 -2
  166. package/tailwindui/components/pagination-counts.d.ts +0 -2
  167. package/tailwindui/components/pagination-counts.js +0 -18
  168. package/tailwindui/components/pagination-rows-per-page-select.d.ts +0 -2
  169. package/tailwindui/components/select-row-checkbox.d.ts +0 -2
  170. package/tailwindui/components/selected-rows-toolbar.d.ts +0 -2
  171. package/tailwindui/components/toolbar-control.d.ts +0 -2
  172. package/tailwindui/components/toolbar-control.js +0 -86
  173. package/tailwindui/components/toolbar-customs.d.ts +0 -2
  174. package/tailwindui/components/toolbar-tabs.d.ts +0 -2
  175. package/tailwindui/components/toolbar.d.ts +0 -2
  176. package/tailwindui/components/toolbar.js +0 -12
  177. package/tailwindui/data-grid.d.ts +0 -6
  178. package/tailwindui/filter-handler/index.d.ts +0 -2
  179. package/tailwindui/index.d.ts +0 -3
  180. package/tailwindui/show.d.ts +0 -7
  181. package/tailwindui/styles.css +0 -592
  182. package/tailwindui/ui.d.ts +0 -2
  183. package/tailwindui/ui.js +0 -38
  184. /package/{tailwindui/components → _components}/drawer.d.ts +0 -0
  185. /package/{tailwindui/components → _components}/drawer.js +0 -0
  186. /package/{store → _store}/actions.d.ts +0 -0
  187. /package/{store → _store}/actions.js +0 -0
  188. /package/{tailwindui/body-cell → body-cell}/body-cell-boolean.js +0 -0
  189. /package/{tailwindui/body-cell → body-cell}/body-cell-date.js +0 -0
  190. /package/{tailwindui/body-cell → body-cell}/body-cell-datetime.js +0 -0
  191. /package/{tailwindui/body-cell → body-cell}/body-cell-default.js +0 -0
  192. /package/{tailwindui/body-cell → body-cell}/body-cell-email.js +0 -0
  193. /package/{tailwindui/body-cell → body-cell}/body-cell-phone.js +0 -0
  194. /package/{tailwindui/body-cell → body-cell}/body-cell-to-many.js +0 -0
  195. /package/{tailwindui/body-cell → body-cell}/body-cell-to-one.js +0 -0
  196. /package/{tailwindui/body-cell → body-cell}/body-cell-url.js +0 -0
  197. /package/{tailwindui/body-cell → body-cell}/index.js +0 -0
  198. /package/{tailwindui/filter-handler → filter-handler}/bool-filter.js +0 -0
  199. /package/{tailwindui/filter-handler → filter-handler}/boolean-filter.js +0 -0
  200. /package/{tailwindui/filter-handler → filter-handler}/select-filter.js +0 -0
  201. /package/{tailwindui/filter-handler → filter-handler}/text-filter.js +0 -0
  202. /package/{tailwindui → table}/components/action-cell-base.d.ts +0 -0
  203. /package/{tailwindui → table}/components/action-cell-base.js +0 -0
@@ -1,13 +1,6 @@
1
- import { PaginationProps } from "@uxf/ui/pagination/pagination";
2
- import React, { ComponentType, FC, ReactElement, ReactNode } from "react";
3
- import { RenderCheckboxProps } from "react-data-grid";
4
- import { RequestFilter, Response } from "./api";
5
- import { ChangeHiddenColumnsHandler, CsvDownloadHandler } from "./core";
6
- import { BaseGridType, Columns, Filter, Filters, Schema } from "./schema";
7
- import { DataGridState } from "./state";
8
- /**
9
- * Action cell
10
- */
1
+ import { ComponentType, FC } from "react";
2
+ import { RequestFilter } from "./api";
3
+ import { BaseGridType, Columns, Filter } from "./schema";
11
4
  export interface ActionCellProps<R> {
12
5
  row: R;
13
6
  onOpen?: (row: R) => void;
@@ -15,47 +8,20 @@ export interface ActionCellProps<R> {
15
8
  onEdit?: (row: R) => void;
16
9
  getEditUrl?: (row: R) => string | null | undefined;
17
10
  onRemove?: (row: R, reload: () => void) => void;
18
- reload: () => Promise<void>;
11
+ reload: () => void;
19
12
  }
20
13
  export type ActionCellComponent<R> = FC<ActionCellProps<R>>;
21
- /**
22
- * Body cell
23
- */
24
14
  export interface BodyCellProps<C, R> {
25
15
  value: any;
26
16
  column: C;
27
17
  row: R;
28
- reload: () => Promise<void>;
18
+ reload: () => void;
29
19
  }
30
20
  export type BodyCellComponent<C extends BaseGridType["columns"], R> = ComponentType<BodyCellProps<Columns<C>, R>>;
31
21
  export type BodyCellComponents<C, R> = {
32
22
  [key: string]: BodyCellComponent<C, R>;
33
23
  default: BodyCellComponent<C, R>;
34
24
  };
35
- /**
36
- * Container
37
- */
38
- export interface ContainerProps {
39
- noBorder?: boolean;
40
- children: ReactNode;
41
- className?: string;
42
- }
43
- export type ContainerComponent = FC<ContainerProps>;
44
- /**
45
- * Filter list
46
- */
47
- export interface FilterListProps<F extends Filter<any, any>, T> {
48
- gridName?: string;
49
- filters: F[];
50
- filtersData: RequestFilter<T>[];
51
- onFilter: (value: RequestFilter<T>) => void;
52
- filterHandlers: FilterHandlers;
53
- noBorder: boolean | null | undefined;
54
- }
55
- export type FilterListComponent<F extends BaseGridType["filters"], T = any> = ComponentType<FilterListProps<Filters<F>, T>>;
56
- /**
57
- * Filters
58
- */
59
25
  export interface FilterProps<F extends Filter<any, any>, T> {
60
26
  gridName?: string;
61
27
  filter: F;
@@ -63,124 +29,3 @@ export interface FilterProps<F extends Filter<any, any>, T> {
63
29
  onFilter: (value: RequestFilter<T>) => void;
64
30
  onClear: () => void;
65
31
  }
66
- export type FilterComponent<F extends BaseGridType["filters"], T = any> = ComponentType<FilterProps<Filters<F>, T>>;
67
- export interface FilterHandler {
68
- input: FilterComponent<any>;
69
- listItem: FilterComponent<any>;
70
- }
71
- export interface FilterHandlers {
72
- [key: string]: FilterHandler;
73
- }
74
- /**
75
- * Footer
76
- */
77
- export interface FooterProps {
78
- children: ReactNode;
79
- noBorder?: boolean;
80
- }
81
- export type FooterComponent = FC<FooterProps>;
82
- /**
83
- * Linear progress
84
- */
85
- export interface LinearProgressProps {
86
- loading: boolean;
87
- }
88
- export type LinearProgressComponent = FC<LinearProgressProps>;
89
- /**
90
- * No rows fallback
91
- */
92
- export interface NoRowsFallbackProps {
93
- error?: any;
94
- loading: boolean;
95
- }
96
- export type NoRowsFallbackComponent = React.FC<NoRowsFallbackProps>;
97
- /**
98
- * Pagination
99
- */
100
- export type PaginationComponent = React.FC<PaginationProps>;
101
- /**
102
- * Pagination rows per page select
103
- */
104
- export interface PaginationRowsPerPageSelectProps {
105
- value: number;
106
- onChange: (value: number) => void;
107
- }
108
- export type PaginationRowsPerPageSelectComponent = FC<PaginationRowsPerPageSelectProps>;
109
- /**
110
- * Pagination counts
111
- */
112
- export interface PaginationCountsProps {
113
- page: number;
114
- perPage: number;
115
- response?: Response;
116
- }
117
- export type PaginationCountsComponent = FC<PaginationCountsProps>;
118
- /**
119
- * Selected rows toolbar
120
- */
121
- export interface SelectedRowsToolbarProps {
122
- selectedRows?: Set<number>;
123
- onChangeSelectedRows?: (rows: Set<number>) => void;
124
- Actions?: SelectedRowsToolbarActionsComponent;
125
- reload: () => Promise<void>;
126
- }
127
- export type SelectedRowsToolbarComponent = FC<SelectedRowsToolbarProps>;
128
- /**
129
- * Select row checkbox
130
- */
131
- export type SelectRowCheckboxComponent = React.FC<RenderCheckboxProps>;
132
- /**
133
- * Selected rows toolbar actions
134
- */
135
- export interface SelectedRowsToolbarActionsProps {
136
- selectedRows: Set<number>;
137
- onChangeSelectedRows: (rows: Set<number>) => void;
138
- reload: () => Promise<void>;
139
- }
140
- export type SelectedRowsToolbarActionsComponent = FC<SelectedRowsToolbarActionsProps>;
141
- /**
142
- * Toolbar
143
- */
144
- export interface ToolbarProps {
145
- children: ReactNode;
146
- noBorder?: boolean;
147
- }
148
- export type ToolbarComponent = FC<ToolbarProps>;
149
- /**
150
- * Toolbar control
151
- */
152
- export interface ToolbarControlProps {
153
- gridName: string | undefined;
154
- schema: Schema<any>;
155
- dispatch: (action: any) => void;
156
- filterHandlers: FilterHandlers;
157
- onFulltextChange: (value: string) => void;
158
- noBorder: boolean | null | undefined;
159
- onChangeHiddenColumns?: ChangeHiddenColumnsHandler;
160
- onCsvDownload?: CsvDownloadHandler;
161
- hiddenColumns?: string[];
162
- showFulltext?: boolean;
163
- state: DataGridState;
164
- }
165
- export type ToolbarControlComponent = React.FC<ToolbarControlProps>;
166
- /**
167
- * Toolbar customs
168
- */
169
- export interface ToolbarCustomsProps {
170
- buttons?: {
171
- label: string | ReactElement;
172
- onClick?: () => void;
173
- href?: string;
174
- variant?: "default" | "outlined" | "text";
175
- }[];
176
- }
177
- export type ToolbarCustomsComponent = React.FC<ToolbarCustomsProps>;
178
- /**
179
- * Toolbar tabs
180
- */
181
- export interface ToolbarTabsProps {
182
- activeTab: string | null;
183
- onChange: (tabName: string) => void;
184
- schema: Schema<any>;
185
- }
186
- export type ToolbarTabsComponent = React.FC<ToolbarTabsProps>;
@@ -1,38 +1,31 @@
1
- import { MutableRefObject, ReactNode } from "react";
2
1
  import { DataGridProps as RDGProps } from "react-data-grid";
3
- import { Request } from "./api";
4
- import { ToolbarCustomsProps } from "./components";
5
- import { CallbackRef, ChangeHiddenColumnsHandler, Config, CsvDownloadHandler, KeyExtractor, Loader } from "./core";
2
+ import { ToolbarCustomsProps } from "../toolbar-customs";
3
+ import { DataGridControl } from "../use-data-grid-control";
4
+ import { DataGridFetchingResult } from "../use-data-grid-fetching";
5
+ import { CsvDownloadHandler, KeyExtractor } from "./core";
6
6
  import { BaseGridType, Schema } from "./schema";
7
7
  import { UIComponents } from "./ui-components";
8
- export type DataGridBaseProps<GridType extends BaseGridType, R> = {
9
- callbackRef?: MutableRefObject<CallbackRef | undefined>;
8
+ export type DataGridControlProps = DataGridControl;
9
+ export type DataGridDataProps<Row> = DataGridFetchingResult<Row>;
10
+ export type DataGridBaseProps<GridType extends BaseGridType, Row> = {
10
11
  schema: Schema<GridType>;
11
- loader: Loader;
12
12
  gridName?: string;
13
- title?: ReactNode;
14
13
  keyExtractor?: KeyExtractor;
15
- initialState?: Request | string;
16
- onChangeHiddenColumns?: ChangeHiddenColumnsHandler;
17
14
  onCsvDownload?: CsvDownloadHandler;
18
- hiddenColumns?: string[];
19
- onChangeSelectedRows?: (selectedRows: Set<number>) => void;
20
- selectedRows?: Set<number>;
21
- onOpen?: (row: R) => void;
22
- getOpenUrl?: (row: R) => string | null | undefined;
23
- onEdit?: (row: R) => void;
24
- getEditUrl?: (row: R) => string | null | undefined;
25
- onRemove?: (row: R, reload: () => void) => void;
15
+ onOpen?: (row: Row) => void;
16
+ getOpenUrl?: (row: Row) => string | null | undefined;
17
+ onEdit?: (row: Row) => void;
18
+ getEditUrl?: (row: Row) => string | null | undefined;
19
+ onRemove?: (row: Row, reload: () => void) => void;
26
20
  noBorder?: boolean;
27
21
  rowHeight?: RDGProps<any>["rowHeight"];
28
22
  headerRowHeight?: RDGProps<any>["headerRowHeight"];
29
- defaultConfig?: Config<GridType["columns"]>;
30
- rowClass?: (row: R) => "success" | "warning" | "error" | "primary" | "secondary" | string | null | undefined;
23
+ rowClass?: (row: Row) => "success" | "warning" | "error" | "primary" | "secondary" | string | null | undefined;
31
24
  debug?: boolean;
32
25
  className?: string;
33
26
  customActions?: ToolbarCustomsProps["buttons"];
34
27
  mode?: "light" | "dark";
28
+ ui?: UIComponents<GridType, Row>;
29
+ isRowSelectable?: boolean;
35
30
  };
36
- export type DataGridProps<GridType extends BaseGridType, R> = DataGridBaseProps<GridType, R> & {
37
- ui: UIComponents<GridType, R>;
38
- };
31
+ export type DataGridProps<GridType extends BaseGridType, Row> = DataGridBaseProps<GridType, Row> & DataGridDataProps<Row> & DataGridControlProps;
package/types/state.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RequestFilter, Response } from "./api";
2
2
  import { DataGridSortDir } from "./schema";
3
- type GridRequest = {
3
+ export type GridRequest = {
4
4
  f: RequestFilter[];
5
5
  sort: string | null;
6
6
  dir: DataGridSortDir | null;
@@ -9,11 +9,15 @@ type GridRequest = {
9
9
  search: string;
10
10
  tab: string | null;
11
11
  };
12
+ interface ColumnConfig {
13
+ isHidden: boolean;
14
+ width?: number;
15
+ }
12
16
  export interface DataGridState {
13
- loading?: boolean;
14
17
  response?: Response;
15
18
  request: GridRequest;
16
- error?: any;
19
+ selectedRows?: any[];
20
+ columnConfig: Record<string, ColumnConfig>;
17
21
  tabRequests: {
18
22
  [tab: string]: GridRequest;
19
23
  };
@@ -1,4 +1,7 @@
1
- import { ActionCellComponent, BodyCellComponents, ContainerComponent, FilterHandlers, FilterListComponent, LinearProgressComponent, NoRowsFallbackComponent, PaginationComponent, PaginationCountsComponent, PaginationRowsPerPageSelectComponent, SelectedRowsToolbarActionsComponent, SelectedRowsToolbarComponent, SelectRowCheckboxComponent, ToolbarComponent, ToolbarControlComponent, ToolbarCustomsComponent, ToolbarTabsComponent } from "./components";
1
+ import { FilterHandlers } from "../filter-handler";
2
+ import { SelectedRowsToolbarActionsComponent } from "../selected-rows-toolbar";
3
+ import { NoRowsFallbackComponent } from "../table/no-rows-fallback";
4
+ import { ActionCellComponent, BodyCellComponents } from "./components";
2
5
  import { BaseGridType } from "./schema";
3
6
  export type ActionCellWithRequiredWidth<R> = {
4
7
  ActionCell?: ActionCellComponent<R>;
@@ -8,20 +11,8 @@ export type ActionCellWithRequiredWidth<R> = {
8
11
  actionCellWidth?: never;
9
12
  };
10
13
  export type UIComponents<GridType extends BaseGridType, R> = {
11
- BodyCells: BodyCellComponents<GridType["columns"], R>;
12
- Container: ContainerComponent;
13
- FilterHandlers: FilterHandlers;
14
- FilterList: FilterListComponent<GridType["filters"], R>;
15
- LinearProgress: LinearProgressComponent;
16
- NoRowsFallback: NoRowsFallbackComponent;
17
- Pagination: PaginationComponent;
18
- PaginationCounts: PaginationCountsComponent;
19
- PaginationRowsPerPageSelect: PaginationRowsPerPageSelectComponent;
20
- SelectRowCheckbox: SelectRowCheckboxComponent;
21
- SelectedRowsToolbar: SelectedRowsToolbarComponent;
14
+ BodyCells?: BodyCellComponents<GridType["columns"], R>;
15
+ FilterHandlers?: FilterHandlers;
16
+ NoRowsFallback?: NoRowsFallbackComponent;
22
17
  SelectedRowsToolbarActions?: SelectedRowsToolbarActionsComponent;
23
- Toolbar: ToolbarComponent;
24
- ToolbarControl: ToolbarControlComponent;
25
- ToolbarCustoms: ToolbarCustomsComponent;
26
- ToolbarTabs: ToolbarTabsComponent;
27
18
  } & ActionCellWithRequiredWidth<R>;
@@ -0,0 +1,14 @@
1
+ import { Dispatch } from "react";
2
+ import { RequestFilter } from "../types/api";
3
+ export declare function createActions(dispatch: Dispatch<any>): {
4
+ changePage: (page: number) => void;
5
+ changePerPage: (perPage: number) => void;
6
+ filter: (filterValue: RequestFilter) => void;
7
+ sort: (columnName: string, direction: string) => void;
8
+ sortClear: () => void;
9
+ search: (search: string) => void;
10
+ changeTab: (tabName: string) => void;
11
+ setSelectedRows: (rows: any[]) => void;
12
+ hideColumn: (name: string) => void;
13
+ showColumn: (name: string) => void;
14
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createActions = void 0;
4
+ function createActions(dispatch) {
5
+ return {
6
+ changePage: (page) => dispatch({ type: "CHANGE_PAGE", page }),
7
+ changePerPage: (perPage) => dispatch({ type: "CHANGE_PER_PAGE", perPage }),
8
+ filter: (filterValue) => dispatch({ type: "FILTER", filterValue }),
9
+ sort: (columnName, direction) => dispatch({ type: "SORT", columnName, direction }),
10
+ sortClear: () => dispatch({ type: "SORT_CLEAR" }),
11
+ search: (search) => dispatch({ type: "FULLTEXT", search }),
12
+ changeTab: (tabName) => dispatch({ type: "CHANGE_TAB", name: tabName }),
13
+ setSelectedRows: (rows) => dispatch({ type: "SET_SELECTED_ROWS", rows }),
14
+ hideColumn: (name) => dispatch({ type: "HIDE_COLUMN", name }),
15
+ showColumn: (name) => dispatch({ type: "SHOW_COLUMN", name }),
16
+ };
17
+ }
18
+ exports.createActions = createActions;
@@ -0,0 +1 @@
1
+ export * from "./use-data-grid-control";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./use-data-grid-control"), exports);
@@ -0,0 +1,25 @@
1
+ import { Nullish } from "@uxf/core/types";
2
+ import { Request } from "../types/api";
3
+ import { Schema } from "../types/schema";
4
+ interface Config {
5
+ schema: Schema<any>;
6
+ initialState?: Request | string | Nullish;
7
+ isDebug?: boolean;
8
+ }
9
+ export declare function useDataGridControl(config: Config): {
10
+ state: import("..").DataGridState;
11
+ actions: {
12
+ changePage: (page: number) => void;
13
+ changePerPage: (perPage: number) => void;
14
+ filter: (filterValue: import("../types/api").RequestFilter<any>) => void;
15
+ sort: (columnName: string, direction: string) => void;
16
+ sortClear: () => void;
17
+ search: (search: string) => void;
18
+ changeTab: (tabName: string) => void;
19
+ setSelectedRows: (rows: any[]) => void;
20
+ hideColumn: (name: string) => void;
21
+ showColumn: (name: string) => void;
22
+ };
23
+ };
24
+ export type DataGridControl = ReturnType<typeof useDataGridControl>;
25
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDataGridControl = void 0;
4
+ const react_1 = require("react");
5
+ const reducer_1 = require("../_store/reducer");
6
+ const actions_factory_1 = require("./actions-factory");
7
+ function useDataGridControl(config) {
8
+ const [state, dispatch] = (0, react_1.useReducer)(config.isDebug ? reducer_1.debugReducer : reducer_1.reducer, (0, reducer_1.getInitialState)(config.schema, config.initialState));
9
+ const actions = (0, react_1.useMemo)(() => (0, actions_factory_1.createActions)(dispatch), [dispatch]);
10
+ return { state, actions };
11
+ }
12
+ exports.useDataGridControl = useDataGridControl;
@@ -0,0 +1 @@
1
+ export * from "./use-data-grid-fetching";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./use-data-grid-fetching"), exports);
@@ -0,0 +1,16 @@
1
+ import { Loader } from "../types/core";
2
+ import { Schema } from "../types/schema";
3
+ import { DataGridControl } from "../use-data-grid-control";
4
+ interface Response<Row> {
5
+ result: Row[];
6
+ count: number;
7
+ totalCount: number;
8
+ }
9
+ export interface DataGridFetchingResult<Row> {
10
+ isLoading: boolean;
11
+ error?: any;
12
+ data: Response<Row> | null;
13
+ onReload: () => void;
14
+ }
15
+ export declare function useDataGridFetching(loader: Loader, schema: Schema<any>, gridName: string, state: DataGridControl["state"]): DataGridFetchingResult<any>;
16
+ export {};
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDataGridFetching = void 0;
4
+ const react_1 = require("react");
5
+ const utils_1 = require("../utils");
6
+ function useDataGridFetching(loader, schema, gridName, state) {
7
+ const [isLoading, setIsLoading] = (0, react_1.useState)(false);
8
+ const [error, setError] = (0, react_1.useState)(null);
9
+ const [data, setData] = (0, react_1.useState)(null);
10
+ const stringStateRequest = JSON.stringify(state.request);
11
+ const reload = (0, react_1.useCallback)(() => {
12
+ const stateRequest = JSON.parse(stringStateRequest);
13
+ const request = (0, utils_1.createRequest)(stateRequest, schema.sort, schema.dir);
14
+ loader(gridName, request, (0, utils_1.encodeFilter)(request))
15
+ .then((response) => {
16
+ setData(response);
17
+ setError(null);
18
+ setIsLoading(false);
19
+ })
20
+ .catch((e) => {
21
+ // eslint-disable-next-line no-console
22
+ console.error(e);
23
+ setIsLoading(false);
24
+ setError(e);
25
+ });
26
+ }, [stringStateRequest, schema.dir, schema.sort, loader, gridName]);
27
+ (0, react_1.useEffect)(() => {
28
+ reload();
29
+ }, [reload]);
30
+ return {
31
+ data,
32
+ isLoading,
33
+ error,
34
+ onReload: reload,
35
+ };
36
+ }
37
+ exports.useDataGridFetching = useDataGridFetching;
@@ -0,0 +1 @@
1
+ export declare const NO_BORDER_CLASS = "no-border";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NO_BORDER_CLASS = void 0;
4
+ exports.NO_BORDER_CLASS = "no-border";
package/utils.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { DataGridSortDir, DataGridState, Request } from "./types";
1
+ import { Request } from "./types/api";
2
+ import { DataGridSortDir } from "./types/schema";
3
+ import { GridRequest } from "./types/state";
2
4
  export declare function decodeFilter(filterString: string): null | Request;
3
5
  export declare function encodeFilter(request: Request): string;
4
- export declare function createRequest(state: DataGridState, defaultSort: string, defaultDir: DataGridSortDir): Request;
5
- export type ClassArray = ClassValue[];
6
- export type ClassValue = ClassArray | Record<string, any> | string | number | null | boolean | undefined;
7
- export declare function cx(...classes: ClassValue[]): string;
6
+ export declare function createRequest(request: GridRequest, defaultSort: string, defaultDir: DataGridSortDir): Request;
package/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cx = exports.createRequest = exports.encodeFilter = exports.decodeFilter = void 0;
3
+ exports.createRequest = exports.encodeFilter = exports.decodeFilter = void 0;
4
4
  function decodeFilter(filterString) {
5
5
  try {
6
6
  const filter = JSON.parse(decodeURIComponent(escape(atob(filterString))));
@@ -21,67 +21,16 @@ function encodeFilter(request) {
21
21
  return btoa(unescape(encodeURIComponent(JSON.stringify(request))));
22
22
  }
23
23
  exports.encodeFilter = encodeFilter;
24
- function createRequest(state, defaultSort, defaultDir) {
24
+ function createRequest(request, defaultSort, defaultDir) {
25
25
  var _a, _b;
26
26
  return {
27
- sort: (_a = state.request.sort) !== null && _a !== void 0 ? _a : defaultSort,
28
- dir: (_b = state.request.dir) !== null && _b !== void 0 ? _b : defaultDir,
29
- perPage: state.request.perPage,
30
- page: state.request.page,
31
- f: state.request.f.filter((f) => f.value !== undefined && f.value !== null && f.value !== ""),
32
- search: state.request.search,
33
- tab: state.request.tab,
27
+ sort: (_a = request.sort) !== null && _a !== void 0 ? _a : defaultSort,
28
+ dir: (_b = request.dir) !== null && _b !== void 0 ? _b : defaultDir,
29
+ perPage: request.perPage,
30
+ page: request.page,
31
+ f: request.f.filter((f) => f.value !== undefined && f.value !== null && f.value !== ""),
32
+ search: request.search,
33
+ tab: request.tab,
34
34
  };
35
35
  }
36
36
  exports.createRequest = createRequest;
37
- function toVal(mix) {
38
- let k;
39
- let y;
40
- let str = "";
41
- if (typeof mix === "string" || typeof mix === "number") {
42
- str += mix;
43
- }
44
- else if (typeof mix === "object") {
45
- if (Array.isArray(mix)) {
46
- for (k = 0; k < mix.length; k++) {
47
- if (mix[k]) {
48
- if ((y = toVal(mix[k]))) {
49
- if (str) {
50
- str += " ";
51
- }
52
- str += y;
53
- }
54
- }
55
- }
56
- }
57
- else {
58
- for (k in mix) {
59
- if (mix === null || mix === void 0 ? void 0 : mix[k]) {
60
- if (str) {
61
- str += " ";
62
- }
63
- str += k;
64
- }
65
- }
66
- }
67
- }
68
- return str;
69
- }
70
- function cx(...classes) {
71
- let i = 0;
72
- let tmp;
73
- let x;
74
- let str = "";
75
- while (i < classes.length) {
76
- if ((tmp = classes[i++])) {
77
- if ((x = toVal(tmp))) {
78
- if (str) {
79
- str += " ";
80
- }
81
- str += x;
82
- }
83
- }
84
- }
85
- return str;
86
- }
87
- exports.cx = cx;
@@ -1,3 +0,0 @@
1
- import { Column } from "react-data-grid";
2
- import { DataGridProps } from "../types";
3
- export declare const useColumns: (props: DataGridProps<any, any>, reload: () => Promise<void>) => Column<any>[];