feat(custom-request): support adding custom request in more places (#5320)

* feat(custom-request): support adding custom request buttons in more places

* fix: fix known issues
This commit is contained in:
Zeke Zhang 2024-09-25 22:27:24 +08:00 committed by GitHub
parent ef2811f148
commit 058e7e320d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 66 additions and 10 deletions

View File

@ -8,7 +8,6 @@
*/
import { CompatibleSchemaInitializer } from '../../../../application/schema-initializer/CompatibleSchemaInitializer';
import { useCollection } from '../../../../data-source';
import { useActionAvailable } from '../../useActionAvailable';
const commonOptions = {
title: "{{t('Configure actions')}}",
@ -73,6 +72,14 @@ const commonOptions = {
},
},
},
{
name: 'customRequest',
title: '{{t("Custom request")}}',
Component: 'CustomRequestInitializer',
schema: {
'x-action': 'customize:table:request:global',
},
},
],
};

View File

@ -8,7 +8,6 @@
*/
import { CompatibleSchemaInitializer } from '../../../../application/schema-initializer/CompatibleSchemaInitializer';
import { useCollection } from '../../../../data-source';
import { useActionAvailable } from '../../useActionAvailable';
const commonOptions = {
@ -74,6 +73,14 @@ const commonOptions = {
},
},
},
{
name: 'customRequest',
title: '{{t("Custom request")}}',
Component: 'CustomRequestInitializer',
schema: {
'x-action': 'customize:table:request:global',
},
},
],
};

View File

@ -90,6 +90,14 @@ const commonOptions = {
return collection.tree && treeTable;
},
},
{
name: 'customRequest',
title: '{{t("Custom request")}}',
Component: 'CustomRequestInitializer',
schema: {
'x-action': 'customize:table:request:global',
},
},
],
};

View File

@ -11,6 +11,7 @@ import {
DEFAULT_DATA_SOURCE_KEY,
useCollection_deprecated,
useCollectionFilterOptions,
useCollectionRecordData,
useCompile,
} from '@nocobase/client';
import { useMemo } from 'react';
@ -22,13 +23,14 @@ export const useCustomRequestVariableOptions = () => {
const fieldsOptions = useCollectionFilterOptions(collection);
const userFieldOptions = useCollectionFilterOptions('users', DEFAULT_DATA_SOURCE_KEY);
const compile = useCompile();
const recordData = useCollectionRecordData();
const [fields, userFields] = useMemo(() => {
return [compile(fieldsOptions), compile(userFieldOptions)];
}, [fieldsOptions, userFieldOptions]);
return useMemo(() => {
return [
{
recordData && {
name: 'currentRecord',
title: t('Current record', { ns: 'client' }),
children: [...fields],
@ -48,6 +50,6 @@ export const useCustomRequestVariableOptions = () => {
title: 'API token',
children: null,
},
];
}, [fields, userFields]);
].filter(Boolean);
}, [recordData, t, fields, userFields]);
};

View File

@ -7,20 +7,20 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { useFieldSchema } from '@formily/react';
import {
AfterSuccess,
ButtonEditor,
RefreshDataBlockRequest,
RemoveButton,
SchemaSettings,
SchemaSettingsLinkageRules,
SecondConFirm,
useCollection,
useSchemaToolbar,
RefreshDataBlockRequest,
useCollectionRecord,
useSchemaToolbar,
} from '@nocobase/client';
import { CustomRequestACL, CustomRequestSettingsItem } from './components/CustomRequestActionDesigner';
import { useFieldSchema } from '@formily/react';
export const customizeCustomRequestActionSettings = new SchemaSettings({
name: 'actionSettings:customRequest',
@ -48,7 +48,7 @@ export const customizeCustomRequestActionSettings = new SchemaSettings({
},
useVisible() {
const record = useCollectionRecord();
return record && !record?.isNew;
return record && record.data && !record?.isNew;
},
},
{

View File

@ -92,6 +92,14 @@ const commonOptions = {
},
useVisible: () => useActionAvailable('create'),
},
{
name: 'customRequest',
title: '{{t("Custom request")}}',
Component: 'CustomRequestInitializer',
schema: {
'x-action': 'customize:table:request:global',
},
},
],
};

View File

@ -75,6 +75,14 @@ const commonOptions = {
return collection.tree && treeTable;
},
},
{
name: 'customRequest',
title: '{{t("Custom request")}}',
Component: 'CustomRequestInitializer',
schema: {
'x-action': 'customize:table:request:global',
},
},
],
};

View File

@ -7,7 +7,7 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { CompatibleSchemaInitializer, useCollection, useActionAvailable } from '@nocobase/client';
import { CompatibleSchemaInitializer, useActionAvailable } from '@nocobase/client';
const commonOptions = {
title: "{{t('Configure actions')}}",
@ -37,6 +37,14 @@ const commonOptions = {
},
useVisible: () => useActionAvailable('create'),
},
{
name: 'customRequest',
title: '{{t("Custom request")}}',
Component: 'CustomRequestInitializer',
schema: {
'x-action': 'customize:table:request:global',
},
},
],
};

View File

@ -45,6 +45,14 @@ const commonOptions = {
'x-align': 'right',
},
},
{
name: 'customRequest',
title: '{{t("Custom request")}}',
Component: 'CustomRequestInitializer',
schema: {
'x-action': 'customize:table:request:global',
},
},
],
};