Skip to content

Commit d6a55b0

Browse files
feat: display friendly ct names (#622)
1 parent 0b963c0 commit d6a55b0

4 files changed

Lines changed: 11 additions & 13 deletions

File tree

admin/src/api/validators.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ export const configContentTypeSchema = z.object({
115115
collectionName: z.string(),
116116
contentTypeName: z.string(),
117117
label: z.string(),
118-
labelSingular: z.string(),
119118
endpoint: z.string(),
120119
available: z.boolean(),
121120
visible: z.boolean(),

admin/src/pages/HomePage/components/NavigationItemForm/components/RelatedTypeField/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const RelatedTypeField: React.FC<RelatedTypeFieldProps> = ({
4848
configQuery.data?.contentTypes.map((item) => ({
4949
key: item.uid,
5050
value: item.uid,
51-
label: item.contentTypeName,
51+
label: item.label,
5252
})),
5353
(item) => item.label
5454
),

server/src/dtos/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export type ConfigContentTypeDTO = {
1313
relatedField: string | undefined;
1414
templateName: string | undefined;
1515
available: boolean | undefined;
16-
labelSingular: string;
1716
endpoint: string;
1817
plugin: string | undefined;
1918
visible: boolean;
19+
gqlTypeName: string;
2020
};
2121

2222
export type NavigationPluginConfigDTO = Pick<

server/src/services/admin/admin.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const adminService = (context: { strapi: Core.Strapi }) => ({
8080
preferCustomContentTypes,
8181
} = config;
8282

83-
const isGQLPluginEnabled = !!strapi.plugin('graphql');
83+
const isGQLPluginEnabled = !!context.strapi.plugin('graphql');
8484

8585
let extendedResult: Record<string, unknown> = {
8686
allowedContentTypes: ALLOWED_CONTENT_TYPES,
@@ -103,9 +103,7 @@ const adminService = (context: { strapi: Core.Strapi }) => ({
103103
? additionalFields
104104
: additionalFields.filter((field) => typeof field === 'string' || !!field.enabled),
105105
gql: {
106-
navigationItemRelated: configContentTypes.map(({ labelSingular }) =>
107-
labelSingular.replace(/\s+/g, '')
108-
),
106+
navigationItemRelated: configContentTypes.map(({ gqlTypeName }) => gqlTypeName),
109107
},
110108
isGQLPluginEnabled: viaSettingsPage ? isGQLPluginEnabled : undefined,
111109
cascadeMenuAttached,
@@ -213,7 +211,7 @@ const adminService = (context: { strapi: Core.Strapi }) => ({
213211
}
214212

215213
const { visible = true } = pluginOptions['content-manager'] || {};
216-
const { name = '', description = '' } = info;
214+
const { description = '', displayName = '' } = info;
217215

218216
const findRouteConfig = find(
219217
get(context.strapi.api, `[${modelName}].config.routes`, []),
@@ -232,9 +230,10 @@ const adminService = (context: { strapi: Core.Strapi }) => ({
232230
relationNameParts.length > 1
233231
? relationNameParts.reduce((prev, curr) => `${prev}${upperFirst(curr)}`, '')
234232
: upperFirst(modelName);
235-
const labelSingular =
236-
name ||
237-
upperFirst(relationNameParts.length > 1 ? relationNameParts.join(' ') : relationName);
233+
234+
const gqlPlugin = context.strapi.plugin('graphql');
235+
const graphQlNamingPlugin = gqlPlugin?.service('utils');
236+
const gqlTypeName: string = graphQlNamingPlugin?.naming?.getTypeName(item) || '';
238237

239238
acc.push({
240239
uid,
@@ -244,14 +243,14 @@ const adminService = (context: { strapi: Core.Strapi }) => ({
244243
description,
245244
collectionName,
246245
contentTypeName,
247-
label: isSingle ? labelSingular : pluralize(name || labelSingular),
246+
label: displayName,
248247
relatedField: relatedField ? relatedField.alias : undefined,
249-
labelSingular: singularize(labelSingular),
250248
endpoint: endpoint!,
251249
plugin,
252250
available: isAvailable,
253251
visible,
254252
templateName: options?.templateName,
253+
gqlTypeName,
255254
});
256255

257256
return acc;

0 commit comments

Comments
 (0)