@sqrzro/admin 2.1.0-bz.22 → 2.1.0-bz.23

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.
@@ -1,7 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import type { FilterObject } from '../FilterBar';
3
3
  import type { ListComponentProps } from '../ListComponent';
4
- export interface ListProps<Item extends object, Params> extends ListComponentProps<Item, Params> {
4
+ export interface ListProps<Item extends object, Params> extends Omit<ListComponentProps<Item, Params>, 'actions'> {
5
+ actions: (data: Record<string, unknown>) => React.ReactNode;
5
6
  filters?: FilterObject[];
6
7
  }
7
8
  declare function List<Item extends object, Params>({ filters, hasSearch, ...props }: Readonly<ListProps<Item, Params>>): Promise<React.ReactElement>;
@@ -3,10 +3,6 @@ import { Fragment, Suspense } from 'react';
3
3
  import { getLayout } from '../../services/SettingsService';
4
4
  import FilterBar from '../FilterBar';
5
5
  import ListComponent from '../ListComponent';
6
- const reservedSearchParams = ['action'];
7
- function checkHasFilters(searchParams) {
8
- return Array.from(searchParams.entries()).some(([key, value]) => !reservedSearchParams.includes(key) && Boolean(value));
9
- }
10
6
  async function List({ filters, hasSearch, ...props }) {
11
7
  const layout = await getLayout();
12
8
  let searchParams; // eslint-disable-line @typescript-eslint/init-declarations
@@ -18,6 +18,6 @@ function ListActions({ actions, id }) {
18
18
  href: item.href ? parseHref(item.href, id) : undefined, // eslint-disable-line no-undefined
19
19
  onClick: () => handleClick(item),
20
20
  }));
21
- return (_jsxs("div", { ref: ref, className: "relative h-5", children: [_jsx("button", { onClick: toggleIsOpen, type: "button", children: _jsx("svg", { "aria-hidden": "true", className: "h-5 w-5 fill-slate-500", viewBox: "0 0 20 20", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M10 3a1.5 1.5 0 110 3 1.5 1.5 0 010-3zM10 8.5a1.5 1.5 0 110 3 1.5 1.5 0 010-3zM11.5 15.5a1.5 1.5 0 10-3 0 1.5 1.5 0 003 0z" }) }) }), isOpen ? _jsx(Menu, { actions: transformedActions, align: "right" }) : null] }));
21
+ return (_jsxs("div", { ref: ref, className: "relative col-start-4 flex h-5 justify-end self-center pl-4", children: [_jsx("button", { onClick: toggleIsOpen, type: "button", children: _jsx("svg", { "aria-hidden": "true", className: "h-5 w-5 fill-slate-500", viewBox: "0 0 20 20", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M10 3a1.5 1.5 0 110 3 1.5 1.5 0 010-3zM10 8.5a1.5 1.5 0 110 3 1.5 1.5 0 010-3zM11.5 15.5a1.5 1.5 0 10-3 0 1.5 1.5 0 003 0z" }) }) }), isOpen ? _jsx(Menu, { actions: transformedActions, align: "right" }) : null] }));
22
22
  }
23
23
  export default ListActions;
@@ -1,15 +1,14 @@
1
1
  /// <reference types="react" />
2
2
  import type { EmptyMessageProps } from '@sqrzro/components';
3
- import type { ListAction } from '../ListActions';
4
3
  import type { ListObject } from '../ListItem';
5
- export interface ListClientComponentProps {
6
- actions?: ListAction[];
4
+ export interface ListClientComponentProps<Data = Record<string, unknown>> {
5
+ actions?: ListObject<Data>['actions'];
7
6
  columns?: number;
8
- data: ListObject[];
7
+ data: ListObject<Data>[];
9
8
  emptyMessageProps?: EmptyMessageProps;
10
9
  hasFilters?: boolean;
11
10
  isMinimal?: boolean;
12
- renderItem?: (props: ListObject) => JSX.Element;
11
+ renderItem?: (props: ListObject<Data>) => JSX.Element;
13
12
  }
14
- declare function ListClientComponent({ actions, columns, data, emptyMessageProps, hasFilters, isMinimal, renderItem, }: Readonly<ListClientComponentProps>): React.ReactElement;
13
+ declare function ListClientComponent<Data = Record<string, unknown>>({ actions, columns, data, emptyMessageProps, hasFilters, isMinimal, renderItem, }: Readonly<ListClientComponentProps<Data>>): React.ReactElement;
15
14
  export default ListClientComponent;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
- import type { ListAction } from '../ListActions';
3
- export interface ListObject {
4
- actions?: ListAction[] | ((id: string) => ListAction[]);
2
+ export interface ListObject<Data = Record<string, unknown>> {
3
+ $data?: Data;
4
+ actions?: (data: Data) => React.ReactNode;
5
5
  description?: React.ReactNode | null;
6
6
  href?: string;
7
7
  id: string;
@@ -19,5 +19,5 @@ export interface ListObject {
19
19
  title?: React.ReactNode;
20
20
  }
21
21
  export declare function renderMeta(id: string, meta: ListObject['meta']): React.ReactElement | null;
22
- declare function ListItem({ actions, description, href, id, isMinimal, meta, secondary, tertiary, title, }: Readonly<ListObject>): React.ReactElement;
22
+ declare function ListItem<Data = Record<string, unknown>>({ $data, actions, description, href, id, isMinimal, meta, secondary, tertiary, title, }: Readonly<ListObject<Data>>): React.ReactElement;
23
23
  export default ListItem;
@@ -2,7 +2,6 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { isValidElement } from 'react';
3
3
  import { Link, tw } from '@sqrzro/components';
4
4
  import { filterNull } from '@sqrzro/utility';
5
- import ListActions from '../ListActions';
6
5
  function getKey(item) {
7
6
  if (isValidElement(item)) {
8
7
  return item.key;
@@ -18,9 +17,9 @@ export function renderMeta(id, meta) {
18
17
  }
19
18
  return (_jsx("table", { className: "w-full text-xs", children: _jsx("tbody", { children: Object.entries(meta).map(([key, value]) => (_jsxs("tr", { className: "odd:bg-slate-100", children: [_jsx("th", { className: "p-2 font-semibold", children: key }), _jsx("td", { className: "p-2 text-right", children: value || '-' })] }, key))) }) }));
20
19
  }
21
- function ListItem({ actions, description, href, id, isMinimal, meta, secondary, tertiary, title, }) {
20
+ function ListItem({ $data, actions, description, href, id, isMinimal, meta, secondary, tertiary, title, }) {
22
21
  return (_jsx("li", { children: _jsx("article", { className: tw('', isMinimal
23
22
  ? 'border-b border-slate-200 pb-4'
24
- : 'bg-panel rounded p-4 shadow-[0px_0px_0px_1px_rgba(9,9,11,0.07),0px_2px_2px_0px_rgba(9,9,11,0.05)]'), "data-testid": `list-item-root--${id}`, children: _jsxs("div", { className: "grid grid-cols-[3fr_2fr_2fr_auto]", children: [_jsxs("div", { children: [title ? (_jsx("h2", { className: "text-base font-semibold", "data-testid": `list-item-title--${id}`, children: href ? _jsx(Link, { href: href, children: title }) : title })) : null, description, meta ? (_jsx("div", { className: tw(isMinimal ? 'mt-1' : 'mt-2 flex items-center justify-between'), children: meta ? renderMeta(id, meta) : null })) : null] }), tertiary ? (_jsx("div", { className: "flex h-full flex-col justify-center", children: tertiary })) : null, secondary ? (_jsxs("div", { className: "col-start-3 text-right", children: [secondary.title ? (_jsx("p", { className: "text-base font-semibold", children: secondary.title })) : null, secondary.description ? (_jsx("div", { className: "text-xs text-slate-500", children: secondary.description })) : null, secondary.meta ? (_jsx("ul", { className: "flex items-center justify-end gap-4 text-xs text-slate-500", children: filterNull(secondary.meta).map((item) => (_jsx("li", { children: item }, getKey(item)))) })) : null] })) : null, actions ? (_jsx("div", { className: "col-start-4 h-5 self-center pl-6", children: _jsx(ListActions, { actions: actions, id: id }) })) : null] }) }) }));
23
+ : 'bg-panel rounded p-4 shadow-[0px_0px_0px_1px_rgba(9,9,11,0.07),0px_2px_2px_0px_rgba(9,9,11,0.05)]'), "data-testid": `list-item-root--${id}`, children: _jsxs("div", { className: "grid grid-cols-[3fr_2fr_2fr_auto]", children: [_jsxs("div", { children: [title ? (_jsx("h2", { className: "text-base font-semibold", "data-testid": `list-item-title--${id}`, children: href ? _jsx(Link, { href: href, children: title }) : title })) : null, description, meta ? (_jsx("div", { className: tw('mt-1', isMinimal ? '' : 'flex items-center justify-between'), children: meta ? renderMeta(id, meta) : null })) : null] }), tertiary ? (_jsx("div", { className: "flex h-full flex-col justify-center", children: tertiary })) : null, secondary ? (_jsxs("div", { className: "col-start-3 text-right", children: [secondary.title ? (_jsx("p", { className: "text-base font-semibold", children: secondary.title })) : null, secondary.description ? (_jsx("div", { className: "mt-1 text-xs text-slate-500", children: secondary.description })) : null, secondary.meta ? (_jsx("ul", { className: "mt-1 flex items-center justify-end gap-4 text-xs text-slate-500", children: filterNull(secondary.meta).map((item) => (_jsx("li", { children: item }, getKey(item)))) })) : null] })) : null, typeof actions === 'function' ? actions($data) : null] }) }) }));
25
24
  }
26
25
  export default ListItem;
@@ -91,7 +91,7 @@ const classNames = twx({
91
91
  field: tw(props?.isEditable ? 'flex min-h-10 flex-col justify-center' : ''),
92
92
  details: tw('text-xs font-normal text-slate-500', props?.isEditable ? 'col-start-2 row-start-2 mt-2' : 'mb-2'),
93
93
  optional: 'pl-2 text-xs font-normal leading-none text-slate-500',
94
- error: tw('mt-2 flex items-center gap-1.5 text-red-600 before:h-4 before:w-4 before:rounded-full before:bg-[url(/admin/images/danger.svg)] before:bg-contain', props?.isEditable ? 'col-start-2' : ''),
94
+ error: tw('mt-2 flex items-start gap-1.5 text-red-600 before:mt-0.5 before:h-4 before:w-4 before:flex-none before:rounded-full before:bg-[url(/admin/images/danger.svg)] before:bg-contain', props?.isEditable ? 'col-start-2' : ''),
95
95
  }),
96
96
  imageInput: () => ({
97
97
  root: 'h-64 rounded border border-slate-300 bg-slate-50 p-8',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqrzro/admin",
3
3
  "type": "module",
4
- "version": "2.1.0-bz.22",
4
+ "version": "2.1.0-bz.23",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "ISC",