diff --git a/docs/plugins/multi-tenant.mdx b/docs/plugins/multi-tenant.mdx index 29c68f4465..544efd71a2 100644 --- a/docs/plugins/multi-tenant.mdx +++ b/docs/plugins/multi-tenant.mdx @@ -80,13 +80,18 @@ type MultiTenantPluginConfig = { * @default false */ isGlobal?: boolean + /** + * Opt out of adding the tenant field and place + * it manually using the `tenantField` export from the plugin + */ + customTenantField?: boolean /** * Overrides for the tenant field, will override the entire tenantField configuration */ tenantFieldOverrides?: CollectionTenantFieldConfigOverrides /** - * Set to `false` if you want to manually apply - * the baseFilter + * Set to `false` if you want to manually apply the baseListFilter + * Set to `false` if you want to manually apply the baseFilter * * @default true */ diff --git a/packages/plugin-multi-tenant/src/components/TenantField/index.client.tsx b/packages/plugin-multi-tenant/src/components/TenantField/index.client.tsx index 477a8782c2..a657a82b11 100644 --- a/packages/plugin-multi-tenant/src/components/TenantField/index.client.tsx +++ b/packages/plugin-multi-tenant/src/components/TenantField/index.client.tsx @@ -53,7 +53,7 @@ export const TenantField = (args: Props) => { } }, [args.unique, options, selectedTenantID, setTenant, value, setEntityType, entityType]) - if (options.length > 1) { + if (options.length > 1 && !args.field.admin?.hidden && !args.field.hidden) { return ( <>
@@ -64,7 +64,7 @@ export const TenantField = (args: Props) => { ...args.field, required: true, }} - readOnly={args.readOnly || args.unique} + readOnly={args.readOnly || args.field.admin?.readOnly || args.unique} />
diff --git a/packages/plugin-multi-tenant/src/exports/fields.ts b/packages/plugin-multi-tenant/src/exports/fields.ts index b333696f27..7dd1ac4477 100644 --- a/packages/plugin-multi-tenant/src/exports/fields.ts +++ b/packages/plugin-multi-tenant/src/exports/fields.ts @@ -1 +1,2 @@ +export { tenantField } from '../fields/tenantField/index.js' export { tenantsArrayField } from '../fields/tenantsArrayField/index.js' diff --git a/packages/plugin-multi-tenant/src/exports/utilities.ts b/packages/plugin-multi-tenant/src/exports/utilities.ts index 07f232a71f..78190c57e4 100644 --- a/packages/plugin-multi-tenant/src/exports/utilities.ts +++ b/packages/plugin-multi-tenant/src/exports/utilities.ts @@ -1,3 +1,4 @@ +export { defaults } from '../defaults.js' export { filterDocumentsByTenants as getTenantListFilter } from '../filters/filterDocumentsByTenants.js' export { getGlobalViewRedirect } from '../utilities/getGlobalViewRedirect.js' export { getTenantAccess } from '../utilities/getTenantAccess.js' diff --git a/packages/plugin-multi-tenant/src/index.ts b/packages/plugin-multi-tenant/src/index.ts index 39fbc40466..0328a9fd3a 100644 --- a/packages/plugin-multi-tenant/src/index.ts +++ b/packages/plugin-multi-tenant/src/index.ts @@ -178,24 +178,24 @@ export const multiTenantPlugin = tenantsCollectionSlug, }) - const overrides = pluginConfig.collections[collection.slug]?.tenantFieldOverrides - ? pluginConfig.collections[collection.slug]?.tenantFieldOverrides - : pluginConfig.tenantField || {} - - /** - * Add tenant field to enabled collections - */ - collection.fields.unshift( - tenantField({ - name: tenantFieldName, - debug: pluginConfig.debug, - overrides, - tenantsArrayFieldName, - tenantsArrayTenantFieldName, - tenantsCollectionSlug, - unique: false, - }), - ) + if (pluginConfig.collections[foldersSlug]?.customTenantField !== true) { + /** + * Add tenant field to enabled collections + */ + collection.fields.unshift( + tenantField({ + name: tenantFieldName, + debug: pluginConfig.debug, + overrides: pluginConfig.collections[collection.slug]?.tenantFieldOverrides + ? pluginConfig.collections[collection.slug]?.tenantFieldOverrides + : pluginConfig.tenantField || {}, + tenantsArrayFieldName, + tenantsArrayTenantFieldName, + tenantsCollectionSlug, + unique: false, + }), + ) + } const { useBaseFilter, useBaseListFilter } = pluginConfig.collections[collection.slug] || {} if (useBaseFilter ?? useBaseListFilter ?? true) { @@ -348,24 +348,24 @@ export const multiTenantPlugin = tenantsCollectionSlug, }) - const overrides = pluginConfig.collections[collection.slug]?.tenantFieldOverrides - ? pluginConfig.collections[collection.slug]?.tenantFieldOverrides - : pluginConfig.tenantField || {} - - /** - * Add tenant field to enabled collections - */ - collection.fields.unshift( - tenantField({ - name: tenantFieldName, - debug: pluginConfig.debug, - overrides, - tenantsArrayFieldName, - tenantsArrayTenantFieldName, - tenantsCollectionSlug, - unique: isGlobal, - }), - ) + if (pluginConfig.collections[collection.slug]?.customTenantField !== true) { + /** + * Add tenant field to enabled collections + */ + collection.fields.unshift( + tenantField({ + name: tenantFieldName, + debug: pluginConfig.debug, + overrides: pluginConfig.collections[collection.slug]?.tenantFieldOverrides + ? pluginConfig.collections[collection.slug]?.tenantFieldOverrides + : pluginConfig.tenantField || {}, + tenantsArrayFieldName, + tenantsArrayTenantFieldName, + tenantsCollectionSlug, + unique: isGlobal, + }), + ) + } const { useBaseFilter, useBaseListFilter } = pluginConfig.collections[collection.slug] || {} if (useBaseFilter ?? useBaseListFilter ?? true) { diff --git a/packages/plugin-multi-tenant/src/types.ts b/packages/plugin-multi-tenant/src/types.ts index 7b87c90a3e..0374bc9a5f 100644 --- a/packages/plugin-multi-tenant/src/types.ts +++ b/packages/plugin-multi-tenant/src/types.ts @@ -30,6 +30,11 @@ export type MultiTenantPluginConfig = { */ collections: { [key in CollectionSlug]?: { + /** + * Opt out of adding the tenant field and place + * it manually using the `tenantField` export from the plugin + */ + customTenantField?: boolean /** * Set to `true` if you want the collection to behave as a global * diff --git a/packages/ui/src/elements/FolderView/FolderTypeField/index.tsx b/packages/ui/src/elements/FolderView/FolderTypeField/index.tsx index 3ac8125945..16b07ed88b 100644 --- a/packages/ui/src/elements/FolderView/FolderTypeField/index.tsx +++ b/packages/ui/src/elements/FolderView/FolderTypeField/index.tsx @@ -102,39 +102,37 @@ export const FolderTypeField = ({ const styles = React.useMemo(() => mergeFieldStyles(field), [field]) return ( -
- - selectFilterOptions?.some( - (option) => (typeof option === 'string' ? option : option.value) === value, - ) - : undefined - } - hasMany={hasMany} - isClearable={isClearable} - isSortable={isSortable} - Label={Label} - label={label} - localized={localized} - name={name} - onChange={onChange} - options={options} - path={path} - placeholder={placeholder} - readOnly={readOnly || disabled} - required={required || (Array.isArray(folderType) && folderType.length > 0)} - showError={showError} - style={styles} - value={value as string | string[]} - /> -
+ + selectFilterOptions?.some( + (option) => (typeof option === 'string' ? option : option.value) === value, + ) + : undefined + } + hasMany={hasMany} + isClearable={isClearable} + isSortable={isSortable} + Label={Label} + label={label} + localized={localized} + name={name} + onChange={onChange} + options={options} + path={path} + placeholder={placeholder} + readOnly={readOnly || disabled} + required={required || (Array.isArray(folderType) && folderType.length > 0)} + showError={showError} + style={styles} + value={value as string | string[]} + /> ) }