refactor: collection template support presetFieldsDisabled (#4159)

* refactor: collection template support presetFieldsDisabled

* refactor: code improve
This commit is contained in:
katherinehhh 2024-04-25 13:17:45 +08:00 committed by GitHub
parent 343b97de14
commit 2d66f4d44b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 1 deletions

View File

@ -145,6 +145,7 @@ export const AddCollectionAction = (props) => {
const { getTemplate, templates: collectionTemplates } = useCollectionManager_deprecated(); const { getTemplate, templates: collectionTemplates } = useCollectionManager_deprecated();
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [schema, setSchema] = useState({}); const [schema, setSchema] = useState({});
const [currentTemplate, setCurrentTemplate] = useState(null);
const compile = useCompile(); const compile = useCompile();
const { t } = useTranslation(); const { t } = useTranslation();
const items = useMemo(() => { const items = useMemo(() => {
@ -173,6 +174,7 @@ export const AddCollectionAction = (props) => {
}, },
onClick: (info) => { onClick: (info) => {
const schema = getSchema(getTemplate(info.key), category, compile); const schema = getSchema(getTemplate(info.key), category, compile);
setCurrentTemplate(getTemplate(info.key));
setSchema(schema); setSchema(schema);
setVisible(true); setVisible(true);
}, },
@ -199,6 +201,7 @@ export const AddCollectionAction = (props) => {
useCreateCollection, useCreateCollection,
record, record,
showReverseFieldConfig: true, showReverseFieldConfig: true,
presetFieldsDisabled: currentTemplate?.presetFieldsDisabled,
...scope, ...scope,
}} }}
/> />

View File

@ -194,8 +194,8 @@ export const PresetFields = observer(
type: 'checkbox', type: 'checkbox',
selectedRowKeys, selectedRowKeys,
getCheckboxProps: (record) => ({ getCheckboxProps: (record) => ({
disabled: form.values.template === 'file', // Column configuration not to be checked
name: record.name, name: record.name,
disabled: props?.disabled,
}), }),
onChange: (_, selectedRows) => { onChange: (_, selectedRows) => {
const fields = getDefaultCollectionFields(selectedRows, form.values); const fields = getDefaultCollectionFields(selectedRows, form.values);

View File

@ -64,6 +64,9 @@ export const defaultConfigurableProperties = {
`, `,
}, },
'x-component': PresetFields, 'x-component': PresetFields,
'x-component-props': {
disabled: '{{ presetFieldsDisabled }}',
},
}, },
}; };

View File

@ -139,6 +139,7 @@ export class FileCollectionTemplate extends CollectionTemplate {
}, },
], ],
}; };
presetFieldsDisabled = true;
configurableProperties = { configurableProperties = {
...getConfigurableProperties('title', 'name'), ...getConfigurableProperties('title', 'name'),
inherits: { inherits: {