Show all locales in the listview content-available cell (#9877)

This commit is contained in:
Marvin Frachet 2021-03-30 11:06:06 +02:00 committed by GitHub
parent f30895b588
commit ba1f493c8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -5,8 +5,9 @@ import { Tooltip } from '@buffetjs/styles';
const mapToLocaleName = (locales, localeCode) =>
locales.find(({ code }) => code === localeCode).name;
const LocaleListCell = ({ locales, localizations, id }) => {
const localizationNames = localizations.map(locale => locale.locale);
const LocaleListCell = ({ locales, localizations, locale: currentLocaleCode, id }) => {
const allLocalizations = [{ locale: currentLocaleCode }, ...localizations];
const localizationNames = allLocalizations.map(locale => locale.locale);
const defaultLocale = locales.find(locale => locale.isDefault);
const hasDefaultLocale = localizationNames.includes(defaultLocale.code);
@ -61,6 +62,7 @@ LocaleListCell.propTypes = {
isDefault: PropTypes.bool,
})
).isRequired,
locale: PropTypes.string.isRequired,
};
export default LocaleListCell;

View File

@ -42,7 +42,7 @@ describe('LocaleListCell', () => {
<LocaleListCell id={12} locales={locales} locale={locale} localizations={localizations} />
);
expect(screen.getByText('French (default), Arabic')).toBeVisible();
expect(screen.getByText('French (default), Arabic, English')).toBeVisible();
});
it('returns the "ar" when there s 2 locales available', () => {
@ -80,7 +80,7 @@ describe('LocaleListCell', () => {
<LocaleListCell id={12} locales={locales} locale={locale} localizations={localizations} />
);
expect(screen.getByText('Arabic')).toBeVisible();
expect(screen.getByText('Arabic, English')).toBeVisible();
});
it('returns the "ar" and "en" locales alphabetically sorted', () => {
@ -118,6 +118,6 @@ describe('LocaleListCell', () => {
<LocaleListCell id={12} locales={locales} locale={locale} localizations={localizations} />
);
expect(screen.getByText('Arabic, English')).toBeVisible();
expect(screen.getByText('French (default), Arabic, English')).toBeVisible();
});
});