Skip to content

Commit 774a094

Browse files
committed
fix: Move sidebar field to the top-level (#50)
1 parent a80a016 commit 774a094

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

packages/dev/src/payload-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export interface User {
178178
id?: string | null;
179179
}[]
180180
| null;
181+
sidebarField?: string | null;
181182
updatedAt: string;
182183
createdAt: string;
183184
enableAPIKey?: boolean | null;
@@ -330,6 +331,7 @@ export interface UsersSelect<T extends boolean = true> {
330331
credentialDeviceType?: T;
331332
id?: T;
332333
};
334+
sidebarField?: T;
333335
updatedAt?: T;
334336
createdAt?: T;
335337
enableAPIKey?: T;

packages/dev/src/payload/collections/users.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ const Users: CollectionConfig<"users"> = {
176176
}),
177177
],
178178
},
179+
{
180+
name: "sidebarField",
181+
type: "text",
182+
admin: {
183+
position: "sidebar",
184+
},
185+
},
179186
/* {
180187
name: "examples",
181188
type: "join",

packages/payload-authjs/src/payload/collection/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CollectionConfig, TabsField } from "payload";
1+
import type { CollectionConfig, Field, TabsField } from "payload";
22
import {
33
isEmailProviderAvailable,
44
isSessionStrategyDatabase,
@@ -93,8 +93,21 @@ export const generateUsersCollection = (
9393
],
9494
patchFields: collection.fields, // User defined fields
9595
});
96+
const { topLevelFields, restTabFields } = restFields.reduce(
97+
(acc, field) => {
98+
// Sidebar fields must put at the top level
99+
if (field.admin?.position === "sidebar") {
100+
acc.topLevelFields.push(field);
101+
} else {
102+
acc.restTabFields.push(field);
103+
}
104+
return acc;
105+
},
106+
{ topLevelFields: [] as Field[], restTabFields: [] as Field[] },
107+
);
96108
collection.fields = mergedFields;
97-
(collection.fields[1] as TabsField).tabs[0].fields.push(...restFields); // Add the rest fields to the general tab
109+
collection.fields.push(...topLevelFields); // Add top-level fields
110+
(collection.fields[1] as TabsField).tabs[0].fields.push(...restTabFields); // Add the rest fields to the general tab
98111

99112
// Override the access control
100113
collection.access = {

0 commit comments

Comments
 (0)