Sort permissions and add enum name (#3268)

This commit is contained in:
Jakub Neander 2023-03-07 10:50:11 +01:00 committed by GitHub
parent d79e21349a
commit b7abf57a05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,11 @@ import { makeStyles } from "@saleor/macaw-ui";
import React from "react";
import { useIntl } from "react-intl";
const byAlphabeticalOrder =
<T extends {}>(field: string) =>
(a: T, b: T) =>
a[field].localeCompare(b[field]);
const useStyles = makeStyles(
theme => ({
checkboxContainer: {
@ -50,7 +55,6 @@ const AccountPermissions: React.FC<AccountPermissionsProps> = props => {
const {
data,
disabled,
permissions,
permissionsExceeded,
onChange,
description,
@ -58,6 +62,10 @@ const AccountPermissions: React.FC<AccountPermissionsProps> = props => {
errorMessage,
} = props;
const permissions = Object.values(props.permissions).sort(
byAlphabeticalOrder("name"),
);
const classes = useStyles(props);
const intl = useIntl();
const { user } = useUser();
@ -192,13 +200,14 @@ const AccountPermissions: React.FC<AccountPermissionsProps> = props => {
id={perm.code}
primary={perm.name.replace(/\./, "")}
secondary={
perm.lastSource &&
intl.formatMessage({
id: "VmMDLN",
defaultMessage:
"This group is last source of that permission",
description: "permission list item description",
})
perm.lastSource
? intl.formatMessage({
id: "VmMDLN",
defaultMessage:
"This group is last source of that permission",
description: "permission list item description",
})
: perm.code
}
/>
</ListItem>