Skip to content

Commit b417e3a

Browse files
authored
fix: empty url when read from related (#615)
* fix: empty url when read from related * fix:PR fixes
1 parent 5ed369d commit b417e3a

File tree

9 files changed

+34
-15
lines changed

9 files changed

+34
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Config for this plugin is stored as a part of the `config/plugins.{js|ts}` or `c
168168
- `contentTypes` - UIDs of related content types
169169
- `defaultContentTypes` - UID of content type that will be selected by default while creating a new navigation item
170170
- `contentTypesNameFields` - Definition of content type title fields like `'api::<collection name>.<content type name>': ['field_name_1', 'field_name_2']`, if not set titles are pulled from fields like `['title', 'subject', 'name']`. **TIP** - Proper content type uid you can find in the URL of Content Manager where you're managing relevant entities like: `admin/content-manager/collectionType/< THE UID HERE >?page=1&pageSize=10&sort=Title:ASC&plugins[i18n][locale]=en`
171-
- `pathDefaultFields` - The attribute to copy the default path from per content type. Syntax: `'api::<collection name>.<content type name>': ['url_slug', 'path']`
171+
- `pathDefaultFields` - The attribute to copy the default path from per content type. Syntax: `'api::<collection name>.<content type name>': ['url_slug', 'path']`. If you leave it empty, the default path is generated based on the ID.
172172
- `gql` - If you're using GraphQL that's the right place to put all necessary settings. More **[ here ](#gql-configuration)**
173173
- `cascadeMenuAttached` - If you don't want "Menu attached" to cascade on child items set this value `Disabled`.
174174

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { generatePreviewPath } from '../../utils/properties';
1010
import { useConfig } from '../../../../hooks';
1111
import { NavigationItemFormSchema } from '../../utils/form';
1212
import { StrapiContentTypeItemSchema } from 'src/api/validators';
13+
import { isEmpty } from 'lodash';
1314

1415
type PathFieldProps = {
1516
contentTypeItems: StrapiContentTypeItemSchema[] | undefined;
@@ -34,9 +35,9 @@ export const PathField: React.FC<PathFieldProps> = ({
3435
values.type === 'INTERNAL'
3536
? values
3637
: {
37-
related: undefined,
38-
relatedType: undefined,
39-
};
38+
related: undefined,
39+
relatedType: undefined,
40+
};
4041

4142
const pathDefault = generatePreviewPath({
4243
currentPath: values.path,
@@ -50,6 +51,12 @@ export const PathField: React.FC<PathFieldProps> = ({
5051
isSingleSelected,
5152
});
5253

54+
const disabled =
55+
!canUpdate || (values.autoSync && values.type === 'INTERNAL')
56+
57+
const [pathDefaultFieldsValue] =
58+
Object.values(configQuery.data?.pathDefaultFields ?? {}).flat()
59+
5360
return (
5461
<Grid.Item alignItems="flex-start" key="title" col={12}>
5562
<Field
@@ -60,13 +67,20 @@ export const PathField: React.FC<PathFieldProps> = ({
6067
formatMessage(getTrad(`popup.item.form.${pathSourceName}.placeholder`, 'e.g. Blog')),
6168
pathDefault
6269
? formatMessage(getTrad('popup.item.form.type.external.description'), {
63-
value: pathDefault,
64-
})
70+
value: pathDefault,
71+
})
72+
: '',
73+
disabled
74+
? formatMessage(getTrad('popup.item.form.type.internal.source'), {
75+
value: !isEmpty(pathDefaultFieldsValue)
76+
? pathDefaultFieldsValue
77+
: "id"
78+
})
6579
: '',
6680
].join(' ')}
6781
>
6882
<TextInput
69-
disabled={!canUpdate}
83+
disabled={disabled}
7084
name={pathSourceName}
7185
onChange={(eventOrPath: FormChangeEvent, value?: any) =>
7286
handleChange(eventOrPath, value, onChange)

admin/src/pages/HomePage/components/NavigationItemForm/components/RelatedEntityField/hooks.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const useChangeFieldsFromRelated = (
1111
const configQuery = useConfig();
1212

1313
useEffect(() => {
14-
if (!values.autoSync || !values.related || !configQuery.data) {
14+
if (!values.autoSync || !values.related || !values.relatedType || !configQuery.data) {
1515
return;
1616
}
1717

@@ -21,21 +21,21 @@ export const useChangeFieldsFromRelated = (
2121

2222
if (!relatedItem) {
2323
return;
24-
}
25-
24+
}
25+
2626
const { contentTypesNameFields, pathDefaultFields } = configQuery.data;
2727

28-
const nextPath = pathDefaultFields[values.relatedType]?.reduce<string | undefined>(
28+
const nextPath = (pathDefaultFields[values.relatedType]?.reduce<string | undefined>(
2929
(acc, field) => {
3030
return acc ? acc : relatedItem?.[field];
3131
},
32-
undefined
33-
) || '';
32+
undefined
33+
) || relatedItem.id).toString();
3434

3535
const nextTitle = (contentTypesNameFields[values.relatedType] ?? [])
3636
.concat(contentTypesNameFields.default ?? [])
3737
.reduce<undefined | string>((acc, field) => {
38-
return acc ? acc : relatedItem?.[field];
38+
return acc ? acc.toString() : relatedItem?.[field];
3939
}, undefined);
4040

4141
const batch: Array<{ name: keyof NavigationItemFormSchema; value: string }> = [];

admin/src/translations/ca.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const ca = {
139139
label: "Type d'élément de navigation",
140140
internal: {
141141
label: 'Source interne',
142+
source: 'URL basat en: {value}',
142143
},
143144
external: {
144145
label: 'Source externe',

admin/src/translations/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ const en = {
143143
label: 'Navigation item type',
144144
internal: {
145145
label: 'Internal source',
146+
source: 'URL based on: {value}',
146147
},
147148
external: {
148149
label: 'External source',

admin/src/translations/es.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ const en = {
144144
label: 'Tipo de ítem de navegación',
145145
internal: {
146146
label: 'Fuente interna',
147+
source: 'URL basado en: {value}',
147148
},
148149
external: {
149150
label: 'Fuente externa',

admin/src/translations/fr.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ const fr = {
143143
label: "Type d'élément de navigation",
144144
internal: {
145145
label: 'Source interne',
146+
source: 'URL basé sur: {value}',
146147
},
147148
external: {
148149
label: 'Source externe',

admin/src/translations/tr.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ const tr = {
143143
label: 'Navigasyon öğesi türü',
144144
internal: {
145145
label: 'Dahili kaynak',
146+
source: 'URL dayalı: {value}',
146147
},
147148
external: {
148149
label: 'Harici kaynak',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strapi-plugin-navigation",
3-
"version": "3.2.5",
3+
"version": "3.2.5-beta.1",
44
"description": "Strapi - Navigation plugin",
55
"strapi": {
66
"name": "navigation",

0 commit comments

Comments
 (0)