
* Minor fixes for intl messages * Add esbuild-loader * switch from babel to esbuild-loader * use formatjs enforce-id linter * Generate ids for intl messages * id format defined by idInterpolationPattern * Modify intl messages extraction * remove react-intl-translations-manager * remove transpile-tx.js * use formatjs cli * Modify defaultMessages.json * modify ids in defaultMessages.json with defined idInterpolationPattern * Fix errors * Fix page crash * Use babel to transpile tests * Fix useStateFromProps * Improve render count * Add test to useStateFromProps * Fix reloading state buh * Do not check if form with channels is dirty * Stop blocking save if form has not changed * Remove debug code * Fix form disabling * Fix variant selection checkbox onClick * Update translations * Update messages * Use esbuild to build storybook Co-authored-by: Bartłomiej Wiaduch <tukan2can@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
141 lines
3.8 KiB
TypeScript
141 lines
3.8 KiB
TypeScript
import {
|
|
TableBody,
|
|
TableCell,
|
|
TableFooter,
|
|
TableHead,
|
|
TableRow
|
|
} from "@material-ui/core";
|
|
import ResponsiveTable from "@saleor/components/ResponsiveTable";
|
|
import Skeleton from "@saleor/components/Skeleton";
|
|
import TablePagination from "@saleor/components/TablePagination";
|
|
import { makeStyles } from "@saleor/macaw-ui";
|
|
import classNames from "classnames";
|
|
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 Omit<ListProps, "onRowClick"> {
|
|
entities: TranslatableEntity[];
|
|
onRowClick: (code: string) => void;
|
|
}
|
|
|
|
const useStyles = makeStyles(
|
|
{
|
|
tableRow: {
|
|
cursor: "pointer"
|
|
},
|
|
textRight: {
|
|
textAlign: "right"
|
|
},
|
|
wideColumn: {
|
|
width: "80%"
|
|
}
|
|
},
|
|
{ name: "TranslationsEntitiesList" }
|
|
);
|
|
const TranslationsEntitiesList: React.FC<TranslationsEntitiesListProps> = props => {
|
|
const {
|
|
disabled,
|
|
entities,
|
|
onNextPage,
|
|
onPreviousPage,
|
|
onRowClick,
|
|
pageInfo
|
|
} = props;
|
|
|
|
const classes = useStyles(props);
|
|
const intl = useIntl();
|
|
|
|
return (
|
|
<ResponsiveTable>
|
|
<TableHead>
|
|
<TableRow>
|
|
<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>
|
|
</TableRow>
|
|
</TableHead>
|
|
<TableFooter>
|
|
<TableRow>
|
|
<TablePagination
|
|
colSpan={2}
|
|
hasNextPage={
|
|
pageInfo && !disabled ? pageInfo.hasNextPage : undefined
|
|
}
|
|
onNextPage={onNextPage}
|
|
hasPreviousPage={
|
|
pageInfo && !disabled ? pageInfo.hasPreviousPage : undefined
|
|
}
|
|
onPreviousPage={onPreviousPage}
|
|
/>
|
|
</TableRow>
|
|
</TableFooter>
|
|
<TableBody>
|
|
{renderCollection(
|
|
entities,
|
|
entity => (
|
|
<TableRow
|
|
className={classNames({
|
|
[classes.tableRow]: !!entity
|
|
})}
|
|
hover={!!entity}
|
|
onClick={entity ? () => onRowClick(entity.id) : undefined}
|
|
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>
|
|
</TableRow>
|
|
),
|
|
() => (
|
|
<TableRow>
|
|
<TableCell colSpan={2}>
|
|
<FormattedMessage
|
|
id="vcwrgW"
|
|
defaultMessage="No translatable entities found"
|
|
/>
|
|
</TableCell>
|
|
</TableRow>
|
|
)
|
|
)}
|
|
</TableBody>
|
|
</ResponsiveTable>
|
|
);
|
|
};
|
|
TranslationsEntitiesList.displayName = "TranslationsEntitiesList";
|
|
export default TranslationsEntitiesList;
|