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

View File

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

View File

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

View File

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