@sqrzro/admin 2.1.0-bz.37 → 2.1.0-bz.39
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/dist/components/DateFilter/index.js +22 -2
- package/dist/components/FilterBarItem/index.js +4 -4
- package/dist/components/RootLayout/index.js +1 -1
- package/dist/components/Table/index.d.ts +6 -8
- package/dist/components/Table/index.js +16 -14
- package/dist/components/TableComponent/index.d.ts +12 -0
- package/dist/components/TableComponent/index.js +17 -0
- package/package.json +1 -1
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { CalendarInput } from '@sqrzro/components';
|
|
3
|
+
import { formatDate } from '@sqrzro/utility';
|
|
4
|
+
function parseValueUp(value) {
|
|
5
|
+
if (!value) {
|
|
6
|
+
return '';
|
|
7
|
+
}
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
return value.map((item) => formatDate(item, 'YYYY-MM-DD')).join(',');
|
|
10
|
+
}
|
|
11
|
+
return formatDate(value, 'YYYY-MM-DD');
|
|
12
|
+
}
|
|
13
|
+
function parseValueDown(value) {
|
|
14
|
+
if (!value) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (value.includes(',')) {
|
|
18
|
+
const [start, end] = value.split(',').map((item) => new Date(item));
|
|
19
|
+
return [start, end];
|
|
20
|
+
}
|
|
21
|
+
return new Date(value);
|
|
22
|
+
}
|
|
3
23
|
function DateFilter({ name, onChange, value }) {
|
|
4
24
|
function handleChange(event) {
|
|
5
|
-
onChange({ target: { name, value:
|
|
25
|
+
onChange({ target: { name, value: parseValueUp(event.target.value) } });
|
|
6
26
|
}
|
|
7
|
-
return (_jsx(CalendarInput, { name: name, onChange: handleChange, value:
|
|
27
|
+
return (_jsx(CalendarInput, { name: name, onChange: handleChange, value: parseValueDown(value), isPanelOnly: true, isRange: true }));
|
|
8
28
|
}
|
|
9
29
|
export function transformDateValue(value) {
|
|
10
30
|
return value || '';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useRef } from 'react';
|
|
4
3
|
import { tw } from '@sqrzro/components';
|
|
4
|
+
import { useClickOutside } from '@sqrzro/hooks';
|
|
5
5
|
import BooleanFilter, { renderBooleanValue } from '../BooleanFilter';
|
|
6
6
|
import DateFilter, { renderDateValue, transformDateValue } from '../DateFilter';
|
|
7
7
|
import DropdownFilter, { renderDropdownValue } from '../DropdownFilter';
|
|
@@ -18,15 +18,15 @@ const map = {
|
|
|
18
18
|
};
|
|
19
19
|
const DEFAULT_SIZE = 'w-56';
|
|
20
20
|
function FilterBarItem({ data, label, name, onChange, type, value, }) {
|
|
21
|
-
const
|
|
21
|
+
const [isOpen, setIsOpen, node] = useClickOutside();
|
|
22
22
|
function handleChange(event) {
|
|
23
23
|
onChange(name, event.target.value);
|
|
24
|
-
|
|
24
|
+
setIsOpen(false);
|
|
25
25
|
}
|
|
26
26
|
function handleClear() {
|
|
27
27
|
onChange(name, '');
|
|
28
28
|
}
|
|
29
29
|
const { component: FilterComponent, renderValue, size, transformValue } = map[type];
|
|
30
|
-
return (_jsxs("li", { className: tw('relative inline-flex h-8 items-center gap-2 rounded-full border px-5 text-xs text-white', value ? 'border-solid border-slate-400' : 'border-dashed border-slate-400', value ? 'bg-slate-700 pr-10' : 'text-slate-300'), children: [_jsx("p", { className: "", children: label }), value ? (_jsx("p", { className: "border-l border-l-slate-300 pl-2 font-semibold", children: renderValue(value, data) })) : null, _jsx("button", { className: tw('absolute left-0 top-0 h-full select-none text-transparent', value ? 'right-10' : 'right-0'),
|
|
30
|
+
return (_jsxs("li", { ref: node, className: tw('relative inline-flex h-8 items-center gap-2 rounded-full border px-5 text-xs text-white', value ? 'border-solid border-slate-400' : 'border-dashed border-slate-400', value ? 'bg-slate-700 pr-10' : 'text-slate-300'), children: [_jsx("p", { className: "", children: label }), value ? (_jsx("p", { className: "border-l border-l-slate-300 pl-2 font-semibold", children: renderValue(value, data) })) : null, _jsx("button", { className: tw('absolute left-0 top-0 h-full select-none text-transparent', value ? 'right-10' : 'right-0'), onClick: () => setIsOpen(!isOpen), type: "button", children: "Edit" }), value ? _jsx(FilterBarClearButton, { onClick: handleClear }) : null, _jsx("div", { className: tw('show absolute left-0 top-full z-10 -ml-px mt-2 origin-top-left origin-top-left rounded bg-white shadow-lg', size || DEFAULT_SIZE, isOpen ? 'block' : 'hidden'), children: _jsx("div", { className: "py-1", role: "none", children: _jsx(FilterComponent, { data: data, name: name, onChange: handleChange, value: transformValue ? transformValue(value) : value }) }) })] }));
|
|
31
31
|
}
|
|
32
32
|
export default FilterBarItem;
|
|
@@ -8,7 +8,7 @@ function RootLayout({ children, config, font, logo, }) {
|
|
|
8
8
|
if (config) {
|
|
9
9
|
setConfig(config, logo);
|
|
10
10
|
}
|
|
11
|
-
return (_jsxs("html", { lang: "en", children: [_jsx("head", {}), _jsxs("body", { className: tw(font, 'overflow-x-hidden overflow-y-scroll bg-slate-50 font-sans text-sm text-slate-800 has-[[data-modal][open]]:overflow-hidden'), children: [_jsx("script", { dangerouslySetInnerHTML: {
|
|
11
|
+
return (_jsxs("html", { lang: "en", children: [_jsx("head", { children: _jsx("link", { href: "/images/favicon.svg", rel: "icon" }) }), _jsxs("body", { className: tw(font, 'overflow-x-hidden overflow-y-scroll bg-slate-50 font-sans text-sm text-slate-800 has-[[data-modal][open]]:overflow-hidden'), children: [_jsx("script", { dangerouslySetInnerHTML: {
|
|
12
12
|
__html: "(function(d){var v=d.createElement('div'),t=d.createElement('style'),s=v.style;s.overflowY='scroll';s.width='50';s.height='50';d.body.append(v);t.innerHTML='body:has([data-modal][open]){padding-right:'+(v.offsetWidth-v.clientWidth)+'px}';d.body.append(t);v.remove()}(document))",
|
|
13
13
|
} }), _jsx(Config, { data: config }), _jsx(ClassNames, { data: classNames }), children, _jsx(Toaster, {})] })] }));
|
|
14
14
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
export interface TableProps<Item, Params> extends Omit<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
searchParams?: URLSearchParams;
|
|
8
|
-
transformer?: (item: Item) => TableItemObject;
|
|
2
|
+
import type { FilterObject } from '../FilterBar';
|
|
3
|
+
import type { TableComponentProps } from '../TableComponent';
|
|
4
|
+
export interface TableProps<Item extends object, Params> extends Omit<TableComponentProps<Item, Params>, 'actions'> {
|
|
5
|
+
actions?: (data: Record<string, unknown>) => React.ReactNode;
|
|
6
|
+
filters?: FilterObject[];
|
|
9
7
|
}
|
|
10
|
-
declare function Table<Item extends object, Params>({
|
|
8
|
+
declare function Table<Item extends object, Params>({ filters, hasSearch, ...props }: Readonly<TableProps<Item, Params>>): Promise<React.ReactElement>;
|
|
11
9
|
export default Table;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, Suspense } from 'react';
|
|
3
|
+
import { getLayout } from '../../services/SettingsService';
|
|
4
|
+
import FilterBar from '../FilterBar';
|
|
5
|
+
import Panel from '../Panel';
|
|
6
|
+
import TableComponent from '../TableComponent';
|
|
7
|
+
async function Table({ filters, hasSearch, ...props }) {
|
|
8
|
+
const layout = await getLayout();
|
|
9
|
+
let searchParams; // eslint-disable-line @typescript-eslint/init-declarations
|
|
10
|
+
try {
|
|
11
|
+
const { headers } = await import('next/headers');
|
|
12
|
+
searchParams = new URLSearchParams((await headers()).get('x-search-params') || '');
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
searchParams = new URLSearchParams();
|
|
13
16
|
}
|
|
14
|
-
|
|
15
|
-
return _jsx(TableClientComponent, { columns: columns, data: data });
|
|
17
|
+
return (_jsxs(Fragment, { children: [filters || hasSearch ? (_jsx(FilterBar, { hasSearch: hasSearch, layout: layout, map: filters })) : null, _jsx(Panel, { children: _jsx(Suspense, { fallback: _jsx("div", { children: "Loading..." }), children: _jsx(TableComponent, { ...props, searchParams: searchParams }) }) })] }));
|
|
16
18
|
}
|
|
17
19
|
export default Table;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Errorable } from '@sqrzro/interfaces';
|
|
3
|
+
import type { TableClientComponentProps, TableItemObject } from '../TableClientComponent';
|
|
4
|
+
export interface TableComponentProps<Item, Params> extends Omit<TableClientComponentProps, 'data'> {
|
|
5
|
+
fn: (params?: Params, searchParams?: URLSearchParams) => Promise<Errorable<Item[]>>;
|
|
6
|
+
hasSearch?: boolean;
|
|
7
|
+
params?: Params;
|
|
8
|
+
searchParams?: URLSearchParams;
|
|
9
|
+
transformer?: (item: Item) => TableItemObject;
|
|
10
|
+
}
|
|
11
|
+
declare function TableComponent<Item extends object, Params>({ columns, fn, params, searchParams, transformer, }: Readonly<TableComponentProps<Item, Params>>): Promise<React.ReactElement>;
|
|
12
|
+
export default TableComponent;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import TableClientComponent from '../TableClientComponent';
|
|
3
|
+
function defaultTransformer(item) {
|
|
4
|
+
return {
|
|
5
|
+
id: item.id,
|
|
6
|
+
...item,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
async function TableComponent({ columns, fn, params, searchParams, transformer, }) {
|
|
10
|
+
const [response, error] = await fn(params, searchParams);
|
|
11
|
+
if (error) {
|
|
12
|
+
return _jsxs("div", { children: ["Error - ", error.message] });
|
|
13
|
+
}
|
|
14
|
+
const data = response.map(transformer || defaultTransformer);
|
|
15
|
+
return _jsx(TableClientComponent, { columns: columns, data: data });
|
|
16
|
+
}
|
|
17
|
+
export default TableComponent;
|