@gisce/react-ooui 0.8.3 → 0.8.6

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 (29) hide show
  1. package/dist/helpers/treeHelper.d.ts +2 -1
  2. package/dist/helpers/treeHelper.d.ts.map +1 -1
  3. package/dist/helpers/treeHelper.js +16 -11
  4. package/dist/helpers/treeHelper.js.map +1 -1
  5. package/dist/index.js +4 -4
  6. package/dist/widgets/base/one2many/One2manyInput.d.ts.map +1 -1
  7. package/dist/widgets/base/one2many/One2manyInput.js +43 -41
  8. package/dist/widgets/base/one2many/One2manyInput.js.map +1 -1
  9. package/dist/widgets/base/one2many/One2manyTopBar.d.ts +2 -0
  10. package/dist/widgets/base/one2many/One2manyTopBar.d.ts.map +1 -1
  11. package/dist/widgets/base/one2many/One2manyTopBar.js +4 -4
  12. package/dist/widgets/base/one2many/One2manyTopBar.js.map +1 -1
  13. package/dist/widgets/views/Dashboard/DashboardTree.d.ts.map +1 -1
  14. package/dist/widgets/views/Dashboard/DashboardTree.js +2 -1
  15. package/dist/widgets/views/Dashboard/DashboardTree.js.map +1 -1
  16. package/dist/widgets/views/SearchTree.d.ts.map +1 -1
  17. package/dist/widgets/views/SearchTree.js +2 -1
  18. package/dist/widgets/views/SearchTree.js.map +1 -1
  19. package/dist/widgets/views/Tree.d.ts +1 -1
  20. package/dist/widgets/views/Tree.d.ts.map +1 -1
  21. package/dist/widgets/views/Tree.js +4 -11
  22. package/dist/widgets/views/Tree.js.map +1 -1
  23. package/package.json +2 -2
  24. package/src/helpers/treeHelper.ts +18 -13
  25. package/src/widgets/base/one2many/One2manyInput.tsx +30 -32
  26. package/src/widgets/base/one2many/One2manyTopBar.tsx +13 -7
  27. package/src/widgets/views/Dashboard/DashboardTree.tsx +2 -1
  28. package/src/widgets/views/SearchTree.tsx +2 -1
  29. package/src/widgets/views/Tree.tsx +5 -12
@@ -26,7 +26,7 @@ import { readObjectValues, getNextPendingId } from "@/helpers/one2manyHelper";
26
26
  import { SearchModal } from "@/widgets/modals/SearchModal";
27
27
  import { LocaleContext, LocaleContextType } from "@/context/LocaleContext";
28
28
  import { ViewModes } from "@/widgets/base/one2many/One2many";
29
- import { sortResults } from "@/helpers/treeHelper";
29
+ import { sortResults, sortResultsWithOrder } from "@/helpers/treeHelper";
30
30
 
31
31
  type One2manyValue = {
32
32
  fields?: any;
@@ -95,6 +95,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
95
95
  );
96
96
  const transformedDomain = useRef<any[]>([]);
97
97
  const [sorter, setSorter] = useState<any>();
98
+ const originalSortItemIds = useRef<number[]>();
98
99
 
99
100
  const {
100
101
  readOnly,
@@ -108,14 +109,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
108
109
  (item) => item.values && item.operation !== "pendingRemove"
109
110
  );
110
111
 
111
- const noFieldsTree = views.get("tree")?.fields === undefined;
112
- const noFieldsForm = views.get("form")?.fields === undefined;
113
-
114
112
  useEffect(() => {
115
- if (noFieldsForm || noFieldsTree) {
116
- return;
117
- }
118
-
119
113
  if (items.some((item) => !item.values)) {
120
114
  fetchData();
121
115
  }
@@ -127,7 +121,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
127
121
 
128
122
  const triggerChange = (changedValue: Array<One2manyItem>) => {
129
123
  onChange?.({
130
- fields: views.get("form").fields,
124
+ fields: views.get("form")?.fields || views.get("tree")?.fields,
131
125
  items: filterDuplicateItems(changedValue),
132
126
  });
133
127
  };
@@ -147,12 +141,16 @@ const One2manyInput: React.FC<One2manyInputProps> = (
147
141
  try {
148
142
  const itemsWithValues = await readObjectValues({
149
143
  treeFields: views.get("tree").fields,
150
- formFields: views.get("form").fields,
144
+ formFields: views.get("form")?.fields || {},
151
145
  model: relation,
152
146
  items,
153
147
  context: { ...getContext?.(), ...context },
154
148
  });
155
149
 
150
+ if (!originalSortItemIds.current) {
151
+ originalSortItemIds.current = itemsWithValues.map((item) => item.id!);
152
+ }
153
+
156
154
  triggerChange(itemsWithValues);
157
155
  } catch (err) {
158
156
  setError(err as any);
@@ -438,7 +436,8 @@ const One2manyInput: React.FC<One2manyInputProps> = (
438
436
  }
439
437
  };
440
438
 
441
- const onTreeRowClicked = (itemId: number) => {
439
+ const onTreeRowClicked = (record: any) => {
440
+ const { id: itemId } = record;
442
441
  // We show the detail for the clicked item in a Form modal
443
442
  setModalItem(items.find((item) => item.id === itemId));
444
443
  setContinuousEntryMode(false);
@@ -544,14 +543,19 @@ const One2manyInput: React.FC<One2manyInputProps> = (
544
543
  );
545
544
  }
546
545
 
547
- const resultsToShow = sortResults({
548
- resultsToSort: itemsToShow.map((item) => item.treeValues),
549
- sorter,
550
- fields: {
551
- ...views.get("tree").fields,
552
- ...views.get("form").fields,
553
- },
554
- });
546
+ const resultsToShow = sorter
547
+ ? sortResults({
548
+ resultsToSort: itemsToShow.map((item) => item.treeValues),
549
+ sorter,
550
+ fields: {
551
+ ...views.get("tree").fields,
552
+ ...(views.get("form")?.fields || {}),
553
+ },
554
+ })
555
+ : sortResultsWithOrder(
556
+ itemsToShow.map((item) => item.treeValues),
557
+ originalSortItemIds.current!
558
+ );
555
559
 
556
560
  if (currentView === "tree") {
557
561
  return (
@@ -561,7 +565,11 @@ const One2manyInput: React.FC<One2manyInputProps> = (
561
565
  treeView={views.get("tree")}
562
566
  results={resultsToShow}
563
567
  loading={isLoading}
564
- onRowClicked={onTreeRowClicked}
568
+ onRowClicked={
569
+ views.get("form")?.fields !== undefined
570
+ ? onTreeRowClicked
571
+ : undefined
572
+ }
565
573
  showPagination={false}
566
574
  rowSelection={{
567
575
  selectedRowKeys,
@@ -590,18 +598,6 @@ const One2manyInput: React.FC<One2manyInputProps> = (
590
598
  return <Alert className="mt-10" message={error} type="error" banner />;
591
599
  }
592
600
 
593
- if (noFieldsForm || noFieldsTree) {
594
- const mode = noFieldsTree ? "tree" : "form";
595
- return (
596
- <Alert
597
- className="mt-10"
598
- message={`No fields in ${mode} view for model ${relation}`}
599
- type="error"
600
- banner
601
- />
602
- );
603
- }
604
-
605
601
  // If we are in create mode we have to show the modal in continuous mode.
606
602
  // This means the modal won't close after clicking OK, the modal will add the new item
607
603
  // and will reset to defaults to let the user add a new item.
@@ -628,6 +624,8 @@ const One2manyInput: React.FC<One2manyInputProps> = (
628
624
  onNextItem={nextItem}
629
625
  onSearchItem={searchItem}
630
626
  selectedRowKeys={selectedRowKeys}
627
+ showCreateButton={views.get("form")?.fields !== undefined}
628
+ showToggleButton={views.size > 1}
631
629
  />
632
630
  {content()}
633
631
  <FormModal
@@ -27,6 +27,8 @@ type One2manyTopBarProps = {
27
27
  onNextItem: () => void;
28
28
  onSearchItem: () => void;
29
29
  selectedRowKeys: string[];
30
+ showToggleButton: boolean;
31
+ showCreateButton: boolean;
30
32
  };
31
33
 
32
34
  export const One2manyTopBar = (props: One2manyTopBarProps) => {
@@ -44,6 +46,8 @@ export const One2manyTopBar = (props: One2manyTopBarProps) => {
44
46
  isMany2Many,
45
47
  onSearchItem,
46
48
  selectedRowKeys,
49
+ showCreateButton,
50
+ showToggleButton,
47
51
  } = props;
48
52
 
49
53
  function separator() {
@@ -112,7 +116,7 @@ export const One2manyTopBar = (props: One2manyTopBarProps) => {
112
116
  <div className="flex mb-2">
113
117
  {title()}
114
118
  <div className="h-8 flex-none pl-2">
115
- {mode !== "graph" && (
119
+ {mode !== "graph" && showCreateButton && (
116
120
  <ButtonWithTooltip
117
121
  tooltip={"Create new item"}
118
122
  icon={<FileAddOutlined />}
@@ -120,7 +124,7 @@ export const One2manyTopBar = (props: One2manyTopBarProps) => {
120
124
  onClick={onCreateItem}
121
125
  />
122
126
  )}
123
- {isMany2Many && (
127
+ {isMany2Many && showCreateButton && (
124
128
  <ButtonWithTooltip
125
129
  tooltip={"Search existing item"}
126
130
  icon={<SearchOutlined />}
@@ -132,11 +136,13 @@ export const One2manyTopBar = (props: One2manyTopBarProps) => {
132
136
  {mode !== "graph" && deleteButton()}
133
137
  {mode === "form" && itemBrowser()}
134
138
  {separator()}
135
- <ButtonWithTooltip
136
- tooltip={"Toggle view mode"}
137
- icon={<AlignLeftOutlined />}
138
- onClick={onToggleViewMode}
139
- />
139
+ {showToggleButton && (
140
+ <ButtonWithTooltip
141
+ tooltip={"Toggle view mode"}
142
+ icon={<AlignLeftOutlined />}
143
+ onClick={onToggleViewMode}
144
+ />
145
+ )}
140
146
  </div>
141
147
  </div>
142
148
  );
@@ -208,7 +208,8 @@ function DashboardTree(props: Props) {
208
208
  }
209
209
  }, [action, model]);
210
210
 
211
- const onRowClickedHandler = (id: number) => {
211
+ const onRowClickedHandler = (record: any) => {
212
+ const { id } = record;
212
213
  onRowClicked({
213
214
  id,
214
215
  model: currentModel!,
@@ -430,7 +430,8 @@ function SearchTree(props: Props, ref: any) {
430
430
  internalLimit.current = newLimit;
431
431
  };
432
432
 
433
- const onRowClickedHandler = (id: number) => {
433
+ const onRowClickedHandler = (record: any) => {
434
+ const { id } = record;
434
435
  onRowClicked({
435
436
  id,
436
437
  model: currentModel!,
@@ -21,7 +21,7 @@ type Props = {
21
21
  results: Array<any>;
22
22
  showPagination?: boolean;
23
23
  onRequestPageChange?: (page: number, pageSize?: number) => void;
24
- onRowClicked?: (id: number) => void;
24
+ onRowClicked?: (record: any) => void;
25
25
  rowSelection?: any;
26
26
  scrollY?: number;
27
27
  colorsForResults?: { [key: number]: string };
@@ -234,20 +234,13 @@ function Tree(props: Props): React.ReactElement {
234
234
  dataSource={items}
235
235
  loading={loading}
236
236
  loadingComponent={<Spin />}
237
- onRow={(record: any) => {
238
- let style = undefined;
239
-
237
+ onRowStyle={(record: any) => {
240
238
  if (colorsForResults![record.id]) {
241
- style = { color: colorsForResults![record.id] };
239
+ return { color: colorsForResults![record.id] };
242
240
  }
243
-
244
- return {
245
- style,
246
- onDoubleClick: () => {
247
- if (onRowClicked) onRowClicked(record.id);
248
- },
249
- };
241
+ return undefined;
250
242
  }}
243
+ onRowDoubleClick={onRowClicked}
251
244
  onRowSelectionChange={rowSelection?.onChange}
252
245
  onChangeSort={onChangeSort}
253
246
  sorter={sorter}