muffin-admin 8.2.0 → 8.4.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.
@@ -0,0 +1,8 @@
1
+ import { SortPayload } from "react-admin";
2
+ type TProps = {
3
+ resource: string;
4
+ filter: (record: any) => Record<string, any>;
5
+ sort?: SortPayload;
6
+ };
7
+ export declare function MuffinRecordList({ resource, filter, sort }: TProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import Box from "@mui/material/Box";
3
+ import Typography from "@mui/material/Typography";
4
+ import { Datagrid, useGetList, useRecordContext, useTranslate } from "react-admin";
5
+ import { useMuffinResourceOpts } from "./hooks";
6
+ import { buildAdmin } from "./utils";
7
+ export function MuffinRecordList({ resource, filter, sort }) {
8
+ const record = useRecordContext();
9
+ const translate = useTranslate();
10
+ const { list: { fields }, } = useMuffinResourceOpts(resource);
11
+ const { data, isPending } = useGetList(resource, { sort, filter: filter(record) });
12
+ return (_jsxs(Box, { p: 2, children: [_jsx(Typography, { variant: "h6", children: translate(`resources.${resource}.name`, { smart_count: 2 }) }), _jsx(Datagrid, { resource: resource, bulkActionButtons: false, isPending: isPending, data: data, children: buildAdmin(["list-fields", resource], fields) })] }));
13
+ }
package/dist/buildRA.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { ArrayField, ArrayInput, AutocompleteArrayInput, AutocompleteInput, BooleanField, BooleanInput, CheckboxGroupInput, ChipField, DateField, DateInput, DateTimeInput, EmailField, FileField, FileInput, ImageField, ImageInput, NullableBooleanInput, NumberField, NumberInput, PasswordInput, RadioButtonGroupInput, ReferenceArrayField, ReferenceArrayInput, ReferenceField, ReferenceInput, ReferenceManyField, required, RichTextField, SelectArrayInput, SelectField, SelectInput, TextField, TextInput, UrlField, } from "react-admin";
3
- import { AvatarField, EditableBooleanField, FKField, JsonField } from "./fields";
3
+ import { AvatarField, CopyField, EditableBooleanField, FKField, JsonField } from "./fields";
4
4
  import { FilterInput, FKInput, JsonInput, TimestampInput } from "./inputs";
5
5
  const UI = {
6
6
  // Fields
@@ -23,6 +23,7 @@ const UI = {
23
23
  EditableBooleanField,
24
24
  FKField,
25
25
  JsonField,
26
+ CopyField,
26
27
  // Inputs
27
28
  ArrayInput,
28
29
  AutocompleteArrayInput,
@@ -0,0 +1,3 @@
1
+ export declare function CopyButton({ value }: {
2
+ value: any;
3
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import CopyIcon from "@mui/icons-material/FileCopy";
3
+ import { Snackbar } from "@mui/material";
4
+ import { useState } from "react";
5
+ export function CopyButton({ value }) {
6
+ const [open, setOpen] = useState(false);
7
+ const handleClick = (e) => {
8
+ setOpen(true);
9
+ navigator.clipboard.writeText(value);
10
+ e.stopPropagation();
11
+ };
12
+ return (_jsxs("span", { title: "Copy to clipboard", children: [_jsx(CopyIcon, { color: "info", fontSize: "small", onClick: handleClick, style: { cursor: "pointer" } }), _jsx(Snackbar, { open: open, autoHideDuration: 2000, onClose: () => setOpen(false), message: `Copied to clipboard: ${value}` })] }));
13
+ }
@@ -1,2 +1,3 @@
1
1
  export * from "./ActionButton";
2
+ export * from "./CopyButton";
2
3
  export * from "./LinkButton";
@@ -1,2 +1,3 @@
1
1
  export * from "./ActionButton";
2
+ export * from "./CopyButton";
2
3
  export * from "./LinkButton";
@@ -0,0 +1,4 @@
1
+ export declare function CopyField({ source, ...props }: {
2
+ [x: string]: any;
3
+ source: any;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,23 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import get from "lodash/get";
14
+ import { useRecordContext } from "react-admin";
15
+ import { CopyButton } from "../buttons";
16
+ export function CopyField(_a) {
17
+ var { source } = _a, props = __rest(_a, ["source"]);
18
+ const record = useRecordContext(props);
19
+ const value = get(record, source);
20
+ if (!value)
21
+ return null;
22
+ return (_jsxs("div", { style: { display: "flex", alignItems: "center" }, children: [_jsx("span", { children: value }), _jsx(CopyButton, { value: value })] }));
23
+ }
@@ -1,4 +1,5 @@
1
1
  export * from "./AvatarField";
2
+ export * from "./CopyField";
2
3
  export * from "./EditableBooleanField";
3
4
  export * from "./FKField";
4
5
  export * from "./JsonField";
@@ -1,4 +1,5 @@
1
1
  export * from "./AvatarField";
2
+ export * from "./CopyField";
2
3
  export * from "./EditableBooleanField";
3
4
  export * from "./FKField";
4
5
  export * from "./JsonField";
@@ -1 +1 @@
1
- export declare function useMuffinResourceOpts(): import("..").AdminResourceProps;
1
+ export declare function useMuffinResourceOpts(resource?: any): import("..").AdminResourceProps;
@@ -1,7 +1,7 @@
1
1
  import { useResourceContext } from "react-admin";
2
2
  import { useMuffinAdminOpts } from "./useMuffinAdminOpts";
3
- export function useMuffinResourceOpts() {
4
- const resource = useResourceContext();
3
+ export function useMuffinResourceOpts(resource) {
4
+ resource = useResourceContext({ resource });
5
5
  const { resources } = useMuffinAdminOpts();
6
6
  return resources.find((r) => r.name === resource);
7
7
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./utils";
2
2
  export * from "./MuffinAdmin";
3
3
  export * from "./MuffinDashboard";
4
+ export * from "./MuffinRecordList";
4
5
  export * from "./MuffinResource";
5
6
  export * from "./MuffinResourceCreate";
6
7
  export * from "./MuffinResourceEdit";
@@ -17,4 +18,4 @@ export * from "./fields";
17
18
  export * from "./hooks";
18
19
  export * from "./types";
19
20
  export declare function initAdmin(prefix?: string, containerId?: string): Promise<void>;
20
- export declare const VERSION = "8.2.0";
21
+ export declare const VERSION = "8.4.0";
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ import { MuffinAdminContext } from "./context";
14
14
  export * from "./utils";
15
15
  export * from "./MuffinAdmin";
16
16
  export * from "./MuffinDashboard";
17
+ export * from "./MuffinRecordList";
17
18
  export * from "./MuffinResource";
18
19
  export * from "./MuffinResourceCreate";
19
20
  export * from "./MuffinResourceEdit";
@@ -40,4 +41,4 @@ export function initAdmin() {
40
41
  root.render(_jsx(MuffinAdminContext.Provider, { value: adminOpts, children: _jsx(MuffinAdmin, {}) }));
41
42
  });
42
43
  }
43
- export const VERSION = "8.2.0";
44
+ export const VERSION = "8.4.0";