PHP 8.2.30
Preview: base-action-component.tsx Size: 2.47 KB
//proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/src/frontend/components/app/base-action-component.tsx

import React from 'react'
import { Trans } from 'react-i18next'
import { MessageBox, Link } from '@adminjs/design-system'

import ErrorBoundary from './error-boundary.js'
import { actions } from '../actions/index.js'
import { DOCS } from '../../../constants.js'
import { ActionProps } from '../actions/action.props.js'
import { useTranslation } from '../../hooks/index.js'

declare const AdminJS: {
  UserComponents: Array<string>;
}

/**
 * Component which renders all the default and custom actions for both the Resource and the Record.
 *
 * It passes all props down to the actual Action component.
 *
 * Example of creating your own actions:
 * ```
 * // AdminJS options
 * const AdminJSOptions = {
 *   resources: [
 *      resource,
 *      options: {
 *        actions: {
 *           myNewAction: {
 *             label: 'amazing action',
 *             icon: 'Add',
 *             inVisible: (resource, record) => record.param('email') !== '',
 *             actionType: 'record',
 *             component: 'MyNewAction',
 *             handler: (request, response, data) => {
 *               return {
 *                  ...
 *               }
 *             }
 *           }
 *        }
 *      }
 *   ]
 * }
 * ```
 *
 * ```
 * // ./my-new-action.js
 * import { Box } from 'adminjs'
 *
 * const MyNewAction = (props) => {
 *   const { resource, action, record } = props
 *   // do something with the props and render action
 *   return (
 *     <Box>Some Action Content</Box>
 *   )
 * }
 * ```
 *
 * @component
 * @name BaseActionComponent
 * @subcategory Application
 */
export const BaseActionComponent: React.FC<ActionProps> = (props) => {
  const { resource, action, record, records, setTag } = props
  const documentationLink = [DOCS, 'BaseAction.html'].join('/')

  const { translateMessage } = useTranslation()

  let Action = actions[action.name]

  if (action.component) {
    Action = AdminJS.UserComponents[action.component]
  }

  if (Action) {
    return (
      <ErrorBoundary>
        <Action
          action={action}
          resource={resource}
          record={record}
          records={records}
          setTag={setTag}
        />
      </ErrorBoundary>
    )
  }
  return Action || (
    <MessageBox variant="danger">
      {translateMessage('noActionComponent')}
      <Trans key="messages.buttons.seeTheDocumentation">
        See:
        <Link ml="default" href={documentationLink}>the documentation</Link>
      </Trans>
    </MessageBox>
  )
}

export default BaseActionComponent

Directory Contents

Dirs: 6 × Files: 17

Name Size Perms Modified Actions
- drwxr-xr-x 2026-02-28 00:32:46
Edit Download
- drwxr-xr-x 2026-02-28 00:32:50
Edit Download
- drwxr-xr-x 2026-02-28 00:32:46
Edit Download
- drwxr-xr-x 2026-02-28 00:32:48
Edit Download
sidebar DIR
- drwxr-xr-x 2026-02-28 00:32:50
Edit Download
utils DIR
- drwxr-xr-x 2026-02-28 00:32:48
Edit Download
383 B lrw-r--r-- 2026-02-28 00:32:46
Edit Download
235 B lrw-r--r-- 2026-02-28 00:32:46
Edit Download
525 B lrw-r--r-- 2026-02-28 00:32:46
Edit Download
2.47 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download
3.21 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download
5.74 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download
3.51 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download
966 B lrw-r--r-- 2026-02-28 00:32:46
Edit Download
2.25 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download
4.08 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download
282 B lrw-r--r-- 2026-02-28 00:32:46
Edit Download
755 B lrw-r--r-- 2026-02-28 00:32:28
Edit Download
1.15 KB lrw-r--r-- 2026-02-28 00:32:48
Edit Download
3.27 KB lrw-r--r-- 2026-02-28 00:32:48
Edit Download
1.55 KB lrw-r--r-- 2026-02-28 00:32:50
Edit Download
1.71 KB lrw-r--r-- 2026-02-28 00:32:50
Edit Download
1.22 KB lrw-r--r-- 2026-02-28 00:32:50
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).