@compill/admin 1.0.53 → 1.0.55

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.cjs.js CHANGED
@@ -20,6 +20,7 @@ var admin = require('@compill/admin');
20
20
  var reactDom = require('react-dom');
21
21
  var table = require('@compill/table');
22
22
  var hooks = require('@compill/hooks');
23
+ var router = require('next/router');
23
24
  var reactQuery = require('@tanstack/react-query');
24
25
 
25
26
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -1444,10 +1445,10 @@ function TableCreateButton(_a) {
1444
1445
  children
1445
1446
  } = _a,
1446
1447
  props = __rest$1(_a, ["children"]);
1447
- return jsxRuntime.jsx(admin.ButtonBarDialogButton, Object.assign({}, props, {
1448
- children: children !== null && children !== void 0 ? children : jsxRuntime.jsx(ui.Icon, {
1448
+ return jsxRuntime.jsxs(admin.ButtonBarDialogButton, Object.assign({}, props, {
1449
+ children: [jsxRuntime.jsx(ui.Icon, {
1449
1450
  path: mdiPlusThick
1450
- })
1451
+ }), children]
1451
1452
  }));
1452
1453
  }
1453
1454
 
@@ -2241,7 +2242,7 @@ function ItemDeleteDialog(_a) {
2241
2242
  children: `Delete ${itemLabel}`
2242
2243
  }), jsxRuntime.jsxs(ui.Modal.Body, {
2243
2244
  pb: "6",
2244
- children: [!msg && `Do you really want to delete ${itemLabel}?`, msg && msg(itemLabel)]
2245
+ children: [!msg && `Do you really want to delete ${itemLabel}?`, msg && react.runIfFn(msg, itemLabel)]
2245
2246
  }), jsxRuntime.jsxs(ui.Modal.Footer, {
2246
2247
  dflex: true,
2247
2248
  placeContent: "end",
@@ -2289,18 +2290,20 @@ function TableViewProvider({
2289
2290
  case "edit":
2290
2291
  {
2291
2292
  const editConfig = react.runIfFn(editView, item);
2292
- if (editConfig.type == "customDialog") {
2293
- setDialog(editConfig.render({
2294
- show: true,
2295
- onClose: onCloseDialog
2296
- }));
2297
- } else {
2298
- setDialog(jsxRuntime.jsx(DialogRenderer, {
2299
- onClose: onCloseDialog,
2300
- config: editConfig,
2301
- queryId: item.id,
2302
- invalidateQueryKey: queryKey
2303
- }));
2293
+ if (editConfig) {
2294
+ if (editConfig.type == "customDialog") {
2295
+ setDialog(editConfig.render({
2296
+ show: true,
2297
+ onClose: onCloseDialog
2298
+ }));
2299
+ } else {
2300
+ setDialog(jsxRuntime.jsx(DialogRenderer, {
2301
+ onClose: onCloseDialog,
2302
+ config: editConfig,
2303
+ queryId: item.id,
2304
+ invalidateQueryKey: queryKey
2305
+ }));
2306
+ }
2304
2307
  }
2305
2308
  break;
2306
2309
  }
@@ -2499,6 +2502,7 @@ const schemes$1 = {
2499
2502
 
2500
2503
  function useTableProps(api, table, rowActions) {
2501
2504
  const navigate = reactRouterDom.useNavigate();
2505
+ const nextRouter = router.useRouter();
2502
2506
  const openLink = hooks.useOpenLink();
2503
2507
  const {
2504
2508
  onAction
@@ -2509,7 +2513,27 @@ function useTableProps(api, table, rowActions) {
2509
2513
  } = table,
2510
2514
  props = __rest$1(table, ["onRowClick", "columns"]);
2511
2515
  const onRowClickHandler = React__default["default"].useCallback(item => {
2512
- if ((onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick.type) === "navigate") navigate(react.runIfFn(onRowClick.path, item));else if ((onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick.type) == "link") openLink(`${process.env["NEXT_PUBLIC_WEBSITE_URL"]}/${react.runIfFn(onRowClick.path, item)}`);
2516
+ var _a;
2517
+ const config = react.runIfFn(onRowClick, item);
2518
+ if (config) {
2519
+ switch (config.type) {
2520
+ case "navigate":
2521
+ {
2522
+ navigate((_a = react.runIfFn(config.path, item)) !== null && _a !== void 0 ? _a : "");
2523
+ break;
2524
+ }
2525
+ case "nextpush":
2526
+ {
2527
+ nextRouter.push(react.runIfFn(config.path, item));
2528
+ break;
2529
+ }
2530
+ case "link":
2531
+ {
2532
+ openLink(`${process.env["NEXT_PUBLIC_WEBSITE_URL"]}/${react.runIfFn(config.path, item)}`);
2533
+ break;
2534
+ }
2535
+ }
2536
+ }
2513
2537
  }, [navigate, onRowClick]);
2514
2538
  const columns = React__default["default"].useMemo(() => {
2515
2539
  const columns = table.columns.concat([]);
@@ -2527,7 +2551,7 @@ function useTableProps(api, table, rowActions) {
2527
2551
  }));
2528
2552
  }
2529
2553
  return columns;
2530
- }, [table]);
2554
+ }, [table, onAction, rowActions, api]);
2531
2555
  const tableProps = Object.assign({}, props);
2532
2556
  tableProps.columns = columns;
2533
2557
  tableProps.onRowClick = onRowClickHandler;
@@ -2653,7 +2677,8 @@ function TableButtonBar({
2653
2677
  queryKey: queryKey
2654
2678
  }), buttonBar && buttonBar.map((button, index) => jsxRuntime.jsxs(React__default["default"].Fragment, {
2655
2679
  children: [button.type === "create" && editView && jsxRuntime.jsx(TableCreateButton, {
2656
- buildDialog: createDialogFn(button.data)
2680
+ buildDialog: createDialogFn(button.data),
2681
+ children: button.label
2657
2682
  }), button.type === "invalidate" && jsxRuntime.jsx(InvalidateButton, {
2658
2683
  pathOrPermalink: button.pathOrPermalink
2659
2684
  }), button.type === "custom" && button.render()]
package/index.esm.js CHANGED
@@ -16,6 +16,7 @@ import { PageSectionTitle as PageSectionTitle$1, ButtonBarDialogButton as Button
16
16
  import { createPortal } from 'react-dom';
17
17
  import { TableContextProvider, useTableContext, Table } from '@compill/table';
18
18
  import { useOpenLink, useBoolean } from '@compill/hooks';
19
+ import { useRouter } from 'next/router';
19
20
  import { useQueryClient } from '@tanstack/react-query';
20
21
 
21
22
  /******************************************************************************
@@ -1435,10 +1436,10 @@ function TableCreateButton(_a) {
1435
1436
  children
1436
1437
  } = _a,
1437
1438
  props = __rest$1(_a, ["children"]);
1438
- return jsx(ButtonBarDialogButton$1, Object.assign({}, props, {
1439
- children: children !== null && children !== void 0 ? children : jsx(Icon, {
1439
+ return jsxs(ButtonBarDialogButton$1, Object.assign({}, props, {
1440
+ children: [jsx(Icon, {
1440
1441
  path: mdiPlusThick
1441
- })
1442
+ }), children]
1442
1443
  }));
1443
1444
  }
1444
1445
 
@@ -2232,7 +2233,7 @@ function ItemDeleteDialog(_a) {
2232
2233
  children: `Delete ${itemLabel}`
2233
2234
  }), jsxs(Modal.Body, {
2234
2235
  pb: "6",
2235
- children: [!msg && `Do you really want to delete ${itemLabel}?`, msg && msg(itemLabel)]
2236
+ children: [!msg && `Do you really want to delete ${itemLabel}?`, msg && runIfFn(msg, itemLabel)]
2236
2237
  }), jsxs(Modal.Footer, {
2237
2238
  dflex: true,
2238
2239
  placeContent: "end",
@@ -2280,18 +2281,20 @@ function TableViewProvider({
2280
2281
  case "edit":
2281
2282
  {
2282
2283
  const editConfig = runIfFn(editView, item);
2283
- if (editConfig.type == "customDialog") {
2284
- setDialog(editConfig.render({
2285
- show: true,
2286
- onClose: onCloseDialog
2287
- }));
2288
- } else {
2289
- setDialog(jsx(DialogRenderer, {
2290
- onClose: onCloseDialog,
2291
- config: editConfig,
2292
- queryId: item.id,
2293
- invalidateQueryKey: queryKey
2294
- }));
2284
+ if (editConfig) {
2285
+ if (editConfig.type == "customDialog") {
2286
+ setDialog(editConfig.render({
2287
+ show: true,
2288
+ onClose: onCloseDialog
2289
+ }));
2290
+ } else {
2291
+ setDialog(jsx(DialogRenderer, {
2292
+ onClose: onCloseDialog,
2293
+ config: editConfig,
2294
+ queryId: item.id,
2295
+ invalidateQueryKey: queryKey
2296
+ }));
2297
+ }
2295
2298
  }
2296
2299
  break;
2297
2300
  }
@@ -2490,6 +2493,7 @@ const schemes$1 = {
2490
2493
 
2491
2494
  function useTableProps(api, table, rowActions) {
2492
2495
  const navigate = useNavigate();
2496
+ const nextRouter = useRouter();
2493
2497
  const openLink = useOpenLink();
2494
2498
  const {
2495
2499
  onAction
@@ -2500,7 +2504,27 @@ function useTableProps(api, table, rowActions) {
2500
2504
  } = table,
2501
2505
  props = __rest$1(table, ["onRowClick", "columns"]);
2502
2506
  const onRowClickHandler = React.useCallback(item => {
2503
- if ((onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick.type) === "navigate") navigate(runIfFn(onRowClick.path, item));else if ((onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick.type) == "link") openLink(`${process.env["NEXT_PUBLIC_WEBSITE_URL"]}/${runIfFn(onRowClick.path, item)}`);
2507
+ var _a;
2508
+ const config = runIfFn(onRowClick, item);
2509
+ if (config) {
2510
+ switch (config.type) {
2511
+ case "navigate":
2512
+ {
2513
+ navigate((_a = runIfFn(config.path, item)) !== null && _a !== void 0 ? _a : "");
2514
+ break;
2515
+ }
2516
+ case "nextpush":
2517
+ {
2518
+ nextRouter.push(runIfFn(config.path, item));
2519
+ break;
2520
+ }
2521
+ case "link":
2522
+ {
2523
+ openLink(`${process.env["NEXT_PUBLIC_WEBSITE_URL"]}/${runIfFn(config.path, item)}`);
2524
+ break;
2525
+ }
2526
+ }
2527
+ }
2504
2528
  }, [navigate, onRowClick]);
2505
2529
  const columns = React.useMemo(() => {
2506
2530
  const columns = table.columns.concat([]);
@@ -2518,7 +2542,7 @@ function useTableProps(api, table, rowActions) {
2518
2542
  }));
2519
2543
  }
2520
2544
  return columns;
2521
- }, [table]);
2545
+ }, [table, onAction, rowActions, api]);
2522
2546
  const tableProps = Object.assign({}, props);
2523
2547
  tableProps.columns = columns;
2524
2548
  tableProps.onRowClick = onRowClickHandler;
@@ -2644,7 +2668,8 @@ function TableButtonBar({
2644
2668
  queryKey: queryKey
2645
2669
  }), buttonBar && buttonBar.map((button, index) => jsxs(React.Fragment, {
2646
2670
  children: [button.type === "create" && editView && jsx(TableCreateButton, {
2647
- buildDialog: createDialogFn(button.data)
2671
+ buildDialog: createDialogFn(button.data),
2672
+ children: button.label
2648
2673
  }), button.type === "invalidate" && jsx(InvalidateButton, {
2649
2674
  pathOrPermalink: button.pathOrPermalink
2650
2675
  }), button.type === "custom" && button.render()]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compill/admin",
3
- "version": "1.0.53",
3
+ "version": "1.0.55",
4
4
  "module": "./index.esm.js",
5
5
  "main": "./index.cjs.js"
6
6
  }
@@ -1,3 +1,3 @@
1
- import { TableRowAction, TableViewTable } from "../types/TableView";
2
1
  import { API } from "@compill/admin-api";
2
+ import { TableRowAction, TableViewTable } from "../types/TableView";
3
3
  export declare function useTableProps(api: API<any>, table: TableViewTable, rowActions?: TableRowAction[] | ((item?: any) => TableRowAction[])): any;
@@ -36,10 +36,7 @@ export type TableViewEditView = CustomDialog | EditItemDialogConfig | QueryWrapp
36
36
  export type TableViewTable = Omit<TableProps, "onRowClick" | "queryKey" | "queryFn"> & {
37
37
  initialVisibleColumns?: string[];
38
38
  onRowClick?: {
39
- type: "navigate";
40
- path: string | ((item: any) => string);
41
- } | {
42
- type: "link";
39
+ type: "navigate" | "nextpush" | "link";
43
40
  path: string | ((item: any) => string);
44
41
  };
45
42
  };