Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: function for guard instead of only string #1654

Open
milovanderpas opened this issue Apr 8, 2024 · 0 comments
Open

[Feature]: function for guard instead of only string #1654

milovanderpas opened this issue Apr 8, 2024 · 0 comments

Comments

@milovanderpas
Copy link

milovanderpas commented Apr 8, 2024

Description

When defining a guard at the moment it is only possible to pass a string. I would like to pass a function so that I can show a specific guard message for each record.

Suggested Solution

In the build-action-click-handler.ts:

if (actionHasDisabledComponent(action)) {
      if (action.guard) {
        const modalData: ModalData = {
          modalProps: {
            variant: 'danger',
            label: 'confirm',
            title: typeof action.guard === 'string' ? action.guard : await action.guard(params),
          },
          type: 'confirm',
          resourceId: params.resourceId,
          confirmAction: callApi,
        }

        // If confirmation is required, action trigger should be handled in modal
        openModal(modalData)
        return
      }

      // If no confirmation is required, call API
      callApi()
      return
}

In the action.interface.ts:
export type GuardFunction = (params: DifferentActionParams) => string | Promise<string>
In the action.interface.d.ts:
guard?: string | GuardFunction

Alternatives

I do not have alternatives

Additional Context

The Function type can maybe be changed to a own interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant