mirror of
https://github.com/strapi/strapi.git
synced 2025-08-05 23:40:04 +00:00
refactor: translations
This commit is contained in:
parent
67a489dcc2
commit
9bd5a9d2bc
@ -2,7 +2,6 @@ import React, { useRef, useState, useMemo, useEffect } from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { FixedSizeList as List } from 'react-window';
|
import { FixedSizeList as List } from 'react-window';
|
||||||
import { useIntl } from 'react-intl';
|
|
||||||
|
|
||||||
import { ReactSelect } from '@strapi/helper-plugin';
|
import { ReactSelect } from '@strapi/helper-plugin';
|
||||||
import { Status } from '@strapi/design-system/Status';
|
import { Status } from '@strapi/design-system/Status';
|
||||||
@ -24,7 +23,6 @@ import { RelationList } from './components/RelationList';
|
|||||||
import { Option } from './components/Option';
|
import { Option } from './components/Option';
|
||||||
import { RELATION_GUTTER, RELATION_ITEM_HEIGHT } from './constants';
|
import { RELATION_GUTTER, RELATION_ITEM_HEIGHT } from './constants';
|
||||||
|
|
||||||
import { getTrad } from '../../utils';
|
|
||||||
import { usePrev } from '../../hooks';
|
import { usePrev } from '../../hooks';
|
||||||
|
|
||||||
const LinkEllipsis = styled(Link)`
|
const LinkEllipsis = styled(Link)`
|
||||||
@ -58,6 +56,7 @@ const RelationInput = ({
|
|||||||
description,
|
description,
|
||||||
disabled,
|
disabled,
|
||||||
error,
|
error,
|
||||||
|
iconButtonAriaLabel,
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
numberOfRelationsToDisplay,
|
numberOfRelationsToDisplay,
|
||||||
@ -65,7 +64,12 @@ const RelationInput = ({
|
|||||||
labelAction,
|
labelAction,
|
||||||
labelLoadMore,
|
labelLoadMore,
|
||||||
labelDisconnectRelation,
|
labelDisconnectRelation,
|
||||||
|
listAriaDescription,
|
||||||
|
liveText,
|
||||||
loadingMessage,
|
loadingMessage,
|
||||||
|
onCancel,
|
||||||
|
onDropItem,
|
||||||
|
onGrabItem,
|
||||||
noRelationsMessage,
|
noRelationsMessage,
|
||||||
onRelationConnect,
|
onRelationConnect,
|
||||||
onRelationLoadMore,
|
onRelationLoadMore,
|
||||||
@ -82,13 +86,10 @@ const RelationInput = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [value, setValue] = useState(null);
|
const [value, setValue] = useState(null);
|
||||||
const [overflow, setOverflow] = useState('');
|
const [overflow, setOverflow] = useState('');
|
||||||
const [liveText, setLiveText] = useState('');
|
|
||||||
|
|
||||||
const listRef = useRef();
|
const listRef = useRef();
|
||||||
const outerListRef = useRef();
|
const outerListRef = useRef();
|
||||||
|
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
|
|
||||||
const { data } = searchResults;
|
const { data } = searchResults;
|
||||||
|
|
||||||
const relations = paginatedRelations.data;
|
const relations = paginatedRelations.data;
|
||||||
@ -232,58 +233,9 @@ const RelationInput = ({
|
|||||||
const handleUpdatePositionOfRelation = (newIndex, currentIndex) => {
|
const handleUpdatePositionOfRelation = (newIndex, currentIndex) => {
|
||||||
if (onRelationReorder && newIndex >= 0 && newIndex < relations.length) {
|
if (onRelationReorder && newIndex >= 0 && newIndex < relations.length) {
|
||||||
onRelationReorder(currentIndex, newIndex);
|
onRelationReorder(currentIndex, newIndex);
|
||||||
|
|
||||||
const item = relations[currentIndex];
|
|
||||||
setLiveText(`${item.mainField ?? item.id}. New position in list: ${getItemPos(newIndex)}`);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {number} index
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
const getItemPos = (index) => `${index + 1} of ${relations.length}`;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {number} index
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
const handleGrabItem = (index) => {
|
|
||||||
const item = relations[index];
|
|
||||||
|
|
||||||
setLiveText(
|
|
||||||
`${item.mainField ?? item.id}, grabbed. Current position in list: ${getItemPos(
|
|
||||||
index
|
|
||||||
)}. Press up and down arrow to change position, Spacebar to drop, Escape to cancel.`
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {number} index
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
const handleDropItem = (index) => {
|
|
||||||
const item = relations[index];
|
|
||||||
|
|
||||||
setLiveText(
|
|
||||||
`${item.mainField ?? item.id}, dropped. Final position in list: ${getItemPos(index)}`
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {number} index
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
const handleCancel = (index) => {
|
|
||||||
const item = relations[index];
|
|
||||||
|
|
||||||
setLiveText(`${item.mainField ?? item.id}, dropped. Re-order cancelled.`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const previewRelationsLength = usePrev(relations.length);
|
const previewRelationsLength = usePrev(relations.length);
|
||||||
/**
|
/**
|
||||||
* @type {React.MutableRefObject<'onChange' | 'loadMore'>}
|
* @type {React.MutableRefObject<'onChange' | 'loadMore'>}
|
||||||
@ -371,12 +323,7 @@ const RelationInput = ({
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<RelationList overflow={overflow}>
|
<RelationList overflow={overflow}>
|
||||||
<VisuallyHidden id={`${name}-item-instructions`}>
|
<VisuallyHidden id={`${name}-item-instructions`}>{listAriaDescription}</VisuallyHidden>
|
||||||
{formatMessage({
|
|
||||||
id: getTrad('components.RelationInput.instructions'),
|
|
||||||
defaultMessage: `Press spacebar to grab and re-order`,
|
|
||||||
})}
|
|
||||||
</VisuallyHidden>
|
|
||||||
<VisuallyHidden aria-live="assertive">{liveText}</VisuallyHidden>
|
<VisuallyHidden aria-live="assertive">{liveText}</VisuallyHidden>
|
||||||
<List
|
<List
|
||||||
height={dynamicListHeight}
|
height={dynamicListHeight}
|
||||||
@ -387,13 +334,10 @@ const RelationInput = ({
|
|||||||
itemData={{
|
itemData={{
|
||||||
ariaDescribedBy: `${name}-item-instructions`,
|
ariaDescribedBy: `${name}-item-instructions`,
|
||||||
disabled,
|
disabled,
|
||||||
handleCancel,
|
handleCancel: onCancel,
|
||||||
handleDropItem,
|
handleDropItem: onDropItem,
|
||||||
handleGrabItem,
|
handleGrabItem: onGrabItem,
|
||||||
iconButtonAriaLabel: formatMessage({
|
iconButtonAriaLabel,
|
||||||
id: getTrad('components.RelationInput.icon-button-aria-label'),
|
|
||||||
defaultMessage: 'Drag',
|
|
||||||
}),
|
|
||||||
labelDisconnectRelation,
|
labelDisconnectRelation,
|
||||||
onRelationDisconnect,
|
onRelationDisconnect,
|
||||||
publicationStateTranslations,
|
publicationStateTranslations,
|
||||||
@ -451,8 +395,14 @@ RelationInput.defaultProps = {
|
|||||||
description: undefined,
|
description: undefined,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
error: undefined,
|
error: undefined,
|
||||||
|
iconButtonAriaLabel: 'Drag',
|
||||||
labelAction: null,
|
labelAction: null,
|
||||||
labelLoadMore: null,
|
labelLoadMore: null,
|
||||||
|
listAriaDescription: 'Press spacebar to grab and re-order',
|
||||||
|
liveText: undefined,
|
||||||
|
onCancel: undefined,
|
||||||
|
onDropItem: undefined,
|
||||||
|
onGrabItem: undefined,
|
||||||
required: false,
|
required: false,
|
||||||
relations: { data: [] },
|
relations: { data: [] },
|
||||||
searchResults: { data: [] },
|
searchResults: { data: [] },
|
||||||
@ -462,15 +412,21 @@ RelationInput.propTypes = {
|
|||||||
error: PropTypes.string,
|
error: PropTypes.string,
|
||||||
description: PropTypes.string,
|
description: PropTypes.string,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
|
iconButtonAriaLabel: PropTypes.string,
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
label: PropTypes.string.isRequired,
|
label: PropTypes.string.isRequired,
|
||||||
labelAction: PropTypes.element,
|
labelAction: PropTypes.element,
|
||||||
labelLoadMore: PropTypes.string,
|
labelLoadMore: PropTypes.string,
|
||||||
labelDisconnectRelation: PropTypes.string.isRequired,
|
labelDisconnectRelation: PropTypes.string.isRequired,
|
||||||
|
listAriaDescription: PropTypes.string,
|
||||||
|
liveText: PropTypes.string,
|
||||||
loadingMessage: PropTypes.string.isRequired,
|
loadingMessage: PropTypes.string.isRequired,
|
||||||
name: PropTypes.string.isRequired,
|
name: PropTypes.string.isRequired,
|
||||||
noRelationsMessage: PropTypes.string.isRequired,
|
noRelationsMessage: PropTypes.string.isRequired,
|
||||||
numberOfRelationsToDisplay: PropTypes.number.isRequired,
|
numberOfRelationsToDisplay: PropTypes.number.isRequired,
|
||||||
|
onCancel: PropTypes.func,
|
||||||
|
onDropItem: PropTypes.func,
|
||||||
|
onGrabItem: PropTypes.func,
|
||||||
onRelationConnect: PropTypes.func.isRequired,
|
onRelationConnect: PropTypes.func.isRequired,
|
||||||
onRelationDisconnect: PropTypes.func.isRequired,
|
onRelationDisconnect: PropTypes.func.isRequired,
|
||||||
onRelationLoadMore: PropTypes.func.isRequired,
|
onRelationLoadMore: PropTypes.func.isRequired,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable no-nested-ternary */
|
/* eslint-disable no-nested-ternary */
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import React, { memo, useMemo } from 'react';
|
import React, { memo, useMemo, useState } from 'react';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import get from 'lodash/get';
|
import get from 'lodash/get';
|
||||||
import pick from 'lodash/pick';
|
import pick from 'lodash/pick';
|
||||||
@ -36,6 +36,8 @@ export const RelationInputDataManager = ({
|
|||||||
size,
|
size,
|
||||||
targetModel,
|
targetModel,
|
||||||
}) => {
|
}) => {
|
||||||
|
const [liveText, setLiveText] = useState('');
|
||||||
|
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const {
|
const {
|
||||||
slug,
|
slug,
|
||||||
@ -137,6 +139,12 @@ export const RelationInputDataManager = ({
|
|||||||
const handleSearchMore = () => {
|
const handleSearchMore = () => {
|
||||||
search.fetchNextPage();
|
search.fetchNextPage();
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {number} index
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
const getItemPos = (index) => `${index + 1} of ${relationsFromModifiedData.length}`;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -144,6 +152,20 @@ export const RelationInputDataManager = ({
|
|||||||
* @param {number} oldIndex
|
* @param {number} oldIndex
|
||||||
*/
|
*/
|
||||||
const handleRelationReorder = (oldIndex, newIndex) => {
|
const handleRelationReorder = (oldIndex, newIndex) => {
|
||||||
|
const item = relations[oldIndex];
|
||||||
|
setLiveText(
|
||||||
|
formatMessage(
|
||||||
|
{
|
||||||
|
id: getTrad('components.RelationInputDataManager.reorder'),
|
||||||
|
defaultMessage: '{item}, moved. New position in list: {position}.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
item: item.mainField ?? item.id,
|
||||||
|
position: getItemPos(newIndex),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
relationReorder({
|
relationReorder({
|
||||||
name,
|
name,
|
||||||
newIndex,
|
newIndex,
|
||||||
@ -151,6 +173,71 @@ export const RelationInputDataManager = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {number} index
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
const handleGrabItem = (index) => {
|
||||||
|
const item = relations[index];
|
||||||
|
|
||||||
|
setLiveText(
|
||||||
|
formatMessage(
|
||||||
|
{
|
||||||
|
id: getTrad('components.RelationInputDataManager.grab-item'),
|
||||||
|
defaultMessage: `{item}, grabbed. Current position in list: {position}. Press up and down arrow to change position, Spacebar to drop, Escape to cancel.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
item: item.mainField ?? item.id,
|
||||||
|
position: getItemPos(index),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {number} index
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
const handleDropItem = (index) => {
|
||||||
|
const item = relations[index];
|
||||||
|
|
||||||
|
setLiveText(
|
||||||
|
formatMessage(
|
||||||
|
{
|
||||||
|
id: getTrad('components.RelationInputDataManager.drop-item'),
|
||||||
|
defaultMessage: `{item}, dropped. Final position in list: {position}.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
item: item.mainField ?? item.id,
|
||||||
|
position: getItemPos(index),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {number} index
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
const handleCancel = (index) => {
|
||||||
|
const item = relations[index];
|
||||||
|
|
||||||
|
setLiveText(
|
||||||
|
formatMessage(
|
||||||
|
{
|
||||||
|
id: getTrad('components.RelationInputDataManager.cancel-item'),
|
||||||
|
defaultMessage: '{item}, dropped. Re-order cancelled.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
item: item.mainField ?? item.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(!isFieldAllowed && isCreatingEntry) ||
|
(!isFieldAllowed && isCreatingEntry) ||
|
||||||
(!isCreatingEntry && !isFieldAllowed && !isFieldReadable)
|
(!isCreatingEntry && !isFieldAllowed && !isFieldReadable)
|
||||||
@ -185,25 +272,30 @@ export const RelationInputDataManager = ({
|
|||||||
error={error}
|
error={error}
|
||||||
description={description}
|
description={description}
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
|
iconButtonAriaLabel={formatMessage({
|
||||||
|
id: getTrad('components.RelationInput.icon-button-aria-label'),
|
||||||
|
defaultMessage: 'Drag',
|
||||||
|
})}
|
||||||
id={name}
|
id={name}
|
||||||
label={`${formatMessage({
|
label={`${formatMessage({
|
||||||
id: intlLabel.id,
|
id: intlLabel.id,
|
||||||
defaultMessage: intlLabel.defaultMessage,
|
defaultMessage: intlLabel.defaultMessage,
|
||||||
})} ${totalRelations > 0 ? `(${totalRelations})` : ''}`}
|
})} ${totalRelations > 0 ? `(${totalRelations})` : ''}`}
|
||||||
labelAction={labelAction}
|
labelAction={labelAction}
|
||||||
labelLoadMore={
|
labelLoadMore={formatMessage({
|
||||||
!isCreatingEntry
|
id: getTrad('relation.loadMore'),
|
||||||
? formatMessage({
|
defaultMessage: 'Load More',
|
||||||
id: getTrad('relation.loadMore'),
|
})}
|
||||||
defaultMessage: 'Load More',
|
|
||||||
})
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
labelDisconnectRelation={formatMessage({
|
labelDisconnectRelation={formatMessage({
|
||||||
id: getTrad('relation.disconnect'),
|
id: getTrad('relation.disconnect'),
|
||||||
defaultMessage: 'Remove',
|
defaultMessage: 'Remove',
|
||||||
})}
|
})}
|
||||||
|
listAriaDescription={formatMessage({
|
||||||
|
id: getTrad('components.RelationInput.instructions'),
|
||||||
|
defaultMessage: `Press spacebar to grab and re-order`,
|
||||||
|
})}
|
||||||
listHeight={320}
|
listHeight={320}
|
||||||
|
liveText={liveText}
|
||||||
loadingMessage={formatMessage({
|
loadingMessage={formatMessage({
|
||||||
id: getTrad('relation.isLoading'),
|
id: getTrad('relation.isLoading'),
|
||||||
defaultMessage: 'Relations are loading',
|
defaultMessage: 'Relations are loading',
|
||||||
@ -214,6 +306,9 @@ export const RelationInputDataManager = ({
|
|||||||
defaultMessage: 'No relations available',
|
defaultMessage: 'No relations available',
|
||||||
})}
|
})}
|
||||||
numberOfRelationsToDisplay={RELATIONS_TO_DISPLAY}
|
numberOfRelationsToDisplay={RELATIONS_TO_DISPLAY}
|
||||||
|
onDropItem={handleDropItem}
|
||||||
|
onGrabItem={handleGrabItem}
|
||||||
|
onCancel={handleCancel}
|
||||||
onRelationConnect={handleRelationConnect}
|
onRelationConnect={handleRelationConnect}
|
||||||
onRelationDisconnect={handleRelationDisconnect}
|
onRelationDisconnect={handleRelationDisconnect}
|
||||||
onRelationLoadMore={handleRelationLoadMore}
|
onRelationLoadMore={handleRelationLoadMore}
|
||||||
|
@ -568,6 +568,10 @@
|
|||||||
"content-manager.components.NotAllowedInput.text": "No permissions to see this field",
|
"content-manager.components.NotAllowedInput.text": "No permissions to see this field",
|
||||||
"content-manager.components.RelationInput.instructions": "Press spacebar to grab and re-order",
|
"content-manager.components.RelationInput.instructions": "Press spacebar to grab and re-order",
|
||||||
"content-manager.components.RelationInput.icon-button-aria-label": "Drag",
|
"content-manager.components.RelationInput.icon-button-aria-label": "Drag",
|
||||||
|
"content-manager.components.RelationInputDataManager.reorder": "{item}, moved. New position in list: {position}.",
|
||||||
|
"content-manager.components.RelationInputDataManager.grab-item": "{item}, grabbed. Current position in list: {position}. Press up and down arrow to change position, Spacebar to drop, Escape to cancel.",
|
||||||
|
"content-manager.components.RelationInputDataManager.drop-item": "{item}, dropped. Final position in list: {position}.",
|
||||||
|
"content-manager.components.RelationInputDataManager.cancel-item": "{item}, dropped. Re-order cancelled.",
|
||||||
"content-manager.components.RepeatableComponent.error-message": "The component(s) contain error(s)",
|
"content-manager.components.RepeatableComponent.error-message": "The component(s) contain error(s)",
|
||||||
"content-manager.components.Search.placeholder": "Search for an entry...",
|
"content-manager.components.Search.placeholder": "Search for an entry...",
|
||||||
"content-manager.components.Select.draft-info-title": "State: Draft",
|
"content-manager.components.Select.draft-info-title": "State: Draft",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user