@sonic-equipment/ui 205.0.0 → 207.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.
@@ -4,9 +4,12 @@ export interface TableCardProps {
4
4
  children?: React.ReactNode;
5
5
  className?: string;
6
6
  'data-test-selector'?: string;
7
+ id?: string;
8
+ isLoading?: boolean;
7
9
  paging?: React.ReactNode;
10
+ results?: number;
8
11
  showError?: Error | TranslationId | boolean | null;
9
12
  stickyHeader?: boolean;
10
13
  title?: TranslationId;
11
14
  }
12
- export declare function TableCard({ actions, children, className, 'data-test-selector': dataTestSelector, paging, showError, stickyHeader, title, }: TableCardProps): import("react/jsx-runtime").JSX.Element;
15
+ export declare function TableCard({ actions, children, className, 'data-test-selector': dataTestSelector, id, isLoading, paging, results, showError, stickyHeader, title, }: TableCardProps): import("react/jsx-runtime").JSX.Element;
@@ -5,10 +5,8 @@ import { UnauthorizedRequestError } from '../../shared/fetch/request.js';
5
5
  import { Heading } from '../../typography/heading/heading.js';
6
6
  import styles from './table-card.module.css.js';
7
7
 
8
- function TableCard({ actions, children, className, 'data-test-selector': dataTestSelector,
9
- // rendering,
10
- paging, showError = false, stickyHeader = false, title, }) {
11
- return (jsxs("section", { className: clsx(styles['table-card-container'], stickyHeader && styles['sticky-header'], className), "data-test-selector": dataTestSelector, children: [title && (jsx(Heading, { className: styles.title, size: "xxs", tag: "h3", children: jsx(FormattedMessage, { id: title }) })), jsx("div", { className: styles['table-card'], children: showError ? (jsx("div", { className: styles['error-container'], children: showError instanceof UnauthorizedRequestError ? (jsx(FormattedMessage, { id: "You are not authorized to access this information." })) : typeof showError === 'string' ? (jsx(FormattedMessage, { id: showError })) : (jsx(FormattedMessage, { id: "An unexpected error occured" })) })) : children ? (jsxs(Fragment, { children: [Boolean(actions?.length) && (jsx("div", { className: styles['actions'], children: actions })), jsx("div", { className: styles['data'], children: children }), paging && jsx("div", { className: styles['paging'], children: paging })] })) : (jsx("div", { className: clsx(styles['no-data-container']), children: jsx(FormattedMessage, { id: "There is no information to display" }) })) }), jsx("div", { className: styles['sticky-bar'], role: "presentation" })] }));
8
+ function TableCard({ actions, children, className, 'data-test-selector': dataTestSelector, id, isLoading, paging, results = 0, showError = false, stickyHeader = false, title, }) {
9
+ return (jsxs("section", { className: clsx(styles['table-card-container'], stickyHeader && styles['sticky-header'], className), "data-test-selector": dataTestSelector, id: id, children: [title && (jsx(Heading, { className: styles.title, size: "xxs", tag: "h3", children: jsx(FormattedMessage, { id: title }) })), jsx("div", { className: styles['table-card'], children: showError ? (jsx("div", { className: styles['error-container'], children: showError instanceof UnauthorizedRequestError ? (jsx(FormattedMessage, { id: "You are not authorized to access this information." })) : typeof showError === 'string' ? (jsx(FormattedMessage, { id: showError })) : (jsx(FormattedMessage, { id: "An unexpected error occured" })) })) : (jsxs(Fragment, { children: [Boolean(actions?.length) && (jsx("div", { className: styles['actions'], children: actions })), results === 0 && !isLoading && (jsx("div", { className: clsx(styles['no-data-container']), children: jsx(FormattedMessage, { id: "There is no information to display" }) })), jsx("div", { className: styles['data'], children: children }), paging && jsx("div", { className: styles['paging'], children: paging })] })) }), jsx("div", { className: styles['sticky-bar'], role: "presentation" })] }));
12
10
  }
13
11
 
14
12
  export { TableCard };
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
- import { useState, useRef } from 'react';
3
+ import { useState, useRef, useEffect } from 'react';
4
4
  import clsx from 'clsx';
5
5
  import { useIntersectionObserver } from '../shared/hooks/use-intersection-observer.js';
6
6
  import { ProgressCircle } from './progress-circle.js';
@@ -21,6 +21,12 @@ function DynamicLoadingOverlay({ children, className, isLoading, }) {
21
21
  },
22
22
  threshold,
23
23
  });
24
+ useEffect(() => {
25
+ if (!isLoading) {
26
+ // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
27
+ setIntersectedHeight(0);
28
+ }
29
+ }, [isLoading]);
24
30
  return (jsxs("div", { ref: container, className: clsx(styles['dynamic-loading-overlay'], isLoading && styles['is-loading'], className), style: { '--intersected-height': `${intersectedHeight}px` }, children: [jsx("div", { className: styles['content'], children: children }), jsx("div", { className: styles['loading-indicator'], children: jsx(ProgressCircle, { className: styles['spinner'], variant: "gray" }) })] }));
25
31
  }
26
32
 
@@ -18,15 +18,17 @@ import styles from './connected-address-book-widget.module.css.js';
18
18
 
19
19
  function ConnectedAddressBookWidget() {
20
20
  const t = useFormattedMessage();
21
+ const { pathname, search: searchParams } = useLocation();
22
+ const href = `${pathname}${searchParams}`;
23
+ const paths = usePaths();
24
+ const addressBookId = 'address-book';
21
25
  const [sort, setSort] = useState({
22
26
  name: 'companyName',
23
- order: 'DESC',
27
+ order: 'ASC',
24
28
  });
25
29
  const [search, setSearch] = useState('');
26
30
  const [page, setPage] = useState(1);
27
31
  const addressBookRef = useRef(null);
28
- const { href } = useLocation();
29
- const paths = usePaths();
30
32
  const { data, error, isFetching } = useFetchPagedShipToAddresses({
31
33
  page,
32
34
  pageSize: 20,
@@ -48,11 +50,11 @@ function ConnectedAddressBookWidget() {
48
50
  };
49
51
  return (jsx(TableCard, { stickyHeader: true, actions: [
50
52
  jsx(SearchField, { isDebounced: true, className: styles['search-field'], label: t('Search'), onChange: searchAddresses, placeholder: t('Search'), showLabel: false, size: "md", variant: "outline" }, "searchAddresses"),
51
- jsx(Button, { color: "secondary", href: `${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/current${paths.ACCOUNT_EDIT_SHIP_TO_ADDRESS}/new?returnUrl=${encodeURIComponent(href)}`, size: "sm", variant: "outline", children: t('Add address') }, "addAddress"),
52
- ], className: styles['address-book-widget'], "data-test-selector": "address-book-widget", paging: addresses &&
53
- addresses.length > 0 && (jsx("nav", { className: styles['paging'], children: jsx(Pagination, { currentPage: pagination?.currentPage || 1, onChange: page => setPage(page), totalPages: pagination?.numberOfPages || 1 }) })), showError: error, title: "Address book", children: jsx("div", { ref: addressBookRef, "aria-label": "Results", "aria-live": "polite", className: styles['results'], children: jsx(DynamicLoadingOverlay, { isLoading: isFetching, children: addresses && addresses.length > 0 && (jsx(DataTable, { actions: [
53
+ jsx(Button, { color: "secondary", href: `${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/current${paths.ACCOUNT_EDIT_SHIP_TO_ADDRESS}/new?returnUrl=${encodeURIComponent(`${href}#${addressBookId}`)}`, size: "sm", variant: "outline", children: t('Add address') }, "addAddress"),
54
+ ], className: styles['address-book-widget'], "data-test-selector": "address-book-widget", id: addressBookId, isLoading: isFetching, paging: addresses &&
55
+ addresses.length > 0 && (jsx("nav", { className: styles['paging'], children: jsx(Pagination, { currentPage: pagination?.currentPage || 1, onChange: page => setPage(page), totalPages: pagination?.numberOfPages || 1 }) })), results: addresses ? addresses.length : 0, showError: error, title: "Address book", children: jsx("div", { ref: addressBookRef, "aria-label": "Results", "aria-live": "polite", className: styles['results'], children: jsx(DynamicLoadingOverlay, { isLoading: isFetching, children: jsx(DataTable, { actions: [
54
56
  {
55
- href: address => `${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/current${paths.ACCOUNT_EDIT_SHIP_TO_ADDRESS}/${address.id}?returnUrl=${encodeURIComponent(href)}`,
57
+ href: address => `${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/current${paths.ACCOUNT_EDIT_SHIP_TO_ADDRESS}/${address.id}?returnUrl=${encodeURIComponent(`${href}#${addressBookId}`)}`,
56
58
  key: 'edit',
57
59
  label: 'Edit',
58
60
  },
@@ -83,7 +85,7 @@ function ConnectedAddressBookWidget() {
83
85
  sticky: true,
84
86
  truncated: 3,
85
87
  },
86
- sort: { direction: 'DESC', isEnabled: true },
88
+ sort: { direction: sort.order, isEnabled: true },
87
89
  value: {
88
90
  propertyName: 'companyName',
89
91
  },
@@ -153,14 +155,14 @@ function ConnectedAddressBookWidget() {
153
155
  action: 'edit',
154
156
  },
155
157
  },
156
- ], data: addresses, onSort: (key, direction) => {
158
+ ], data: addresses && addresses.length > 0 ? addresses : [], onSort: (key, direction) => {
157
159
  if (direction === 'NONE')
158
160
  return;
159
161
  setSort({
160
162
  name: key,
161
163
  order: direction,
162
164
  });
163
- } })) }) }) }));
165
+ } }) }) }) }));
164
166
  }
165
167
 
166
168
  export { ConnectedAddressBookWidget };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "205.0.0",
3
+ "version": "207.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {