diff --git a/packages/payload/src/admin/fields/Tabs.ts b/packages/payload/src/admin/fields/Tabs.ts index 605706fa9d8..f37cdfaea8a 100644 --- a/packages/payload/src/admin/fields/Tabs.ts +++ b/packages/payload/src/admin/fields/Tabs.ts @@ -3,11 +3,9 @@ import type { MarkOptional } from 'ts-essentials' import type { ClientField, NamedTab, - NamedTabWithCondition, TabsField, TabsFieldClient, UnnamedTab, - UnnamedTabWithCondition, } from '../../fields/config/types.js' import type { FieldErrorClientComponent, FieldErrorServerComponent } from '../forms/Error.js' import type { @@ -24,10 +22,8 @@ import type { } from '../types.js' export type ClientTab = - | ({ fields: ClientField[] } & Omit) - | ({ fields: ClientField[] } & Omit) - | ({ fields: ClientField[]; passesCondition: boolean } & Omit) - | ({ fields: ClientField[]; passesCondition: boolean } & Omit) + | ({ fields: ClientField[]; passesCondition?: boolean } & Omit) + | ({ fields: ClientField[]; passesCondition?: boolean } & Omit) type TabsFieldClientWithoutType = MarkOptional diff --git a/packages/payload/src/config/sanitize.ts b/packages/payload/src/config/sanitize.ts index 4950c5e8f95..010437196c2 100644 --- a/packages/payload/src/config/sanitize.ts +++ b/packages/payload/src/config/sanitize.ts @@ -18,7 +18,6 @@ import { sanitizeGlobals } from '../globals/config/sanitize.js' import { getLockedDocumentsCollection } from '../lockedDocuments/lockedDocumentsCollection.js' import getPreferencesCollection from '../preferences/preferencesCollection.js' import checkDuplicateCollections from '../utilities/checkDuplicateCollections.js' -import checkDuplicateTabsIds from '../utilities/checkDuplicateTabsIds.js' import { defaults } from './defaults.js' const sanitizeAdminConfig = (configToSanitize: Config): Partial => { @@ -201,8 +200,6 @@ export const sanitizeConfig = async (incomingConfig: Config): Promise[] = [] for (const sanitizeFunction of richTextSanitizationPromises) { promises.push(sanitizeFunction(config as SanitizedConfig)) diff --git a/packages/payload/src/fields/config/types.ts b/packages/payload/src/fields/config/types.ts index fb60fb87c7d..6b9a5c7bd2b 100644 --- a/packages/payload/src/fields/config/types.ts +++ b/packages/payload/src/fields/config/types.ts @@ -766,6 +766,9 @@ export type CollapsibleFieldClient = { Pick type TabBase = { + admin?: { + condition?: Pick + } description?: Description fields: Field[] interfaceName?: string @@ -782,10 +785,6 @@ export type NamedTab = { interfaceName?: string } & TabBase -export type NamedTabWithCondition = { - admin?: Pick -} & NamedTab - export type UnnamedTab = { interfaceName?: never /** @@ -802,30 +801,26 @@ export type UnnamedTab = { localized?: never } & Omit -export type UnnamedTabWithCondition = { - admin?: Pick -} & UnnamedTab - -export type TabWithoutCondition = NamedTab | UnnamedTab -export type TabWithCondition = NamedTabWithCondition | UnnamedTabWithCondition -export type Tab = TabWithCondition | TabWithoutCondition +export type Tab = NamedTab | UnnamedTab export type TabsField = { admin?: Omit type: 'tabs' -} & ({ id: string; tabs: TabWithCondition[] } | { id?: never; tabs: TabWithoutCondition[] }) & - Omit +} & { id: string; tabs: Tab[] } & Omit< + FieldBase, + 'admin' | 'localized' | 'name' | 'saveToJWT' | 'virtual' + > export type TabsFieldClient = { admin?: Omit tabs: ClientTab[] } & Omit & - Pick + Pick export type TabAsField = { name?: string type: 'tab' -} & TabWithCondition +} & Tab export type TabAsFieldClient = ClientTab & Pick diff --git a/packages/payload/src/index.ts b/packages/payload/src/index.ts index 726b6a5a882..c8caf1f9971 100644 --- a/packages/payload/src/index.ts +++ b/packages/payload/src/index.ts @@ -906,7 +906,6 @@ export type { Labels, LabelsClient, NamedTab, - NamedTabWithCondition, NonPresentationalField, NonPresentationalFieldClient, NumberField, @@ -942,7 +941,6 @@ export type { UIField, UIFieldClient, UnnamedTab, - UnnamedTabWithCondition, UploadField, UploadFieldClient, Validate, diff --git a/packages/payload/src/utilities/checkDuplicateTabsIds.ts b/packages/payload/src/utilities/checkDuplicateTabsIds.ts deleted file mode 100644 index 20c13354f99..00000000000 --- a/packages/payload/src/utilities/checkDuplicateTabsIds.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { SanitizedCollectionConfig } from '../collections/config/types.js' - -import { DuplicateTabsIds } from '../errors/DuplicateTabsIds.js' -import { traverseFields } from './traverseFields.js' - -const getDuplicates = (arr: string[]) => arr.filter((item, index) => arr.indexOf(item) !== index) - -const checkDuplicateTabsIds = (collections: SanitizedCollectionConfig[]): void => { - collections.forEach((collection) => { - const fields = collection.fields - const tabIds: string[] = [] - - traverseFields({ - callback: ({ field }) => { - if (field.type === 'tabs' && field.id) { - tabIds.push(field.id) - } - }, - fields, - }) - - const duplicateTabIds = getDuplicates(tabIds) - - if (duplicateTabIds.length > 0) { - throw new DuplicateTabsIds(duplicateTabIds) - } - }) -} - -export default checkDuplicateTabsIds