muffin-admin 3.15.0 → 3.17.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.
@@ -35,7 +35,8 @@ setupAdmin(["list-grid-buttons"], MuffinListGridButtons);
35
35
  function MuffinListToolbar() {
36
36
  const { actions: baseActions = [], help, list: { create }, } = useMuffinResourceOpts();
37
37
  const actions = baseActions.filter((a) => { var _a; return (_a = a.view) === null || _a === void 0 ? void 0 : _a.includes("list"); });
38
- return (_jsxs(TopToolbar, { children: [help && _jsx(HelpLink, { href: help }), _jsx(SelectColumnsButton, {}), _jsx(FilterButton, {}), actions.length ? actions.map((props) => _jsx(ActionButton, Object.assign({}, props), props.id)) : null, create && _jsx(CreateButton, {}), _jsx(ExportButton, {})] }));
38
+ const hasExport = actions.some((a) => a.id === "export");
39
+ return (_jsxs(TopToolbar, { children: [help && _jsx(HelpLink, { href: help }), _jsx(SelectColumnsButton, {}), _jsx(FilterButton, {}), create && _jsx(CreateButton, {}), actions.length ? actions.map((props) => _jsx(ActionButton, Object.assign({}, props), props.id)) : null, !hasExport && _jsx(ExportButton, {})] }));
39
40
  }
40
41
  setupAdmin(["list-toolbar"], MuffinListToolbar);
41
42
  function MuffinListBulkActions() {
@@ -3,6 +3,7 @@ export declare function MuffinAuthProvider(props: AdminOpts["auth"]): {
3
3
  login: (data: any) => Promise<void>;
4
4
  checkError: (error: any) => Promise<void>;
5
5
  checkAuth: () => Promise<any>;
6
+ getAuthorization: () => any;
6
7
  logout: () => Promise<void>;
7
8
  getIdentity: () => Promise<any>;
8
9
  getPermissions: () => Promise<any>;
@@ -64,6 +64,7 @@ export function MuffinAuthProvider(props) {
64
64
  throw { message: "Authorization required" };
65
65
  return user;
66
66
  }),
67
+ getAuthorization: () => authGet(storageName),
67
68
  logout: () => __awaiter(this, void 0, void 0, function* () {
68
69
  // Clean storage
69
70
  authSet(storageName, "");
@@ -19,15 +19,16 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  return t;
20
20
  };
21
21
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
22
- import { Button, FormGroupsProvider, useAugmentedForm, useDataProvider, useListContext, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
22
+ import { Button, FormGroupsProvider, useAugmentedForm, useListContext, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
23
23
  import { FormProvider } from "react-hook-form";
24
24
  import { Link, Stack } from "@mui/material";
25
25
  import { useState } from "react";
26
26
  import { buildRA } from "../buildRA";
27
27
  import { AdminModal, PayloadButtons, useConfirmation } from "../common";
28
28
  import { HelpLink } from "../common/HelpLink";
29
+ import { useMuffinAdminOpts } from "../hooks";
29
30
  import { useAction } from "../hooks/useAction";
30
- import { buildIcon, findBuilder } from "../utils";
31
+ import { buildIcon, findBuilder, requestHeaders } from "../utils";
31
32
  export function ActionButton(_a) {
32
33
  var { paths, confirm, file } = _a, props = __rest(_a, ["paths", "confirm", "file"]);
33
34
  const translate = useTranslate();
@@ -35,12 +36,15 @@ export function ActionButton(_a) {
35
36
  const confirmation = useConfirmation();
36
37
  const path = paths.find((p) => p.includes("{id}")) || paths[paths.length - 1];
37
38
  const { mutate, isPending } = useAction(path);
38
- const dataprovider = useDataProvider();
39
+ const { apiUrl } = useMuffinAdminOpts();
39
40
  if (file) {
40
- return (_jsx(Button, { component: Link, label: props.label, onClick: (e) => {
41
- e.stopPropagation();
42
- dataprovider.downloadFile(path);
43
- }, children: buildIcon(props.icon) }));
41
+ let url = `${apiUrl}${path}`;
42
+ if (record)
43
+ url.replace("{id}", record.id);
44
+ const authorization = requestHeaders["Authorization"];
45
+ if (authorization)
46
+ url += `?t=${authorization}`;
47
+ return (_jsx(Button, { href: url, label: props.label, component: Link, target: "_blank", children: buildIcon(props.icon) }));
44
48
  }
45
49
  const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
46
50
  const onHandle = (payload) => __awaiter(this, void 0, void 0, function* () {
@@ -60,7 +60,6 @@ export declare function MuffinDataprovider(apiUrl: string): {
60
60
  runAction: (resource: string, action: string, props: TActionProps) => Promise<{
61
61
  data: any;
62
62
  }>;
63
- downloadFile: (path: string) => Promise<void>;
64
63
  };
65
64
  export type TActionProps<T = any> = {
66
65
  payload?: any;
@@ -18,7 +18,7 @@ var __rest = (this && this.__rest) || function (s, e) {
18
18
  }
19
19
  return t;
20
20
  };
21
- import { makeRequest, requestHeaders, setupAdmin } from "./utils";
21
+ import { makeRequest, setupAdmin } from "./utils";
22
22
  export function MuffinDataprovider(apiUrl) {
23
23
  function request(url, options) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
@@ -101,23 +101,6 @@ export function MuffinDataprovider(apiUrl) {
101
101
  });
102
102
  return { data: json };
103
103
  }),
104
- downloadFile: (path) => __awaiter(this, void 0, void 0, function* () {
105
- var _a;
106
- path = path.replace(/^\/+/, "");
107
- const response = yield fetch(`${apiUrl}/${path}`, {
108
- headers: requestHeaders,
109
- });
110
- const url = window.URL.createObjectURL(yield response.blob());
111
- const link = document.createElement("a");
112
- link.href = url;
113
- const filename = ((_a = response.headers.get("content-disposition")) === null || _a === void 0 ? void 0 : _a.split("filename=")[1]) || path.split("/").pop();
114
- link.setAttribute("download", filename);
115
- if (filename)
116
- link.setAttribute("download", filename);
117
- link.click();
118
- // no need to append link as child to body.
119
- setTimeout(() => window.URL.revokeObjectURL(url), 0); // this is important too, otherwise we will be unnecessarily spiking memory!
120
- }),
121
104
  };
122
105
  return methods;
123
106
  }