@gisce/react-ooui 0.8.4 → 0.8.7

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.
@@ -109,14 +109,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
109
109
  (item) => item.values && item.operation !== "pendingRemove"
110
110
  );
111
111
 
112
- const noFieldsTree = views.get("tree")?.fields === undefined;
113
- const noFieldsForm = views.get("form")?.fields === undefined;
114
-
115
112
  useEffect(() => {
116
- if (noFieldsForm || noFieldsTree) {
117
- return;
118
- }
119
-
120
113
  if (items.some((item) => !item.values)) {
121
114
  fetchData();
122
115
  }
@@ -128,7 +121,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
128
121
 
129
122
  const triggerChange = (changedValue: Array<One2manyItem>) => {
130
123
  onChange?.({
131
- fields: views.get("form").fields,
124
+ fields: views.get("form")?.fields || views.get("tree")?.fields,
132
125
  items: filterDuplicateItems(changedValue),
133
126
  });
134
127
  };
@@ -148,7 +141,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
148
141
  try {
149
142
  const itemsWithValues = await readObjectValues({
150
143
  treeFields: views.get("tree").fields,
151
- formFields: views.get("form").fields,
144
+ formFields: views.get("form")?.fields || {},
152
145
  model: relation,
153
146
  items,
154
147
  context: { ...getContext?.(), ...context },
@@ -443,7 +436,8 @@ const One2manyInput: React.FC<One2manyInputProps> = (
443
436
  }
444
437
  };
445
438
 
446
- const onTreeRowClicked = (itemId: number) => {
439
+ const onTreeRowClicked = (record: any) => {
440
+ const { id: itemId } = record;
447
441
  // We show the detail for the clicked item in a Form modal
448
442
  setModalItem(items.find((item) => item.id === itemId));
449
443
  setContinuousEntryMode(false);
@@ -555,7 +549,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
555
549
  sorter,
556
550
  fields: {
557
551
  ...views.get("tree").fields,
558
- ...views.get("form").fields,
552
+ ...(views.get("form")?.fields || {}),
559
553
  },
560
554
  })
561
555
  : sortResultsWithOrder(
@@ -571,7 +565,11 @@ const One2manyInput: React.FC<One2manyInputProps> = (
571
565
  treeView={views.get("tree")}
572
566
  results={resultsToShow}
573
567
  loading={isLoading}
574
- onRowClicked={onTreeRowClicked}
568
+ onRowClicked={
569
+ views.get("form")?.fields !== undefined
570
+ ? onTreeRowClicked
571
+ : undefined
572
+ }
575
573
  showPagination={false}
576
574
  rowSelection={{
577
575
  selectedRowKeys,
@@ -600,18 +598,6 @@ const One2manyInput: React.FC<One2manyInputProps> = (
600
598
  return <Alert className="mt-10" message={error} type="error" banner />;
601
599
  }
602
600
 
603
- if (noFieldsForm || noFieldsTree) {
604
- const mode = noFieldsTree ? "tree" : "form";
605
- return (
606
- <Alert
607
- className="mt-10"
608
- message={`No fields in ${mode} view for model ${relation}`}
609
- type="error"
610
- banner
611
- />
612
- );
613
- }
614
-
615
601
  // If we are in create mode we have to show the modal in continuous mode.
616
602
  // This means the modal won't close after clicking OK, the modal will add the new item
617
603
  // and will reset to defaults to let the user add a new item.
@@ -638,6 +624,8 @@ const One2manyInput: React.FC<One2manyInputProps> = (
638
624
  onNextItem={nextItem}
639
625
  onSearchItem={searchItem}
640
626
  selectedRowKeys={selectedRowKeys}
627
+ showCreateButton={views.get("form")?.fields !== undefined}
628
+ showToggleButton={views.size > 1}
641
629
  />
642
630
  {content()}
643
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}