saleor-dashboard/src/translations/components/TranslationsEntitiesList/TranslationsEntitiesList.tsx
Michał Droń 347e32ef4a
Replace classnames with clsx (#2759)
* Replace classnames with clsx

* Add clsx to package.json

* Remove classnames

* Remove classnames types

* Restrict classnames in eslint rules
2022-12-02 11:45:19 +01:00

123 lines
3.5 KiB
TypeScript

import {
TableBody,
TableCell,
TableFooter,
TableHead,
} from "@material-ui/core";
import ResponsiveTable from "@saleor/components/ResponsiveTable";
import Skeleton from "@saleor/components/Skeleton";
import { TablePaginationWithContext } from "@saleor/components/TablePagination";
import TableRowLink from "@saleor/components/TableRowLink";
import { makeStyles } from "@saleor/macaw-ui";
import clsx from "clsx";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { maybe, renderCollection } from "../../../misc";
import { ListProps } from "../../../types";
export interface TranslatableEntity {
id: string;
name: string;
completion: {
current: number;
max: number;
};
}
export interface TranslationsEntitiesListProps extends ListProps {
entities: TranslatableEntity[];
getRowHref: (id: string) => string;
}
const useStyles = makeStyles(
{
tableRow: {
cursor: "pointer",
},
textRight: {
textAlign: "right",
},
wideColumn: {
width: "80%",
},
},
{ name: "TranslationsEntitiesList" },
);
const TranslationsEntitiesList: React.FC<TranslationsEntitiesListProps> = props => {
const { disabled, entities, getRowHref } = props;
const classes = useStyles(props);
const intl = useIntl();
return (
<ResponsiveTable>
<TableHead>
<TableRowLink>
<TableCell className={classes.wideColumn}>
<FormattedMessage
id="X6PF8z"
defaultMessage="Name"
description="entity (product, collection, shipping method) name"
/>
</TableCell>
<TableCell className={classes.textRight}>
<FormattedMessage
id="LWmYSU"
defaultMessage="Completed Translations"
/>
</TableCell>
</TableRowLink>
</TableHead>
<TableFooter>
<TableRowLink>
<TablePaginationWithContext colSpan={2} disabled={disabled} />
</TableRowLink>
</TableFooter>
<TableBody>
{renderCollection(
entities,
entity => (
<TableRowLink
className={clsx({
[classes.tableRow]: !!entity,
})}
hover={!!entity}
href={entity && getRowHref(entity.id)}
key={entity ? entity.id : "skeleton"}
>
<TableCell>{entity?.name || <Skeleton />}</TableCell>
<TableCell className={classes.textRight}>
{!!entity?.completion &&
maybe<React.ReactNode>(
() =>
intl.formatMessage(
{
id: "ikRuLs",
defaultMessage: "{current} of {max}",
description: "translation progress",
},
entity.completion,
),
<Skeleton />,
)}
</TableCell>
</TableRowLink>
),
() => (
<TableRowLink>
<TableCell colSpan={2}>
<FormattedMessage
id="vcwrgW"
defaultMessage="No translatable entities found"
/>
</TableCell>
</TableRowLink>
),
)}
</TableBody>
</ResponsiveTable>
);
};
TranslationsEntitiesList.displayName = "TranslationsEntitiesList";
export default TranslationsEntitiesList;