Skip to content

Commit 35a5199

Browse files
authored
fix(next): returns proper document id type from init page result (#8700)
1 parent 3f2b828 commit 35a5199

File tree

6 files changed

+53
-39
lines changed

6 files changed

+53
-39
lines changed

packages/next/src/utilities/initPage/handleAdminPage.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
1-
import type { SanitizedCollectionConfig, SanitizedConfig, SanitizedGlobalConfig } from 'payload'
1+
import type {
2+
Payload,
3+
SanitizedCollectionConfig,
4+
SanitizedConfig,
5+
SanitizedGlobalConfig,
6+
} from 'payload'
27

38
import { getRouteWithoutAdmin, isAdminRoute } from './shared.js'
49

510
type Args = {
611
adminRoute: string
712
config: SanitizedConfig
13+
defaultIDType: Payload['db']['defaultIDType']
814
route: string
915
}
16+
1017
type RouteInfo = {
1118
collectionConfig?: SanitizedCollectionConfig
1219
collectionSlug?: string
13-
docID?: string
20+
docID?: number | string
1421
globalConfig?: SanitizedGlobalConfig
1522
globalSlug?: string
1623
}
1724

18-
export function getRouteInfo({ adminRoute, config, route }: Args): RouteInfo {
25+
export function getRouteInfo({ adminRoute, config, defaultIDType, route }: Args): RouteInfo {
1926
if (isAdminRoute({ adminRoute, config, route })) {
2027
const routeWithoutAdmin = getRouteWithoutAdmin({ adminRoute, route })
2128
const routeSegments = routeWithoutAdmin.split('/').filter(Boolean)
2229
const [entityType, entitySlug, createOrID] = routeSegments
2330
const collectionSlug = entityType === 'collections' ? entitySlug : undefined
2431
const globalSlug = entityType === 'globals' ? entitySlug : undefined
25-
const docID = collectionSlug && createOrID !== 'create' ? createOrID : undefined
32+
33+
const docID =
34+
collectionSlug && createOrID !== 'create'
35+
? defaultIDType === 'number'
36+
? Number(createOrID)
37+
: createOrID
38+
: undefined
2639

2740
let collectionConfig: SanitizedCollectionConfig | undefined
2841
let globalConfig: SanitizedGlobalConfig | undefined

packages/next/src/utilities/initPage/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export const initPage = async ({
146146
const { collectionConfig, collectionSlug, docID, globalConfig, globalSlug } = getRouteInfo({
147147
adminRoute,
148148
config: payload.config,
149+
defaultIDType: payload.db.defaultIDType,
149150
route,
150151
})
151152

packages/next/src/views/Account/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const Account: React.FC<AdminViewProps> = async ({
9595
docPermissions={docPermissions}
9696
hasPublishPermission={hasPublishPermission}
9797
hasSavePermission={hasSavePermission}
98-
id={user?.id.toString()}
98+
id={user?.id}
9999
initialData={data}
100100
initialState={formState}
101101
isEditing

packages/next/src/views/Versions/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const VersionsView: PayloadServerReactComponent<EditViewComponent> = asyn
4848
if (collectionSlug) {
4949
limitToUse = limitToUse || collectionConfig.admin.pagination.defaultLimit
5050
const whereQuery: {
51-
and: Array<{ parent?: { equals: string }; snapshot?: { not_equals: boolean } }>
51+
and: Array<{ parent?: { equals: number | string }; snapshot?: { not_equals: boolean } }>
5252
} = {
5353
and: [
5454
{

packages/payload/src/admin/views/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export type VisibleEntities = {
4848
export type InitPageResult = {
4949
collectionConfig?: SanitizedCollectionConfig
5050
cookies: Map<string, string>
51-
docID?: string
51+
docID?: number | string
5252
globalConfig?: SanitizedGlobalConfig
5353
languageOptions: LanguageOptions
5454
locale?: Locale

test/joins/payload-types.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface Config {
2222
'payload-migrations': PayloadMigration;
2323
};
2424
db: {
25-
defaultIDType: string;
25+
defaultIDType: number;
2626
};
2727
globals: {};
2828
locale: 'en' | 'es';
@@ -53,15 +53,15 @@ export interface UserAuthOperations {
5353
* via the `definition` "posts".
5454
*/
5555
export interface Post {
56-
id: string;
56+
id: number;
5757
title?: string | null;
58-
upload?: (string | null) | Upload;
59-
category?: (string | null) | Category;
60-
categories?: (string | Category)[] | null;
61-
categoriesLocalized?: (string | Category)[] | null;
58+
upload?: (number | null) | Upload;
59+
category?: (number | null) | Category;
60+
categories?: (number | Category)[] | null;
61+
categoriesLocalized?: (number | Category)[] | null;
6262
group?: {
63-
category?: (string | null) | Category;
64-
camelCaseCategory?: (string | null) | Category;
63+
category?: (number | null) | Category;
64+
camelCaseCategory?: (number | null) | Category;
6565
};
6666
updatedAt: string;
6767
createdAt: string;
@@ -71,9 +71,9 @@ export interface Post {
7171
* via the `definition` "uploads".
7272
*/
7373
export interface Upload {
74-
id: string;
74+
id: number;
7575
relatedPosts?: {
76-
docs?: (string | Post)[] | null;
76+
docs?: (number | Post)[] | null;
7777
hasNextPage?: boolean | null;
7878
} | null;
7979
updatedAt: string;
@@ -93,27 +93,27 @@ export interface Upload {
9393
* via the `definition` "categories".
9494
*/
9595
export interface Category {
96-
id: string;
96+
id: number;
9797
name?: string | null;
9898
relatedPosts?: {
99-
docs?: (string | Post)[] | null;
99+
docs?: (number | Post)[] | null;
100100
hasNextPage?: boolean | null;
101101
} | null;
102102
hasManyPosts?: {
103-
docs?: (string | Post)[] | null;
103+
docs?: (number | Post)[] | null;
104104
hasNextPage?: boolean | null;
105105
} | null;
106106
hasManyPostsLocalized?: {
107-
docs?: (string | Post)[] | null;
107+
docs?: (number | Post)[] | null;
108108
hasNextPage?: boolean | null;
109109
} | null;
110110
group?: {
111111
relatedPosts?: {
112-
docs?: (string | Post)[] | null;
112+
docs?: (number | Post)[] | null;
113113
hasNextPage?: boolean | null;
114114
} | null;
115115
camelCasePosts?: {
116-
docs?: (string | Post)[] | null;
116+
docs?: (number | Post)[] | null;
117117
hasNextPage?: boolean | null;
118118
} | null;
119119
};
@@ -125,9 +125,9 @@ export interface Category {
125125
* via the `definition` "localized-posts".
126126
*/
127127
export interface LocalizedPost {
128-
id: string;
128+
id: number;
129129
title?: string | null;
130-
category?: (string | null) | LocalizedCategory;
130+
category?: (number | null) | LocalizedCategory;
131131
updatedAt: string;
132132
createdAt: string;
133133
}
@@ -136,10 +136,10 @@ export interface LocalizedPost {
136136
* via the `definition` "localized-categories".
137137
*/
138138
export interface LocalizedCategory {
139-
id: string;
139+
id: number;
140140
name?: string | null;
141141
relatedPosts?: {
142-
docs?: (string | LocalizedPost)[] | null;
142+
docs?: (number | LocalizedPost)[] | null;
143143
hasNextPage?: boolean | null;
144144
} | null;
145145
updatedAt: string;
@@ -150,7 +150,7 @@ export interface LocalizedCategory {
150150
* via the `definition` "users".
151151
*/
152152
export interface User {
153-
id: string;
153+
id: number;
154154
updatedAt: string;
155155
createdAt: string;
156156
email: string;
@@ -167,36 +167,36 @@ export interface User {
167167
* via the `definition` "payload-locked-documents".
168168
*/
169169
export interface PayloadLockedDocument {
170-
id: string;
170+
id: number;
171171
document?:
172172
| ({
173173
relationTo: 'posts';
174-
value: string | Post;
174+
value: number | Post;
175175
} | null)
176176
| ({
177177
relationTo: 'categories';
178-
value: string | Category;
178+
value: number | Category;
179179
} | null)
180180
| ({
181181
relationTo: 'uploads';
182-
value: string | Upload;
182+
value: number | Upload;
183183
} | null)
184184
| ({
185185
relationTo: 'localized-posts';
186-
value: string | LocalizedPost;
186+
value: number | LocalizedPost;
187187
} | null)
188188
| ({
189189
relationTo: 'localized-categories';
190-
value: string | LocalizedCategory;
190+
value: number | LocalizedCategory;
191191
} | null)
192192
| ({
193193
relationTo: 'users';
194-
value: string | User;
194+
value: number | User;
195195
} | null);
196196
globalSlug?: string | null;
197197
user: {
198198
relationTo: 'users';
199-
value: string | User;
199+
value: number | User;
200200
};
201201
updatedAt: string;
202202
createdAt: string;
@@ -206,10 +206,10 @@ export interface PayloadLockedDocument {
206206
* via the `definition` "payload-preferences".
207207
*/
208208
export interface PayloadPreference {
209-
id: string;
209+
id: number;
210210
user: {
211211
relationTo: 'users';
212-
value: string | User;
212+
value: number | User;
213213
};
214214
key?: string | null;
215215
value?:
@@ -229,7 +229,7 @@ export interface PayloadPreference {
229229
* via the `definition` "payload-migrations".
230230
*/
231231
export interface PayloadMigration {
232-
id: string;
232+
id: number;
233233
name?: string | null;
234234
batch?: number | null;
235235
updatedAt: string;

0 commit comments

Comments
 (0)