@abgov/jsonforms-components 2.6.7 → 2.6.9

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/index.esm.js CHANGED
@@ -6617,7 +6617,7 @@ const CheckboxGroup = props => {
6617
6617
  } else {
6618
6618
  newData = newData.filter(item => item !== enumValue);
6619
6619
  }
6620
- handleChange(path, newData);
6620
+ handleChange(path, newData.length === 0 ? undefined : newData);
6621
6621
  }
6622
6622
  }));
6623
6623
  })
@@ -9974,14 +9974,15 @@ const ObjectArrayList = ({
9974
9974
  config,
9975
9975
  enabled,
9976
9976
  cells,
9977
- translations
9977
+ translations,
9978
+ currentIndex,
9979
+ setCurrentIndex
9978
9980
  }) => {
9979
9981
  const isEmptyList = data === 0;
9980
9982
  const rightRef = useRef(null);
9981
9983
  const current = rightRef.current;
9982
9984
  const minHeight = 300;
9983
9985
  const [rightHeight, setRightHeight] = useState(minHeight);
9984
- const [currentTab, setCurrentTab] = useState(0);
9985
9986
  useEffect(() => {
9986
9987
  const resizeObserver = new ResizeObserver(() => {
9987
9988
  if (rightHeight !== (current === null || current === void 0 ? void 0 : current.offsetHeight) && (current === null || current === void 0 ? void 0 : current.offsetHeight)) setRightHeight((current === null || current === void 0 ? void 0 : current.offsetHeight) > minHeight ? current === null || current === void 0 ? void 0 : current.offsetHeight : minHeight);
@@ -10004,7 +10005,7 @@ const ObjectArrayList = ({
10004
10005
  }
10005
10006
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
10006
10007
  const selectCurrentTab = index => {
10007
- setCurrentTab(index);
10008
+ setCurrentIndex(index);
10008
10009
  };
10009
10010
  const paddedHeight = rightHeight && rightHeight + 48;
10010
10011
  return jsx(ListContainer, {
@@ -10019,7 +10020,7 @@ const ObjectArrayList = ({
10019
10020
  return jsx(LeftTab, {
10020
10021
  childPath: childPath,
10021
10022
  rowIndex: index,
10022
- currentTab: currentTab,
10023
+ currentTab: currentIndex,
10023
10024
  name: name,
10024
10025
  openDeleteDialog: openDeleteDialog,
10025
10026
  selectCurrentTab: selectCurrentTab,
@@ -10030,8 +10031,8 @@ const ObjectArrayList = ({
10030
10031
  }), jsx(FlexForm, {
10031
10032
  ref: rightRef,
10032
10033
  children: jsx(NonEmptyList, {
10033
- childPath: Paths.compose(path, `${currentTab}`),
10034
- rowIndex: currentTab,
10034
+ childPath: Paths.compose(path, `${currentIndex}`),
10035
+ rowIndex: currentIndex,
10035
10036
  schema: schema,
10036
10037
  openDeleteDialog: openDeleteDialog,
10037
10038
  showSortButtons: appliedUiSchemaOptions.showSortButtons || appliedUiSchemaOptions.showArrayTableSortButtons,
@@ -10040,7 +10041,7 @@ const ObjectArrayList = ({
10040
10041
  path: path,
10041
10042
  uischema: uischema,
10042
10043
  translations: translations
10043
- }, Paths.compose(path, `${currentTab}`))
10044
+ }, Paths.compose(path, `${currentIndex}`))
10044
10045
  })]
10045
10046
  })
10046
10047
  });
@@ -10051,9 +10052,18 @@ class ListWithDetailControl extends React.Component {
10051
10052
  super(...arguments);
10052
10053
  // eslint-disable-next-line
10053
10054
  this.addItem = (path, value) => {
10054
- const pathIdValue = (path === null || path === void 0 ? void 0 : path.split('.')) || '';
10055
- if (pathIdValue.length > 1 && +this.props.data >= 0 || pathIdValue.length === 1) {
10056
- this.props.addItem(path, value)();
10055
+ const {
10056
+ data,
10057
+ addItem,
10058
+ setCurrentTab
10059
+ } = this.props;
10060
+ const isNonEmpty = data !== undefined && data !== null;
10061
+ const newIndex = isNonEmpty ? data !== null && data !== void 0 ? data : 0 : 0;
10062
+ if (addItem) {
10063
+ addItem(path, value)();
10064
+ }
10065
+ if (typeof setCurrentTab === 'function') {
10066
+ setCurrentTab(newIndex);
10057
10067
  }
10058
10068
  };
10059
10069
  }
@@ -10111,7 +10121,9 @@ class ListWithDetailControl extends React.Component {
10111
10121
  translations: translations,
10112
10122
  data: data,
10113
10123
  cells: cells,
10114
- config: config
10124
+ config: config,
10125
+ currentIndex: this.props.currentTab,
10126
+ setCurrentIndex: this.props.setCurrentTab
10115
10127
  }, additionalProps))
10116
10128
  })]
10117
10129
  });
@@ -10128,6 +10140,7 @@ const ListWithDetailsControl = props => {
10128
10140
  visible,
10129
10141
  handleChange
10130
10142
  } = props;
10143
+ const [currentTab, setCurrentTab] = useState(0);
10131
10144
  const openDeleteDialog = useCallback((p, rowIndex, name) => {
10132
10145
  setOpen(true);
10133
10146
  setPath(p);
@@ -10141,18 +10154,22 @@ const ListWithDetailsControl = props => {
10141
10154
  if (removeItems && p) {
10142
10155
  if (props.data === 1) {
10143
10156
  handleChange(p, null);
10157
+ setCurrentTab(0);
10144
10158
  } else {
10145
10159
  removeItems(p, [rowData])();
10160
+ setCurrentTab(prev => Math.max(0, rowData - 1)); // Safe fallback
10146
10161
  }
10147
10162
  }
10148
10163
  setOpen(false);
10149
10164
  // eslint-disable-next-line
10150
- }, [setOpen, path, rowData]);
10165
+ }, [setOpen, path, rowData, rowData]);
10151
10166
  return jsxs(Visible, {
10152
10167
  visible: visible,
10153
10168
  children: [jsx(ListWithDetailControl, Object.assign({}, props, {
10154
10169
  openDeleteDialog: openDeleteDialog,
10155
- enabled: true
10170
+ enabled: true,
10171
+ currentTab: currentTab,
10172
+ setCurrentTab: setCurrentTab
10156
10173
  })), jsx(DeleteDialog, {
10157
10174
  open: open,
10158
10175
  onCancel: deleteCancel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "2.6.7",
3
+ "version": "2.6.9",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Government of Alberta - React renderers for JSON Forms based on the design system.",
6
6
  "repository": "https://github.com/GovAlta/adsp-monorepo",
@@ -32,7 +32,11 @@ interface NonEmptyRowProps {
32
32
  uischema: ControlElement;
33
33
  }
34
34
  export declare const NonEmptyList: React.MemoExoticComponent<({ childPath, schema, enabled, cells, uischema, }: NonEmptyRowProps & WithDeleteDialogSupport) => import("react/jsx-runtime").JSX.Element>;
35
- export declare class ListWithDetailControl extends React.Component<ObjectArrayControlProps, any> {
35
+ interface ListWithDetailControlProps extends ObjectArrayControlProps {
36
+ currentTab: number;
37
+ setCurrentTab: (index: number) => void;
38
+ }
39
+ export declare class ListWithDetailControl extends React.Component<ListWithDetailControlProps, any> {
36
40
  addItem: (path: string, value: any) => void;
37
41
  render(): import("react/jsx-runtime").JSX.Element;
38
42
  }