Skip to content

Commit 3d129e8

Browse files
fix(plugin-multi-tenant): missing key console message (#11693)
1 parent 6270d73 commit 3d129e8

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

docs/plugins/multi-tenant.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
162162
/**
163163
* Customize tenant selector label
164164
*
165-
* Either a string or an object where the keys are locales and the values are the string labels
165+
* Either a string or an object where the keys are i18n codes and the values are the string labels
166166
*/
167167
tenantSelectorLabel?:
168168
| Partial<{

packages/plugin-multi-tenant/README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
8686
* Access configuration for the array field
8787
*/
8888
arrayFieldAccess?: ArrayField['access']
89+
/**
90+
* Name of the array field
91+
*
92+
* @default 'tenants'
93+
*/
94+
arrayFieldName?: string
95+
/**
96+
* Name of the tenant field
97+
*
98+
* @default 'tenant'
99+
*/
100+
arrayTenantFieldName?: string
89101
/**
90102
* When `includeDefaultField` is `true`, the field will be added to the users collection automatically
91103
*/
@@ -101,13 +113,25 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
101113
}
102114
| {
103115
arrayFieldAccess?: never
116+
arrayFieldName?: string
117+
arrayTenantFieldName?: string
104118
/**
105119
* When `includeDefaultField` is `false`, you must include the field on your users collection manually
106120
*/
107121
includeDefaultField?: false
108122
rowFields?: never
109123
tenantFieldAccess?: never
110124
}
125+
/**
126+
* Customize tenant selector label
127+
*
128+
* Either a string or an object where the keys are i18n codes and the values are the string labels
129+
*/
130+
tenantSelectorLabel?:
131+
| Partial<{
132+
[key in AcceptedLanguages]?: string
133+
}>
134+
| string
111135
/**
112136
* The slug for the tenant collection
113137
*
@@ -120,8 +144,20 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
120144
* Useful for super-admin type users
121145
*/
122146
userHasAccessToAllTenants?: (
123-
user: ConfigTypes extends { user } ? ConfigTypes['user'] : User,
147+
user: ConfigTypes extends { user: unknown } ? ConfigTypes['user'] : User,
124148
) => boolean
149+
/**
150+
* Opt out of adding access constraints to the tenants collection
151+
*/
152+
useTenantsCollectionAccess?: boolean
153+
/**
154+
* Opt out including the baseListFilter to filter tenants by selected tenant
155+
*/
156+
useTenantsListFilter?: boolean
157+
/**
158+
* Opt out including the baseListFilter to filter users by selected tenant
159+
*/
160+
useUsersTenantFilter?: boolean
125161
}
126162
```
127163
@@ -159,7 +195,7 @@ import { Config as ConfigTypes } from './payload-types'
159195
// Add the plugin to your payload config
160196
export default buildConfig({
161197
plugins: [
162-
multiTenantPlugin({
198+
multiTenantPlugin<ConfigTypes>({
163199
collections: {
164200
media: {
165201
useTenantAccess: false,

packages/plugin-multi-tenant/src/components/TenantSelector/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
import type { ReactSelectOption } from '@payloadcms/ui'
33
import type { ViewTypes } from 'payload'
44

5-
import './index.scss'
6-
5+
import { getTranslation } from '@payloadcms/translations'
76
import { SelectInput, useTranslation } from '@payloadcms/ui'
87
import React from 'react'
98

109
import { useTenantSelection } from '../../providers/TenantSelectionProvider/index.client.js'
10+
import './index.scss'
1111

1212
export const TenantSelector = ({ label, viewType }: { label: string; viewType?: ViewTypes }) => {
1313
const { options, selectedTenantID, setTenant } = useTenantSelection()
14-
const { t } = useTranslation()
14+
const { i18n } = useTranslation()
1515

1616
const handleChange = React.useCallback(
1717
(option: ReactSelectOption | ReactSelectOption[]) => {
@@ -32,7 +32,7 @@ export const TenantSelector = ({ label, viewType }: { label: string; viewType?:
3232
<div className="tenant-selector">
3333
<SelectInput
3434
isClearable={viewType === 'list'}
35-
label={t(label as any)}
35+
label={getTranslation(label, i18n)}
3636
name="setTenant"
3737
onChange={handleChange}
3838
options={options}

packages/plugin-multi-tenant/src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const multiTenantPlugin =
3737
pluginConfig?.tenantsArrayField?.arrayFieldName || defaults.tenantsArrayFieldName
3838
const tenantsArrayTenantFieldName =
3939
pluginConfig?.tenantsArrayField?.arrayTenantFieldName || defaults.tenantsArrayTenantFieldName
40-
let tenantSelectorLabel = pluginConfig.tenantSelectorLabel || defaults.tenantSelectorLabel
40+
const tenantSelectorLabel = pluginConfig.tenantSelectorLabel || defaults.tenantSelectorLabel
4141

4242
/**
4343
* Add defaults for admin properties
@@ -68,11 +68,11 @@ export const multiTenantPlugin =
6868
/**
6969
* Add tenant selector localized labels
7070
*/
71-
if (pluginConfig.tenantSelectorLabel && typeof pluginConfig.tenantSelectorLabel === 'object') {
71+
if (typeof tenantSelectorLabel === 'object') {
7272
if (!incomingConfig.i18n) {
7373
incomingConfig.i18n = {}
7474
}
75-
Object.entries(pluginConfig.tenantSelectorLabel).forEach(([_locale, label]) => {
75+
Object.entries(tenantSelectorLabel).forEach(([_locale, label]) => {
7676
const locale = _locale as AcceptedLanguages
7777
if (!incomingConfig.i18n) {
7878
incomingConfig.i18n = {}
@@ -93,7 +93,6 @@ export const multiTenantPlugin =
9393
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
9494
// @ts-expect-error
9595
incomingConfig.i18n.translations[locale].multiTenant.selectorLabel = label
96-
tenantSelectorLabel = 'multiTenant:selectorLabel'
9796
})
9897
}
9998

packages/plugin-multi-tenant/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export type MultiTenantPluginConfig<ConfigTypes = unknown> = {
111111
/**
112112
* Customize tenant selector label
113113
*
114-
* Either a string or an object where the keys are locales and the values are the string labels
114+
* Either a string or an object where the keys are i18n codes and the values are the string labels
115115
*/
116116
tenantSelectorLabel?:
117117
| Partial<{

0 commit comments

Comments
 (0)