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 { CompatibleSchemaInitializer } from '../../../../application/schema-initializer/CompatibleSchemaInitializer';
import { useCollection } from '../../../../data-source';
import { useActionAvailable } from '../../useActionAvailable'; import { useActionAvailable } from '../../useActionAvailable';
const commonOptions = { const commonOptions = {
title: "{{t('Configure actions')}}", 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 { CompatibleSchemaInitializer } from '../../../../application/schema-initializer/CompatibleSchemaInitializer';
import { useCollection } from '../../../../data-source';
import { useActionAvailable } from '../../useActionAvailable'; import { useActionAvailable } from '../../useActionAvailable';
const commonOptions = { 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; 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, DEFAULT_DATA_SOURCE_KEY,
useCollection_deprecated, useCollection_deprecated,
useCollectionFilterOptions, useCollectionFilterOptions,
useCollectionRecordData,
useCompile, useCompile,
} from '@nocobase/client'; } from '@nocobase/client';
import { useMemo } from 'react'; import { useMemo } from 'react';
@ -22,13 +23,14 @@ export const useCustomRequestVariableOptions = () => {
const fieldsOptions = useCollectionFilterOptions(collection); const fieldsOptions = useCollectionFilterOptions(collection);
const userFieldOptions = useCollectionFilterOptions('users', DEFAULT_DATA_SOURCE_KEY); const userFieldOptions = useCollectionFilterOptions('users', DEFAULT_DATA_SOURCE_KEY);
const compile = useCompile(); const compile = useCompile();
const recordData = useCollectionRecordData();
const [fields, userFields] = useMemo(() => { const [fields, userFields] = useMemo(() => {
return [compile(fieldsOptions), compile(userFieldOptions)]; return [compile(fieldsOptions), compile(userFieldOptions)];
}, [fieldsOptions, userFieldOptions]); }, [fieldsOptions, userFieldOptions]);
return useMemo(() => { return useMemo(() => {
return [ return [
{ recordData && {
name: 'currentRecord', name: 'currentRecord',
title: t('Current record', { ns: 'client' }), title: t('Current record', { ns: 'client' }),
children: [...fields], children: [...fields],
@ -48,6 +50,6 @@ export const useCustomRequestVariableOptions = () => {
title: 'API token', title: 'API token',
children: null, children: null,
}, },
]; ].filter(Boolean);
}, [fields, userFields]); }, [recordData, t, fields, userFields]);
}; };

View File

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

View File

@ -92,6 +92,14 @@ const commonOptions = {
}, },
useVisible: () => useActionAvailable('create'), 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; 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. * 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 = { const commonOptions = {
title: "{{t('Configure actions')}}", title: "{{t('Configure actions')}}",
@ -37,6 +37,14 @@ const commonOptions = {
}, },
useVisible: () => useActionAvailable('create'), 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', 'x-align': 'right',
}, },
}, },
{
name: 'customRequest',
title: '{{t("Custom request")}}',
Component: 'CustomRequestInitializer',
schema: {
'x-action': 'customize:table:request:global',
},
},
], ],
}; };