fix: multiple locale related issues

This commit is contained in:
Fernando Chavez 2024-08-21 14:27:42 +02:00
parent 5f649c2558
commit 4bff2c01cc
3 changed files with 40 additions and 26 deletions

View File

@ -587,27 +587,29 @@ const PublishAction: DocumentActionComponent = ({
}, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
React.useEffect(() => {
if (documentId) {
const fetchDraftRelationsCount = async () => {
const { data, error } = await countDraftRelations({
collectionType,
model,
documentId,
params,
});
if (error) {
throw error;
}
if (data) {
setServerCountOfDraftRelations(data.data);
}
};
fetchDraftRelationsCount();
if (!document || !document.documentId) {
return;
}
}, [documentId, countDraftRelations, collectionType, model, params]);
const fetchDraftRelationsCount = async () => {
const { data, error } = await countDraftRelations({
collectionType,
model,
documentId,
params,
});
if (error) {
throw error;
}
if (data) {
setServerCountOfDraftRelations(data.data);
}
};
fetchDraftRelationsCount();
}, [document, documentId, countDraftRelations, collectionType, model, params]);
const isDocumentPublished =
(document?.[PUBLISHED_AT_ATTRIBUTE_NAME] ||

View File

@ -209,7 +209,7 @@ export default {
permissionChecker,
model,
// @ts-expect-error TODO: fix
{ id, locale, publishedAt: null },
{ documentId: id, locale, publishedAt: null },
{ availableLocales: true, availableStatus: false }
);

View File

@ -106,8 +106,14 @@ const LocalePickerAction = ({
}: LocalePickerActionProps) => {
const { formatMessage } = useIntl();
const [{ query }, setQuery] = useQueryParams<I18nBaseQuery>();
const currentDesiredLocale = query.plugins?.i18n?.locale;
const { hasI18n, canCreate, canRead } = useI18n();
const { schema } = useDocument({ model, collectionType, documentId });
const { schema } = useDocument({
model,
collectionType,
documentId,
params: { locale: currentDesiredLocale },
});
const handleSelect = React.useCallback(
(value: string) => {
@ -131,7 +137,6 @@ const LocalePickerAction = ({
* Handle the case where the current locale query param doesn't exist
* in the list of available locales, so we redirect to the default locale.
*/
const currentDesiredLocale = query.plugins?.i18n?.locale;
const doesLocaleExist = locales.find((loc) => loc.code === currentDesiredLocale);
const defaultLocale = locales.find((locale) => locale.isDefault);
if (!doesLocaleExist && defaultLocale?.code) {
@ -245,10 +250,17 @@ const FillFromAnotherLocaleAction = ({
}: FillFromAnotherLocaleActionProps) => {
const [isDialogOpen, setIsDialogOpen] = React.useState<boolean>(false);
const { formatMessage } = useIntl();
const [{ query }] = useQueryParams<I18nBaseQuery>();
const currentDesiredLocale = query.plugins?.i18n?.locale;
const [localeSelected, setLocaleSelected] = React.useState<string | null>(null);
const setValues = useForm('FillFromAnotherLocale', (state) => state.setValues);
const { getDocument } = useDocumentActions();
const { schema } = useDocument({ model, documentId, collectionType });
const { schema } = useDocument({
model,
documentId,
collectionType,
params: { locale: currentDesiredLocale },
});
const availableLocales = locales.filter((locale) =>
meta?.availableLocales.some((l) => l.locale === locale.code)
@ -503,7 +515,7 @@ const BulkLocalePublishAction: DocumentActionComponent = ({
},
},
{
skip: !hasI18n,
skip: !hasI18n || !baseLocale,
}
);
@ -701,7 +713,7 @@ const BulkLocalePublishAction: DocumentActionComponent = ({
defaultMessage: 'Publish Multiple Locales',
}),
icon: <ListPlus />,
disabled: isPublishedTab || canPublish.length === 0,
disabled: isPublishedTab || canPublish.length === 0 || !baseLocale,
position: ['panel'],
variant: 'secondary',
dialog: {