Skip to content

Commit

Permalink
Fix SortButton labels must have a valid translatino message
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Mar 12, 2021
1 parent a171deb commit 3e6b82c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/ra-core/src/util/getFieldLabelTranslationArgs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import inflection from 'inflection';

interface Args {
label: string;
resource: string;
source: string;
label?: string;
resource?: string;
source?: string;
}

type TranslationArguments = [string, any?];
Expand All @@ -17,7 +17,7 @@ type TranslationArguments = [string, any?];
* {translate(...getFieldLabelTranslationArgs({ label, resource, source }))}
* </span>
*/
export default (options: Args): TranslationArguments => {
export default (options?: Args): TranslationArguments => {
if (!options) {
return [''];
}
Expand Down
20 changes: 17 additions & 3 deletions packages/ra-ui-materialui/src/button/SortButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {
import SortIcon from '@material-ui/icons/Sort';
import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
import { shallowEqual } from 'react-redux';
import { useListSortContext, useTranslate } from 'ra-core';
import {
useListSortContext,
useTranslate,
getFieldLabelTranslationArgs,
} from 'ra-core';

/**
* A button allowing to change the sort field and order.
Expand Down Expand Up @@ -72,7 +76,12 @@ const SortButton: FC<SortButtonProps> = ({
};

const buttonLabel = translate(label, {
field: translate(`resources.${resource}.fields.${currentSort.field}`),
field: translate(
...getFieldLabelTranslationArgs({
resource,
source: currentSort.field,
})
),
order: translate(`ra.sort.${currentSort.order}`),
_: label,
});
Expand Down Expand Up @@ -115,7 +124,12 @@ const SortButton: FC<SortButtonProps> = ({
data-sort={field}
key={field}
>
{translate(`resources.${resource}.fields.${field}`)}{' '}
{translate(
...getFieldLabelTranslationArgs({
resource,
source: field,
})
)}{' '}
{translate(
`ra.sort.${
currentSort.field === field
Expand Down

0 comments on commit 3e6b82c

Please sign in to comment.