UNPKG

@premieroctet/next-admin

Version:

Next-Admin provides a customizable and turnkey admin dashboard for applications built with Next.js and powered by the Prisma ORM. It aims to simplify the development process by providing a turnkey admin system that can be easily integrated into your proje

191 lines (190 loc) 11.4 kB
"use client"; "use strict"; var __webpack_require__ = {}; (()=>{ __webpack_require__.n = (module)=>{ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module; __webpack_require__.d(getter, { a: getter }); return getter; }; })(); (()=>{ __webpack_require__.d = (exports1, definition)=>{ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, { enumerable: true, get: definition[key] }); }; })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.r = (exports1)=>{ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, { value: 'Module' }); Object.defineProperty(exports1, '__esModule', { value: true }); }; })(); var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { default: ()=>ListHeader }); const jsx_runtime_namespaceObject = require("react/jsx-runtime"); const outline_namespaceObject = require("@heroicons/react/24/outline"); const Link_js_namespaceObject = require("./common/Link.js"); var Link_js_default = /*#__PURE__*/ __webpack_require__.n(Link_js_namespaceObject); const external_react_namespaceObject = require("react"); const Loader_js_namespaceObject = require("../assets/icons/Loader.js"); var Loader_js_default = /*#__PURE__*/ __webpack_require__.n(Loader_js_namespaceObject); const ConfigContext_js_namespaceObject = require("../context/ConfigContext.js"); const I18nContext_js_namespaceObject = require("../context/I18nContext.js"); const useAction_js_namespaceObject = require("../hooks/useAction.js"); const external_types_js_namespaceObject = require("../types.js"); const tools_js_namespaceObject = require("../utils/tools.js"); const external_ActionsDropdown_js_namespaceObject = require("./ActionsDropdown.js"); var external_ActionsDropdown_js_default = /*#__PURE__*/ __webpack_require__.n(external_ActionsDropdown_js_namespaceObject); const external_Breadcrumb_js_namespaceObject = require("./Breadcrumb.js"); var external_Breadcrumb_js_default = /*#__PURE__*/ __webpack_require__.n(external_Breadcrumb_js_namespaceObject); const external_ExportDropdown_js_namespaceObject = require("./ExportDropdown.js"); var external_ExportDropdown_js_default = /*#__PURE__*/ __webpack_require__.n(external_ExportDropdown_js_namespaceObject); const Button_js_namespaceObject = require("./radix/Button.js"); const AdvancedSearchButton_js_namespaceObject = require("./advancedSearch/AdvancedSearchButton.js"); var AdvancedSearchButton_js_default = /*#__PURE__*/ __webpack_require__.n(AdvancedSearchButton_js_namespaceObject); function ListHeader({ resource, isPending, onSearchChange, search, actions: actionsProp, selectedRows, getSelectedRowsIds, onDelete, title, icon, totalCount, schema }) { const { basePath, options } = (0, ConfigContext_js_namespaceObject.useConfig)(); const { t } = (0, I18nContext_js_namespaceObject.useI18n)(); const hasPermission = (permission)=>!modelOptions?.permissions || modelOptions?.permissions?.includes(permission); const modelOptions = options?.model?.[resource]; const canCreate = hasPermission(external_types_js_namespaceObject.Permission.CREATE); const canDelete = hasPermission(external_types_js_namespaceObject.Permission.DELETE); const selectedRowsCount = Object.keys(selectedRows).length; const actions = (0, external_react_namespaceObject.useMemo)(()=>{ const defaultActions = canDelete ? [ { type: "server", id: useAction_js_namespaceObject.SPECIFIC_IDS_TO_RUN_ACTION.DELETE, title: t("actions.delete.label"), icon: "TrashIcon", style: "destructive", action: async ()=>{ await onDelete(); } } ] : []; return [ ...actionsProp ?? [], ...defaultActions ]; }, [ actionsProp, onDelete, t, canDelete ]); const resourcePluralName = t(`model.${resource}.plural`, {}, title); return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(jsx_runtime_namespaceObject.Fragment, { children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", { className: "bg-nextadmin-background-default dark:bg-dark-nextadmin-background-default dark:border-b-dark-nextadmin-border-default border-b-nextadmin-border-default sticky top-14 z-20 flex h-auto w-full flex-row flex-wrap items-start justify-between gap-3 border-b px-4 py-4 shadow-sm sm:w-auto sm:items-center md:py-3 lg:top-0", children: [ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_Breadcrumb_js_default(), { breadcrumbItems: [ { label: resourcePluralName, href: `${basePath}/${(0, tools_js_namespaceObject.slugify)(resource)}`, current: true, icon } ] }), /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", { className: "flex w-full flex-wrap items-center gap-2 sm:w-auto sm:flex-nowrap md:gap-4", children: [ (totalCount || false || search && totalCount || false) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", { className: "text-nextadmin-content-default dark:text-dark-nextadmin-content-default hidden min-w-fit text-sm sm:block", children: search ? t("list.header.search.result_filtered", { count: totalCount }) : t("list.header.search.result", { count: totalCount }) }), onSearchChange && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", { className: "bg-nextadmin-background-subtle dark:bg-dark-nextadmin-background-subtle ring-nextadmin-border-strong dark:ring-dark-nextadmin-border-strong flex min-w-0 items-center justify-end gap-2 rounded-md px-3 py-1 ring-1", children: [ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("input", { id: "search", name: "search", onInput: onSearchChange, defaultValue: search, type: "search", className: "text-nextadmin-content-subtle dark:text-dark-nextadmin-content-subtle w-full min-w-0 rounded-md bg-[transparent] py-1.5 text-sm focus:outline-none focus:ring-0 focus:ring-offset-0", placeholder: `${t("list.header.search.placeholder")} ${resourcePluralName.toLowerCase()}` }), /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("label", { htmlFor: "search", children: isPending ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Loader_js_default(), { className: "stroke-nextadmin-content-default dark:stroke-dark-nextadmin-content-default h-6 w-6 animate-spin dark:stroke-gray-300" }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(outline_namespaceObject.MagnifyingGlassIcon, { className: "text-nextadmin-content-default dark:text-dark-nextadmin-content-default h-6 w-6", "aria-hidden": "true" }) }) ] }), /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(AdvancedSearchButton_js_default(), { resource: resource, schema: schema }), Boolean(selectedRowsCount) && !!actions.length && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_ActionsDropdown_js_default(), { actions: actions, resource: resource, selectedIds: getSelectedRowsIds(), selectedCount: selectedRowsCount }), modelOptions?.list?.exports && (Array.isArray(modelOptions?.list?.exports) ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_ExportDropdown_js_default(), { exports: modelOptions?.list?.exports }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Link_js_default(), { href: modelOptions?.list?.exports.url, target: "_blank", className: "text-nextadmin-content-inverted dark:text-dark-nextadmin-brand-inverted border-nextadmin-border-default dark:border-dark-nextadmin-border-default dark:bg-dark-nextadmin-background-subtle flex min-w-fit items-center gap-x-2 rounded-md border bg-transparent px-3 py-2 text-sm", children: t("list.row.actions.export", { format: modelOptions?.list?.exports.format }) })), canCreate && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(Link_js_default(), { href: `${basePath}/${(0, tools_js_namespaceObject.slugify)(resource)}/new`, role: "button", "data-testid": "add-new-button", className: (0, Button_js_namespaceObject.buttonVariants)({ variant: "default", size: "sm" }), children: [ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", { children: t("list.header.add.label") }), /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(outline_namespaceObject.PlusSmallIcon, { className: "ml-2 h-5 w-5", "aria-hidden": "true" }) ] }) ] }) ] }) }); } exports["default"] = __webpack_exports__["default"]; for(var __webpack_i__ in __webpack_exports__)if (-1 === [ "default" ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__]; Object.defineProperty(exports, '__esModule', { value: true });