Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-turkeys-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"strapi-plugin-webtools": patch
---

fix: make the locale filter actually work by rewriting the URL params
5 changes: 5 additions & 0 deletions .changeset/social-hands-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"strapi-plugin-webtools": patch
---

fix: make sure the edit URL respects the alias locale
5 changes: 5 additions & 0 deletions .changeset/wet-taxis-send.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"strapi-plugin-webtools": patch
---

fix: actually return the localized entity in the router endpoint
18 changes: 16 additions & 2 deletions packages/core/admin/hooks/useQueryParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState } from 'react';
import qs from 'qs';
import { useLocation } from 'react-router-dom';

const useQueryParams = () => {
Expand All @@ -23,9 +24,22 @@ const useQueryParams = () => {
searchParams.append('pagination[pageSize]', pageSize);
}

setParams(searchParams.toString());
}, [location]);
const paramsObj = qs.parse(searchParams.toString());
// @ts-expect-error
const filters = paramsObj?.filters?.$and as Array<{ [key: string]: any }>;
const localeFilterIndex = filters?.findIndex((filter) => filter.locale !== undefined);
const localeFilter = filters?.[localeFilterIndex];

if (localeFilter) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
paramsObj.locale = localeFilter.locale.$eq as string;
filters.splice(localeFilterIndex, 1);
// @ts-expect-error
paramsObj.filters.$and = filters;
}

setParams(qs.stringify(paramsObj));
}, [location]);

return params;
};
Expand Down
7 changes: 6 additions & 1 deletion packages/core/server/controllers/url-alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ export default factories.createCoreController(contentTypeSlug, ({ strapi }) => (
const contentTypeObj = strapi.contentTypes[contentType];
const contentTypeUrlPartial = contentTypeObj.kind === 'singleType' ? 'single-types' : 'collection-types';

const model = strapi.getModel(contentType);
// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const isLocalized = model.pluginOptions.i18n?.localized as boolean;

ctx.body = {
link: `/content-manager/${contentTypeUrlPartial}/${contentType}/${contentTypeObj.kind === 'collectionType' ? entity.documentId : ''}`,
link: `/content-manager/${contentTypeUrlPartial}/${contentType}/${contentTypeObj.kind === 'collectionType' ? entity.documentId : ''}${isLocalized ? `?plugins[i18n][locale]=${entity.locale}` : ''}`,
};
},
generate: async (
Expand Down
5 changes: 5 additions & 0 deletions packages/core/server/services/url-alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ const customServices = () => ({
}

const contentTypeUid = urlAliasEntity.contenttype as UID.ContentType;
const model = strapi.getModel(contentTypeUid);
// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const isLocalized = model.pluginOptions.i18n?.localized as boolean;

const entity = await strapi.documents(contentTypeUid as 'api::test.test').findFirst({
status: 'published',
...query,
...(isLocalized ? { locale: urlAliasEntity.locale } : {}),
filters: {
...query?.filters,
url_alias: { documentId: urlAliasEntity.documentId },
Expand Down
Loading