From c6705a0b0538329fbbf6d1749a312b062ce6197c Mon Sep 17 00:00:00 2001 From: Romain Lenzotti Date: Tue, 24 Dec 2024 14:04:34 +0100 Subject: [PATCH] fix(react-formio): update action table storybook --- .../components/__fixtures__/form-actions.json | 240 ++++++++++++ .../actions-table/actionsTable.component.tsx | 3 +- .../actions-table/actionsTable.stories.tsx | 362 ++++-------------- .../form-control/formControl.component.tsx | 15 +- .../components/select/select.component.tsx | 30 +- .../defaultCellOperations.component.tsx | 21 +- .../defaultOperationButton.component.tsx | 13 +- 7 files changed, 357 insertions(+), 327 deletions(-) create mode 100644 packages/react-formio/src/components/__fixtures__/form-actions.json diff --git a/packages/react-formio/src/components/__fixtures__/form-actions.json b/packages/react-formio/src/components/__fixtures__/form-actions.json new file mode 100644 index 00000000..e7384cbc --- /dev/null +++ b/packages/react-formio/src/components/__fixtures__/form-actions.json @@ -0,0 +1,240 @@ +[ + { + "name": "webhook", + "title": "Webhook (Premium)", + "description": "Allows you to trigger an external interface.", + "priority": 0, + "defaults": { + "handler": ["after"], + "method": ["create", "update", "delete"], + "priority": 0, + "name": "webhook", + "title": "Webhook (Premium)" + }, + "premium": true + }, + { + "name": "sql", + "title": "SQL Query", + "description": "Allows you to execute a remote SQL Query.", + "priority": 0, + "defaults": { + "handler": ["after"], + "method": ["create"], + "priority": 0, + "name": "sql", + "title": "SQL Query" + } + }, + { + "name": "role", + "title": "Role Assignment", + "description": "Provides the Role Assignment capabilities.", + "priority": 1, + "defaults": { + "handler": ["after"], + "method": ["create"], + "priority": 1, + "name": "role", + "title": "Role Assignment" + }, + "access": { + "handler": false, + "method": false + } + }, + { + "name": "resetpass", + "title": "Reset Password", + "description": "Provides a way to reset a password field.", + "defaults": { + "handler": ["after", "before"], + "method": ["form", "create"], + "priority": 0, + "name": "resetpass", + "title": "Reset Password" + }, + "access": { + "handler": false, + "method": false + } + }, + { + "name": "save", + "title": "Save Submission", + "description": "Saves the submission into the database.", + "priority": 10, + "defaults": { + "handler": ["before"], + "method": ["create", "update"], + "priority": 10, + "name": "save", + "title": "Save Submission" + }, + "access": { + "handler": false, + "method": false + } + }, + { + "name": "login", + "title": "Login", + "description": "Provides a way to login to the application.", + "priority": 2, + "defaults": { + "handler": ["before"], + "method": ["create"], + "priority": 2, + "name": "login", + "title": "Login" + }, + "access": { + "handler": false, + "method": false + } + }, + { + "name": "office365contact", + "title": "Office 365 Contacts (Premium)", + "description": "Allows you to integrate into your Office 365 Contacts.", + "priority": 0, + "defaults": { + "handler": ["after"], + "method": ["create", "update", "delete"], + "priority": 0, + "name": "office365contact", + "title": "Office 365 Contacts (Premium)" + }, + "premium": true + }, + { + "name": "office365calendar", + "title": "Office 365 Calendar (Premium)", + "description": "Allows you to integrate into your Office 365 Calendar.", + "premium": true, + "priority": 0, + "defaults": { + "handler": ["after"], + "method": ["create", "update", "delete"], + "priority": 0, + "name": "office365calendar", + "title": "Office 365 Calendar (Premium)" + } + }, + { + "name": "hubspotContact", + "title": "Hubspot Contact (Premium)", + "description": "Allows you to change contact fields in hubspot.", + "priority": 0, + "defaults": { + "handler": ["after"], + "method": ["create"], + "priority": 0, + "name": "hubspotContact", + "title": "Hubspot Contact (Premium)" + }, + "premium": true + }, + { + "name": "oauth", + "title": "OAuth (Premium)", + "description": "Provides OAuth authentication behavior to this form.", + "priority": 20, + "defaults": { + "handler": ["after"], + "method": ["form", "create"], + "priority": 20, + "name": "oauth", + "title": "OAuth (Premium)" + }, + "premium": true + }, + { + "name": "ldap", + "title": "LDAP Login (Premium)", + "description": "Provides ldap login.", + "priority": 3, + "defaults": { + "handler": ["before"], + "method": ["create"], + "priority": 3, + "name": "ldap", + "title": "LDAP Login (Premium)" + }, + "premium": true + }, + { + "name": "googlesheet", + "title": "Google Sheets (Premium)", + "description": "Allows you to integrate data into Google sheets.", + "priority": 0, + "defaults": { + "handler": ["after"], + "method": ["create", "update", "delete"], + "priority": 0, + "name": "googlesheet", + "title": "Google Sheets (Premium)" + }, + "premium": true + }, + { + "name": "sqlconnector", + "title": "SQL Connector (Premium)", + "description": "Allows you to execute a remote SQL Query via Resquel.", + "priority": 0, + "defaults": { + "handler": ["after"], + "method": ["create", "update", "delete"], + "priority": 0, + "name": "sqlconnector", + "title": "SQL Connector (Premium)" + }, + "premium": true + }, + { + "name": "jira", + "title": "Jira (Premium)", + "description": "Allows you to create issues within Jira.", + "priority": 0, + "defaults": { + "handler": ["after"], + "method": ["create", "update", "delete"], + "priority": 0, + "name": "jira", + "title": "Jira (Premium)" + }, + "premium": true + }, + { + "name": "group", + "title": "Group Assignment (Premium)", + "premium": true, + "description": "Provides the Group Assignment capabilities.", + "priority": 5, + "defaults": { + "handler": ["after"], + "method": ["create", "update", "delete"], + "priority": 5, + "name": "group", + "title": "Group Assignment (Premium)" + }, + "access": { + "handler": false, + "method": false + } + }, + { + "name": "twilioSMS", + "title": "Twilio SMS (Premium)", + "premium": true, + "description": "Allows you to send SMS to phone numbers.", + "priority": 0, + "defaults": { + "handler": ["after"], + "method": ["create"], + "priority": 0, + "name": "twilioSMS", + "title": "Twilio SMS (Premium)" + } + } +] diff --git a/packages/react-formio/src/components/actions-table/actionsTable.component.tsx b/packages/react-formio/src/components/actions-table/actionsTable.component.tsx index 8f9d7813..48f6c2a4 100644 --- a/packages/react-formio/src/components/actions-table/actionsTable.component.tsx +++ b/packages/react-formio/src/components/actions-table/actionsTable.component.tsx @@ -35,6 +35,7 @@ export function ActionsTable({
({ ); } - -Select.propTypes = { - label: PropTypes.string, - name: PropTypes.string.isRequired, - value: PropTypes.any, - required: PropTypes.bool, - onChange: PropTypes.func, - choices: PropTypes.array.isRequired -}; diff --git a/packages/react-formio/src/components/table/components/defaultCellOperations.component.tsx b/packages/react-formio/src/components/table/components/defaultCellOperations.component.tsx index f45fe6ee..9ec836cd 100644 --- a/packages/react-formio/src/components/table/components/defaultCellOperations.component.tsx +++ b/packages/react-formio/src/components/table/components/defaultCellOperations.component.tsx @@ -1,19 +1,32 @@ import React from "react"; -import { DefaultOperationButton } from "./defaultOperationButton.component"; +import { DefaultOperationButton, OperationButtonProps } from "./defaultOperationButton.component"; -export function DefaultCellOperations({ operations, row, onClick, ctx, i18n }: any) { +export interface DefaultCellOperationsProps { + operations: (OperationButtonProps & { + OperationButton: typeof DefaultOperationButton; + permissionsResolver?(data: unknown, ctx: any): boolean; + })[]; + row: any; + + onClick: (data: any, action: string) => void; + ctx: any; + i18n: (i18n: string) => string; +} + +export function DefaultCellOperations({ operations, row, onClick, ctx, i18n }: DefaultCellOperationsProps) { const data = row.original; return (
{operations - .filter(({ permissionsResolver }: any) => !permissionsResolver || permissionsResolver(data, ctx)) - .map(({ OperationButton = DefaultOperationButton, ...operation }: any) => { + .filter(({ permissionsResolver }) => !permissionsResolver || permissionsResolver(data, ctx)) + .map(({ OperationButton = DefaultOperationButton, ...operation }, index: number) => { return ( onClick(data, action)} data={data} i18n={i18n} diff --git a/packages/react-formio/src/components/table/components/defaultOperationButton.component.tsx b/packages/react-formio/src/components/table/components/defaultOperationButton.component.tsx index c9db210b..3471daaa 100644 --- a/packages/react-formio/src/components/table/components/defaultOperationButton.component.tsx +++ b/packages/react-formio/src/components/table/components/defaultOperationButton.component.tsx @@ -1,11 +1,10 @@ import classnames from "classnames"; -import React from "react"; +import { HTMLAttributes } from "react"; import { iconClass } from "../../../utils/iconClass"; import { stopPropagationWrapper } from "../../../utils/stopPropagationWrapper"; -export interface OperationButtonProps { - className?: string; +export interface OperationButtonProps extends Omit, "onClick"> { buttonType?: string; buttonSize?: string; buttonOutline?: boolean; @@ -15,6 +14,7 @@ export interface OperationButtonProps { icon?: string; title?: string; i18n?: (i18n: string) => string; + ctx?: any; } export function DefaultOperationButton(props: OperationButtonProps) { @@ -27,11 +27,16 @@ export function DefaultOperationButton(props: OperationButtonProps) { action, icon = "", title = "", - i18n = (f: string) => f + i18n = (f: string) => f, + data, + ctx, + ...otherProps } = props; return (