@sonic-equipment/ui 190.0.0 → 191.0.0

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.
@@ -244,7 +244,7 @@ function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPa
244
244
  MA: t('industry.MA'),
245
245
  OT: t('industry.OT'),
246
246
  /* eslint-enable sort-keys-fix/sort-keys-fix */
247
- }, placeholder: t('Select an industry'), variant: "solid" }), jsx(TextField, { showLabel: true, isDisabled: isDisabled, label: t('VAT Number'), minLength: 8, name: "customerVatNumber" }, `vat${Boolean(validationErrors.customerVatNumber)}`), jsx(TextField, { showLabel: true, defaultValue: cart.poNumber, isDisabled: isDisabled, isRequired: cart.requiresPoNumber, label: t('PO Number'), name: "poNumber" }), paymentMethodOptions && Object.keys(paymentMethodOptions).length > 1 && (jsx(Select, { "data-test-selector": "paymentMethodSelect", defaultSelectedOption: cart.paymentOptions?.paymentMethods?.[0]?.name || 'ADY', isDisabled: isDisabled, label: t('Payment method'), name: "paymentMethod", onChange: setSelectedPaymentMethod, options: paymentMethodOptions, selectedOption: selectedPaymentMethod, variant: "solid" })), isAdyenPayment && cart.billTo && (jsx(AdyenPayment, { amount: cart.orderGrandTotal, cartId: cart.trackId, countryCode: countryCode, currencyCode: currencyCode, customerId: cart.billTo.id, dropinRef: dropinRef, environment: environment === 'production' ? 'live' : 'test', isDisabled: isDisabled, onComplete: onComplete, onError: onError, orderAmount: cart.orderGrandTotal, returnUrl:
247
+ }, placeholder: t('Select an industry'), variant: "solid" }), jsx(TextField, { showLabel: true, defaultValue: cart.customerVatNumber, isDisabled: isDisabled, label: t('VAT Number'), minLength: 8, name: "customerVatNumber" }, `vat${Boolean(validationErrors.customerVatNumber)}`), jsx(TextField, { showLabel: true, defaultValue: cart.poNumber, isDisabled: isDisabled, isRequired: cart.requiresPoNumber, label: t('PO Number'), name: "poNumber" }), paymentMethodOptions && Object.keys(paymentMethodOptions).length > 1 && (jsx(Select, { "data-test-selector": "paymentMethodSelect", defaultSelectedOption: cart.paymentOptions?.paymentMethods?.[0]?.name || 'ADY', isDisabled: isDisabled, label: t('Payment method'), name: "paymentMethod", onChange: setSelectedPaymentMethod, options: paymentMethodOptions, selectedOption: selectedPaymentMethod, variant: "solid" })), isAdyenPayment && cart.billTo && (jsx(AdyenPayment, { amount: cart.orderGrandTotal, cartId: cart.trackId, countryCode: countryCode, currencyCode: currencyCode, customerId: cart.billTo.id, dropinRef: dropinRef, environment: environment === 'production' ? 'live' : 'test', isDisabled: isDisabled, onComplete: onComplete, onError: onError, orderAmount: cart.orderGrandTotal, returnUrl:
248
248
  /* eslint-disable ssr-friendly/no-dom-globals-in-react-fc */
249
249
  typeof window === 'undefined'
250
250
  ? ''
@@ -64,7 +64,7 @@ function DataTable({ actions, columns: _columns, data, onSort: _onSort, }) {
64
64
  if (data.length === 0 || columns.length === 0)
65
65
  return null;
66
66
  if (isXl)
67
- return (jsx("div", { className: styles['data-table'], children: jsx(Table, { className: styles['content'], cssColumns: cssColumns, highlight: "col", stretch: true, thead: jsx(TR, { children: columns.map(column => (jsx(TH, { ...column.props, sortable: !!column.sort?.isEnabled, children: 'Icon' in column.header ? (jsx(column.header.Icon, { className: styles['th-icon'] })) : (!column.header.isHidden && (jsx(SortWrapper, { column: column, direction: sortInfo?.key === column.key ||
67
+ return (jsx("div", { className: styles['data-table'], children: jsx(Table, { className: styles['content'], cssColumns: cssColumns, highlight: "col", stretch: true, thead: jsx(TR, { children: columns.map(column => (jsx(TH, { scope: "col", ...column.props, sortable: !!column.sort?.isEnabled, children: 'Icon' in column.header ? (jsx(column.header.Icon, { className: styles['th-icon'] })) : (!column.header.isHidden && (jsx(SortWrapper, { column: column, direction: sortInfo?.key === column.key ||
68
68
  (column.sort?.isEnabled &&
69
69
  sortInfo?.key === column.sort.columnName)
70
70
  ? sortInfo?.direction
@@ -4,11 +4,14 @@ import { OnColumnChangedHandler } from './table-context';
4
4
  import { TableColumnProperties } from './types';
5
5
  export interface ColumnInfo {
6
6
  id: UUID;
7
+ index: number | null;
7
8
  props: TableColumnProperties;
8
9
  rowId: UUID;
9
10
  }
10
11
  export interface CellInfo {
12
+ columnId: UUID | null;
11
13
  id: UUID;
14
+ index: number | null;
12
15
  onColumnChanged: OnColumnChangedHandler;
13
16
  }
14
17
  export interface RowInfo {
@@ -13,9 +13,19 @@ function TableProvider({ children, onColumnsChanged, }) {
13
13
  cell: (rowId, onColumnChanged) => {
14
14
  const row = rowsRef.current.find(row => row.id === rowId);
15
15
  if (!row)
16
- return { deregister: voidFunction }; // throw new Error(`Row with id ${id} does not exist.`)
17
- const cell = { id: createUUID(), onColumnChanged };
18
- row.cells.push(cell);
16
+ return { deregister: voidFunction };
17
+ const cell = {
18
+ columnId: null,
19
+ id: createUUID(),
20
+ index: null,
21
+ onColumnChanged,
22
+ };
23
+ cell.index = row.cells.push(cell);
24
+ const columnInfo = columnsRef.current.find(column => column.index === cell.index);
25
+ if (!columnInfo)
26
+ throw new Error(`Column with index ${cell.index} does not exist.`);
27
+ cell.columnId = columnInfo.id;
28
+ onColumnChanged(columnInfo.props);
19
29
  return {
20
30
  deregister: () => {
21
31
  row.cells = row.cells.filter(c => c.id !== cell.id);
@@ -25,10 +35,11 @@ function TableProvider({ children, onColumnsChanged, }) {
25
35
  column: (rowId, props) => {
26
36
  const column = {
27
37
  id: createUUID(),
38
+ index: null,
28
39
  props,
29
40
  rowId,
30
41
  };
31
- columnsRef.current.push(column);
42
+ column.index = columnsRef.current.push(column);
32
43
  onColumnsChanged?.(columnsRef.current);
33
44
  return {
34
45
  deregister: () => {
@@ -36,13 +47,11 @@ function TableProvider({ children, onColumnsChanged, }) {
36
47
  onColumnsChanged?.(columnsRef.current);
37
48
  },
38
49
  update: (props) => {
39
- const updatedColumn = columnsRef.current.find(c => c.id === column.id);
40
- if (!updatedColumn)
41
- throw new Error(`Column with id ${column.id} does not exist.`);
42
- updatedColumn.props = props;
43
- rowsRef.current.forEach(row => row.cells
44
- .find(cell => cell.id === column.id)
45
- ?.onColumnChanged(props));
50
+ column.props = { ...column.props, ...props };
51
+ rowsRef.current.forEach(row => row.cells.forEach(cell => {
52
+ if (cell.columnId === column.id)
53
+ cell.onColumnChanged(props);
54
+ }));
46
55
  },
47
56
  };
48
57
  },
@@ -7,10 +7,10 @@ function useTD(props) {
7
7
  const onColumnChanged = useCallback((columnProps) => {
8
8
  setColumnProps(columnProps);
9
9
  }, []);
10
- const [{ deregister }] = useState(register.cell(onColumnChanged));
11
10
  useEffect(() => {
11
+ const { deregister } = register.cell(onColumnChanged);
12
12
  return deregister;
13
- }, [deregister]);
13
+ }, [onColumnChanged, register]);
14
14
  return {
15
15
  ...props,
16
16
  align: columnProps?.align ?? props.align ?? 'start',
@@ -1,21 +1,19 @@
1
- import { useRef, useEffect } from 'react';
1
+ import { useState, useEffect } from 'react';
2
2
  import { useTableRow } from './use-table-row.js';
3
3
 
4
4
  function useTH(props) {
5
5
  const { register } = useTableRow();
6
- const updateRef = useRef();
6
+ const [update, setUpdate] = useState(null);
7
7
  useEffect(() => {
8
8
  const { deregister, update } = register.column(props);
9
- updateRef.current = update;
10
- return () => {
11
- deregister();
12
- updateRef.current = undefined;
13
- };
9
+ // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
10
+ setUpdate(update);
11
+ return deregister;
14
12
  // eslint-disable-next-line react-hooks/exhaustive-deps
15
13
  }, [register]);
16
14
  useEffect(() => {
17
- updateRef.current?.(props);
18
- }, [props]);
15
+ update?.(props);
16
+ }, [update, props]);
19
17
  return props;
20
18
  }
21
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "190.0.0",
3
+ "version": "191.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {