mirror of
https://github.com/strapi/strapi.git
synced 2025-10-08 06:41:06 +00:00
fix: change status on locale picker
This commit is contained in:
parent
d9f14e6702
commit
e5db813798
@ -108,6 +108,7 @@ interface HeaderActionDescription {
|
|||||||
}>;
|
}>;
|
||||||
onSelect?: (value: string) => void;
|
onSelect?: (value: string) => void;
|
||||||
value?: string;
|
value?: string;
|
||||||
|
customizeContent?: (value: string) => React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -369,6 +370,7 @@ const HeaderActions = ({ actions }: HeaderActionsProps) => {
|
|||||||
// @ts-expect-error – the DS will handle numbers, but we're not allowing the API.
|
// @ts-expect-error – the DS will handle numbers, but we're not allowing the API.
|
||||||
onChange={action.onSelect}
|
onChange={action.onSelect}
|
||||||
value={action.value}
|
value={action.value}
|
||||||
|
customizeContent={action.customizeContent}
|
||||||
>
|
>
|
||||||
{action.options.map(({ label, ...option }) => (
|
{action.options.map(({ label, ...option }) => (
|
||||||
<SingleSelectOption key={option.value} {...option}>
|
<SingleSelectOption key={option.value} {...option}>
|
||||||
|
@ -28,7 +28,7 @@ import {
|
|||||||
SingleSelectOption,
|
SingleSelectOption,
|
||||||
Dialog,
|
Dialog,
|
||||||
} from '@strapi/design-system';
|
} from '@strapi/design-system';
|
||||||
import { WarningCircle, ListPlus, Trash, Download, Cross } from '@strapi/icons';
|
import { WarningCircle, ListPlus, Trash, Download, Cross, Plus } from '@strapi/icons';
|
||||||
import { Modules } from '@strapi/types';
|
import { Modules } from '@strapi/types';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
@ -50,6 +50,59 @@ import type { I18nBaseQuery } from '../types';
|
|||||||
* LocalePickerAction
|
* LocalePickerAction
|
||||||
* -----------------------------------------------------------------------------------------------*/
|
* -----------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
interface LocaleOptionProps {
|
||||||
|
isDraftAndPublishEnabled: boolean;
|
||||||
|
locale: Locale;
|
||||||
|
status: 'draft' | 'published' | 'modified';
|
||||||
|
entryExists: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const LocaleOption = ({
|
||||||
|
isDraftAndPublishEnabled,
|
||||||
|
locale,
|
||||||
|
status,
|
||||||
|
entryExists,
|
||||||
|
}: LocaleOptionProps) => {
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
|
if (!entryExists) {
|
||||||
|
return formatMessage(
|
||||||
|
{
|
||||||
|
id: getTranslation('CMEditViewLocalePicker.locale.create'),
|
||||||
|
defaultMessage: 'Create <bold>{locale}</bold> locale',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
bold: (locale: React.ReactNode) => <b>{locale}</b>,
|
||||||
|
locale: locale.name,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flex width="100%" gap={1} justifyContent="space-between">
|
||||||
|
<Typography>{locale.name}</Typography>
|
||||||
|
{isDraftAndPublishEnabled ? (
|
||||||
|
<Status
|
||||||
|
display="flex"
|
||||||
|
paddingLeft="6px"
|
||||||
|
paddingRight="6px"
|
||||||
|
paddingTop="2px"
|
||||||
|
paddingBottom="2px"
|
||||||
|
showBullet={false}
|
||||||
|
size={'S'}
|
||||||
|
variant={
|
||||||
|
status === 'draft' ? 'secondary' : status === 'published' ? 'success' : 'alternative'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Typography tag="span" variant="pi" fontWeight="bold">
|
||||||
|
{capitalize(status)}
|
||||||
|
</Typography>
|
||||||
|
</Status>
|
||||||
|
) : null}
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const LocalePickerAction = ({
|
const LocalePickerAction = ({
|
||||||
document,
|
document,
|
||||||
meta,
|
meta,
|
||||||
@ -99,11 +152,11 @@ const LocalePickerAction = ({
|
|||||||
}, [handleSelect, hasI18n, locales, currentDesiredLocale]);
|
}, [handleSelect, hasI18n, locales, currentDesiredLocale]);
|
||||||
|
|
||||||
const currentLocale = Array.isArray(locales)
|
const currentLocale = Array.isArray(locales)
|
||||||
? locales.find((locale) => locale.code === currentDesiredLocale)?.code
|
? locales.find((locale) => locale.code === currentDesiredLocale)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const allCurrentLocales = [
|
const allCurrentLocales = [
|
||||||
{ status: getDocumentStatus(document, meta), locale: currentLocale },
|
{ status: getDocumentStatus(document, meta), locale: currentLocale?.code },
|
||||||
...(meta?.availableLocales ?? []),
|
...(meta?.availableLocales ?? []),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -117,38 +170,29 @@ const LocalePickerAction = ({
|
|||||||
defaultMessage: 'Locales',
|
defaultMessage: 'Locales',
|
||||||
}),
|
}),
|
||||||
options: locales.map((locale) => {
|
options: locales.map((locale) => {
|
||||||
|
const entryWithLocaleExists = allCurrentLocales.some((doc) => doc.locale === locale.code);
|
||||||
|
|
||||||
const currentLocaleDoc = allCurrentLocales.find((doc) =>
|
const currentLocaleDoc = allCurrentLocales.find((doc) =>
|
||||||
'locale' in doc ? doc.locale === locale.code : false
|
'locale' in doc ? doc.locale === locale.code : false
|
||||||
);
|
);
|
||||||
const status = currentLocaleDoc?.status ?? 'draft';
|
|
||||||
|
|
||||||
const permissionsToCheck = currentLocaleDoc ? canCreate : canRead;
|
const permissionsToCheck = currentLocaleDoc ? canCreate : canRead;
|
||||||
|
|
||||||
const statusVariant =
|
|
||||||
status === 'draft' ? 'secondary' : status === 'published' ? 'success' : 'alternative';
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
disabled: !permissionsToCheck.includes(locale.code),
|
disabled: !permissionsToCheck.includes(locale.code),
|
||||||
value: locale.code,
|
value: locale.code,
|
||||||
label: locale.name,
|
label: (
|
||||||
startIcon: schema?.options?.draftAndPublish ? (
|
<LocaleOption
|
||||||
<Status
|
isDraftAndPublishEnabled={!!schema?.options?.draftAndPublish}
|
||||||
display="flex"
|
locale={locale}
|
||||||
paddingLeft="6px"
|
status={currentLocaleDoc?.status}
|
||||||
paddingRight="6px"
|
entryExists={entryWithLocaleExists}
|
||||||
paddingTop="2px"
|
/>
|
||||||
paddingBottom="2px"
|
),
|
||||||
showBullet={false}
|
startIcon: !entryWithLocaleExists ? <Plus /> : null,
|
||||||
size={'S'}
|
|
||||||
variant={statusVariant}
|
|
||||||
>
|
|
||||||
<Typography tag="span" variant="pi" fontWeight="bold">
|
|
||||||
{capitalize(status)}
|
|
||||||
</Typography>
|
|
||||||
</Status>
|
|
||||||
) : null,
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
customizeContent: () => currentLocale?.name,
|
||||||
onSelect: handleSelect,
|
onSelect: handleSelect,
|
||||||
value: currentLocale,
|
value: currentLocale,
|
||||||
};
|
};
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
"CMEditViewBulkLocale.publication-status": "Publication Status",
|
"CMEditViewBulkLocale.publication-status": "Publication Status",
|
||||||
"CMEditViewBulkLocale.draft-relation-warning": "Some locales are related to draft entries. Publishing them could leave broken links in your app.",
|
"CMEditViewBulkLocale.draft-relation-warning": "Some locales are related to draft entries. Publishing them could leave broken links in your app.",
|
||||||
"CMEditViewBulkLocale.continue-confirmation": "Are you sure you want to continue?",
|
"CMEditViewBulkLocale.continue-confirmation": "Are you sure you want to continue?",
|
||||||
|
"CMEditViewLocalePicker.locale.create": "Create <bold>{locale}</bold> locale",
|
||||||
"CMListView.popover.display-locales.label": "Display translated locales",
|
"CMListView.popover.display-locales.label": "Display translated locales",
|
||||||
"CheckboxConfirmation.Modal.body": "Do you want to disable it?",
|
"CheckboxConfirmation.Modal.body": "Do you want to disable it?",
|
||||||
"CheckboxConfirmation.Modal.button-confirm": "Yes, disable",
|
"CheckboxConfirmation.Modal.button-confirm": "Yes, disable",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user