@abgov/jsonforms-components 2.6.8 → 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
  })
@@ -9975,8 +9975,8 @@ const ObjectArrayList = ({
9975
9975
  enabled,
9976
9976
  cells,
9977
9977
  translations,
9978
- currentTab,
9979
- setCurrentTab
9978
+ currentIndex,
9979
+ setCurrentIndex
9980
9980
  }) => {
9981
9981
  const isEmptyList = data === 0;
9982
9982
  const rightRef = useRef(null);
@@ -10005,7 +10005,7 @@ const ObjectArrayList = ({
10005
10005
  }
10006
10006
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
10007
10007
  const selectCurrentTab = index => {
10008
- setCurrentTab(index);
10008
+ setCurrentIndex(index);
10009
10009
  };
10010
10010
  const paddedHeight = rightHeight && rightHeight + 48;
10011
10011
  return jsx(ListContainer, {
@@ -10020,7 +10020,7 @@ const ObjectArrayList = ({
10020
10020
  return jsx(LeftTab, {
10021
10021
  childPath: childPath,
10022
10022
  rowIndex: index,
10023
- currentTab: currentTab,
10023
+ currentTab: currentIndex,
10024
10024
  name: name,
10025
10025
  openDeleteDialog: openDeleteDialog,
10026
10026
  selectCurrentTab: selectCurrentTab,
@@ -10031,8 +10031,8 @@ const ObjectArrayList = ({
10031
10031
  }), jsx(FlexForm, {
10032
10032
  ref: rightRef,
10033
10033
  children: jsx(NonEmptyList, {
10034
- childPath: Paths.compose(path, `${currentTab}`),
10035
- rowIndex: currentTab,
10034
+ childPath: Paths.compose(path, `${currentIndex}`),
10035
+ rowIndex: currentIndex,
10036
10036
  schema: schema,
10037
10037
  openDeleteDialog: openDeleteDialog,
10038
10038
  showSortButtons: appliedUiSchemaOptions.showSortButtons || appliedUiSchemaOptions.showArrayTableSortButtons,
@@ -10041,7 +10041,7 @@ const ObjectArrayList = ({
10041
10041
  path: path,
10042
10042
  uischema: uischema,
10043
10043
  translations: translations
10044
- }, Paths.compose(path, `${currentTab}`))
10044
+ }, Paths.compose(path, `${currentIndex}`))
10045
10045
  })]
10046
10046
  })
10047
10047
  });
@@ -10052,16 +10052,19 @@ class ListWithDetailControl extends React.Component {
10052
10052
  super(...arguments);
10053
10053
  // eslint-disable-next-line
10054
10054
  this.addItem = (path, value) => {
10055
- const pathIdValue = (path === null || path === void 0 ? void 0 : path.split('.')) || '';
10056
- if (pathIdValue.length > 1 && +this.props.data >= 0 || pathIdValue.length === 1) {
10057
- this.props.addItem(path, value)();
10058
- this.setState({
10059
- currentTab: this.props.data + 1
10060
- });
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);
10061
10067
  }
10062
- };
10063
- this.state = {
10064
- currentTab: 0
10065
10068
  };
10066
10069
  }
10067
10070
  render() {
@@ -10119,10 +10122,8 @@ class ListWithDetailControl extends React.Component {
10119
10122
  data: data,
10120
10123
  cells: cells,
10121
10124
  config: config,
10122
- currentTab: this.state.currentTab,
10123
- setCurrentTab: i => this.setState({
10124
- currentTab: i
10125
- })
10125
+ currentIndex: this.props.currentTab,
10126
+ setCurrentIndex: this.props.setCurrentTab
10126
10127
  }, additionalProps))
10127
10128
  })]
10128
10129
  });
@@ -10139,6 +10140,7 @@ const ListWithDetailsControl = props => {
10139
10140
  visible,
10140
10141
  handleChange
10141
10142
  } = props;
10143
+ const [currentTab, setCurrentTab] = useState(0);
10142
10144
  const openDeleteDialog = useCallback((p, rowIndex, name) => {
10143
10145
  setOpen(true);
10144
10146
  setPath(p);
@@ -10152,18 +10154,22 @@ const ListWithDetailsControl = props => {
10152
10154
  if (removeItems && p) {
10153
10155
  if (props.data === 1) {
10154
10156
  handleChange(p, null);
10157
+ setCurrentTab(0);
10155
10158
  } else {
10156
10159
  removeItems(p, [rowData])();
10160
+ setCurrentTab(prev => Math.max(0, rowData - 1)); // Safe fallback
10157
10161
  }
10158
10162
  }
10159
10163
  setOpen(false);
10160
10164
  // eslint-disable-next-line
10161
- }, [setOpen, path, rowData]);
10165
+ }, [setOpen, path, rowData, rowData]);
10162
10166
  return jsxs(Visible, {
10163
10167
  visible: visible,
10164
10168
  children: [jsx(ListWithDetailControl, Object.assign({}, props, {
10165
10169
  openDeleteDialog: openDeleteDialog,
10166
- enabled: true
10170
+ enabled: true,
10171
+ currentTab: currentTab,
10172
+ setCurrentTab: setCurrentTab
10167
10173
  })), jsx(DeleteDialog, {
10168
10174
  open: open,
10169
10175
  onCancel: deleteCancel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "2.6.8",
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,11 +32,12 @@ 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
- state: {
38
- currentTab: number;
39
- };
40
41
  render(): import("react/jsx-runtime").JSX.Element;
41
42
  }
42
43
  export {};