Skip to content

Commit 858aab5

Browse files
authored
fix: content type settings (#526), selecting entities (#527, #524) (#529)
1 parent 433c343 commit 858aab5

File tree

8 files changed

+661
-645
lines changed

8 files changed

+661
-645
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Complete installation requirements are exact same as for Strapi itself and can b
113113

114114
**Supported Strapi versions**:
115115

116-
- Strapi v5.9.0 (recently tested)
116+
- Strapi v5.10.3 (recently tested)
117117
- Strapi v5.x
118118

119119
> This plugin is designed for **Strapi v5** and is not working with v4.x. To get version for **Strapi v4** install version [v4.x](https://github.com/VirtusLab-Open-Source/strapi-plugin-navigation/tree/strapi-v4).

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { Grid, Modal, Toggle } from '@strapi/design-system';
99
import {
1010
Box,
1111
Button,
12+
Combobox,
13+
ComboboxOption,
1214
Divider,
1315
MultiSelect,
1416
MultiSelectOption,
@@ -544,8 +546,9 @@ export const NavigationItemForm: React.FC<NavigationItemFormProps> = ({
544546
return (
545547
<>
546548
<Modal.Body>
547-
<Form method="POST" initialValues={formValue}>
549+
<Form width="auto" height="auto" method="POST" initialValues={formValue}>
548550
{({ values, onChange }) => {
551+
console.log('values', values);
549552
const internalValues =
550553
values.type === 'INTERNAL'
551554
? values
@@ -740,21 +743,34 @@ export const NavigationItemForm: React.FC<NavigationItemFormProps> = ({
740743
: undefined
741744
}
742745
>
743-
<SingleSelect
746+
<Combobox
744747
name="relatedType"
745-
onChange={(eventOrPath: FormChangeEvent) =>
746-
handleChange('relatedType', eventOrPath, onChange)
748+
autocomplete="both"
749+
onClear={() => {
750+
handleChange('relatedType', undefined, onChange);
751+
handleChange('related', undefined, onChange);
752+
if (values.autoSync) {
753+
handleChange('title', undefined, onChange);
754+
}
755+
}}
756+
onChange={(eventOrPath: FormChangeEvent) => {
757+
handleChange('relatedType', eventOrPath, onChange);
758+
handleChange('related', undefined, onChange);
759+
if (values.autoSync) {
760+
handleChange('title', undefined, onChange);
761+
}
762+
}
747763
}
748764
value={values.relatedType}
749765
disabled={!configQuery.data?.contentTypes.length || !canUpdate}
750766
width="100%"
751767
>
752768
{configQuery.data?.contentTypes.map((contentType) => (
753-
<SingleSelectOption key={contentType.uid} value={contentType.uid}>
769+
<ComboboxOption key={contentType.uid} value={contentType.uid}>
754770
{contentType.contentTypeName}
755-
</SingleSelectOption>
771+
</ComboboxOption>
756772
))}
757-
</SingleSelect>
773+
</Combobox>
758774
</Field>
759775
</Grid.Item>
760776

@@ -776,8 +792,10 @@ export const NavigationItemForm: React.FC<NavigationItemFormProps> = ({
776792
: undefined
777793
}
778794
>
779-
<SingleSelect
795+
<Combobox
780796
name="related"
797+
autocomplete="both"
798+
onClear={() => handleChange('related', undefined, onChange)}
781799
onChange={(eventOrPath: FormChangeEvent) =>
782800
handleChange('related', eventOrPath, onChange)
783801
}
@@ -787,11 +805,11 @@ export const NavigationItemForm: React.FC<NavigationItemFormProps> = ({
787805
width="100%"
788806
>
789807
{relatedSelectOptions.map(({ key, label, value }) => (
790-
<SingleSelectOption key={key} value={value}>
808+
<ComboboxOption key={key} value={value}>
791809
{label}
792-
</SingleSelectOption>
810+
</ComboboxOption>
793811
))}
794-
</SingleSelect>
812+
</Combobox>
795813
</Field>
796814
</Grid.Item>
797815
)}

admin/src/pages/HomePage/components/NavigationItemListItem/index.tsx

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ export const Item: React.FC<Props> = ({
109109
const absolutePath = isExternal
110110
? undefined
111111
: `${levelPath === '/' ? '' : levelPath}/${mappedItem.path === '/' ? '' : mappedItem.path}`.replace(
112-
'//',
113-
'/'
114-
);
112+
'//',
113+
'/'
114+
);
115115

116116
const contentTypeItemsQuery = useContentTypeItems({
117117
uid: mappedItem.type === 'INTERNAL' ? (mappedItem.relatedType ?? '') : '',
@@ -124,6 +124,8 @@ export const Item: React.FC<Props> = ({
124124
mappedItem.type === 'INTERNAL' ? _.uid === mappedItem.relatedType : false
125125
);
126126

127+
const isContentManagerType = contentType?.uid.includes('api::');
128+
127129
const relatedItem = contentTypeItemsQuery.data?.find((contentTypeItem) =>
128130
mappedItem.type === 'INTERNAL' ? contentTypeItem.documentId === mappedItem.related : false
129131
) ?? { documentId: '', id: 0 };
@@ -295,48 +297,48 @@ export const Item: React.FC<Props> = ({
295297
item:
296298
item.type === 'INTERNAL'
297299
? {
300+
...item,
301+
type: 'INTERNAL',
302+
isMenuAllowedLevel,
303+
isParentAttachedToMenu,
304+
isSearchActive: false,
305+
relatedType: relatedType ?? '',
306+
related: related ?? '',
307+
additionalFields: item.additionalFields ?? {},
308+
items: item.items ?? [],
309+
autoSync: item.autoSync ?? true,
310+
externalPath: undefined,
311+
viewParentId,
312+
audience: item.audience?.map(({ documentId }) => documentId) ?? [],
313+
}
314+
: item.type === 'EXTERNAL'
315+
? {
298316
...item,
299-
type: 'INTERNAL',
317+
type: 'EXTERNAL',
300318
isMenuAllowedLevel,
301319
isParentAttachedToMenu,
302320
isSearchActive: false,
303-
relatedType: relatedType ?? '',
304-
related: related ?? '',
321+
relatedType: undefined,
322+
related: undefined,
305323
additionalFields: item.additionalFields ?? {},
306324
items: item.items ?? [],
307325
autoSync: item.autoSync ?? true,
308-
externalPath: undefined,
326+
externalPath: item.externalPath ?? '',
309327
viewParentId,
310328
audience: item.audience?.map(({ documentId }) => documentId) ?? [],
311329
}
312-
: item.type === 'EXTERNAL'
313-
? {
314-
...item,
315-
type: 'EXTERNAL',
316-
isMenuAllowedLevel,
317-
isParentAttachedToMenu,
318-
isSearchActive: false,
319-
relatedType: undefined,
320-
related: undefined,
321-
additionalFields: item.additionalFields ?? {},
322-
items: item.items ?? [],
323-
autoSync: item.autoSync ?? true,
324-
externalPath: item.externalPath ?? '',
325-
viewParentId,
326-
audience: item.audience?.map(({ documentId }) => documentId) ?? [],
327-
}
328330
: {
329-
...item,
330-
type: 'WRAPPER',
331-
isMenuAllowedLevel,
332-
isParentAttachedToMenu,
333-
isSearchActive: false,
334-
additionalFields: item.additionalFields ?? {},
335-
items: item.items ?? [],
336-
autoSync: item.autoSync ?? true,
337-
viewParentId,
338-
audience: item.audience?.map(({ documentId }) => documentId) ?? [],
339-
},
331+
...item,
332+
type: 'WRAPPER',
333+
isMenuAllowedLevel,
334+
isParentAttachedToMenu,
335+
isSearchActive: false,
336+
additionalFields: item.additionalFields ?? {},
337+
items: item.items ?? [],
338+
autoSync: item.autoSync ?? true,
339+
viewParentId,
340+
audience: item.audience?.map(({ documentId }) => documentId) ?? [],
341+
},
340342
levelPath,
341343
isParentAttachedToMenu,
342344
});
@@ -415,12 +417,12 @@ export const Item: React.FC<Props> = ({
415417
<Typography variant="omega" textColor="neutral800">
416418
{relatedItemLabel}
417419
</Typography>
418-
<Link
420+
{isContentManagerType && (<Link
419421
href={generatePreviewUrl(relatedItem ?? undefined)}
420422
endIcon={<ArrowRight />}
421423
>
422424
&nbsp;
423-
</Link>
425+
</Link>)}
424426
</Flex>
425427
)}
426428
</Flex>

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strapi-plugin-navigation",
3-
"version": "3.0.7",
3+
"version": "3.0.8",
44
"description": "Strapi - Navigation plugin",
55
"strapi": {
66
"name": "navigation",
@@ -40,7 +40,7 @@
4040
}
4141
],
4242
"dependencies": {
43-
"@sensinum/strapi-utils": "^1.0.6",
43+
"@sensinum/strapi-utils": "^1.0.7",
4444
"@sindresorhus/slugify": "1.1.0",
4545
"@tanstack/react-query": "^5.40.0",
4646
"pluralize": "8.0.0",
@@ -54,13 +54,13 @@
5454
"@faker-js/faker": "^9.0.3",
5555
"@jest/types": "29.5.x",
5656
"@koa/router": "^12.0.1",
57-
"@strapi/design-system": "2.0.0-rc.14",
58-
"@strapi/icons": "2.0.0-rc.14",
59-
"@strapi/plugin-graphql": "^5.9.0",
60-
"@strapi/sdk-plugin": "^5.3.0",
61-
"@strapi/strapi": "^5.9.0",
62-
"@strapi/types": "^5.9.0",
63-
"@strapi/typescript-utils": "^5.9.0",
57+
"@strapi/design-system": "2.0.0-rc.16",
58+
"@strapi/icons": "2.0.0-rc.16",
59+
"@strapi/plugin-graphql": "^5.10.3",
60+
"@strapi/sdk-plugin": "^5.3.2",
61+
"@strapi/strapi": "^5.10.3",
62+
"@strapi/types": "^5.10.3",
63+
"@strapi/typescript-utils": "^5.10.3",
6464
"@types/jest": "^29.5.12",
6565
"@types/koa": "^2.15.0",
6666
"@types/koa-bodyparser": "^4.3.12",
@@ -94,10 +94,10 @@
9494
"typescript": "^5.6.2"
9595
},
9696
"peerDependencies": {
97-
"@strapi/design-system": "^2.0.0-rc.14",
98-
"@strapi/icons": "^2.0.0-rc.14",
99-
"@strapi/sdk-plugin": "^5.3.0",
100-
"@strapi/strapi": "^5.9.0",
97+
"@strapi/design-system": "^2.0.0-rc.16",
98+
"@strapi/icons": "^2.0.0-rc.16",
99+
"@strapi/sdk-plugin": "^5.3.2",
100+
"@strapi/strapi": "^5.10.3",
101101
"lodash": "^4.17.21",
102102
"react": "^18.3.1",
103103
"react-dom": "^18.3.1",

server/src/config/setup.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@ import {
1414
PluginConfigPopulate,
1515
} from '../types';
1616
import { assertNotEmpty, resolveGlobalLikeId, validateAdditionalFields } from '../utils';
17+
import { isEmpty } from 'lodash';
1718

1819
type PluginDefaultConfigGetter = (
1920
key: PluginConfigKeys
2021
) => NavigationPluginConfigDBSchema[PluginConfigKeys];
2122

22-
export const configSetup = async ({ strapi }: { strapi: Core.Strapi }) => {
23+
export const configSetup = async ({ strapi, forceDefault = false }: { strapi: Core.Strapi, forceDefault?: boolean }) => {
2324
const pluginStore = strapi.store({
2425
type: 'plugin',
2526
name: 'navigation',
2627
});
2728
const getFromPluginDefaults: PluginDefaultConfigGetter = await strapi.plugin('navigation').config;
28-
const configRaw = {
29+
const configRaw = forceDefault ? {} as NavigationPluginConfigDBSchema : {
2930
...configBase.default,
3031
...((await pluginStore.get({
3132
key: 'config',
3233
})) ?? configBase.default),
3334
};
3435

35-
let config = configSchema.parse(configRaw);
36+
let config = isEmpty(configRaw) ? configRaw : configSchema.parse(configRaw);
3637

3738
const getWithFallback = getWithFallbackFactory(config, getFromPluginDefaults);
3839

@@ -63,13 +64,13 @@ export const configSetup = async ({ strapi }: { strapi: Core.Strapi }) => {
6364

6465
const getWithFallbackFactory =
6566
(config: NavigationPluginConfigDBSchema, fallback: PluginDefaultConfigGetter) =>
66-
<T extends ReturnType<PluginDefaultConfigGetter>>(key: PluginConfigKeys) => {
67-
const value = config?.[key] ?? fallback(key);
67+
<T extends ReturnType<PluginDefaultConfigGetter>>(key: PluginConfigKeys) => {
68+
const value = config?.[key] ?? fallback(key);
6869

69-
assertNotEmpty(value, new Error(`[Navigation] Config "${key}" is undefined`));
70+
assertNotEmpty(value, new Error(`[Navigation] Config "${key}" is undefined`));
7071

71-
return value as T;
72-
};
72+
return value as T;
73+
};
7374

7475
const handleDeletedContentTypes = (
7576
config: NavigationPluginConfigDBSchema,

server/src/services/admin/admin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ const adminService = (context: { strapi: Core.Strapi }) => ({
530530
},
531531

532532
async restoreConfig(): Promise<void> {
533+
console.log('restore');
533534
const commonService = getPluginService(context, 'common');
534535

535536
const pluginStore = await commonService.getPluginStore();

server/src/services/common/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const commonService = (context: { strapi: Core.Strapi }) => ({
119119
},
120120

121121
setDefaultConfig(): Promise<NavigationPluginConfigDBSchema> {
122-
return configSetup({ strapi });
122+
return configSetup({ strapi, forceDefault: true });
123123
},
124124

125125
getBranchName({ item }: GetBranchNameInput): NavigationActionsCategories | void {

0 commit comments

Comments
 (0)