Fix broken pagination in swatch attributes (#2282)

* Fix broken pagination in swatch attributes

* Do not apply styling when value is undefined

* Extract logic to function
This commit is contained in:
Michał Droń 2022-09-21 17:35:04 +02:00 committed by GitHub
parent 5dbd6fed8a
commit 88a0db22e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,7 @@ import {
import TablePagination from "@saleor/components/TablePagination"; import TablePagination from "@saleor/components/TablePagination";
import { import {
AttributeInputTypeEnum, AttributeInputTypeEnum,
AttributeValueFragment,
AttributeValueListFragment, AttributeValueListFragment,
} from "@saleor/graphql"; } from "@saleor/graphql";
import { DeleteIcon, IconButton, makeStyles } from "@saleor/macaw-ui"; import { DeleteIcon, IconButton, makeStyles } from "@saleor/macaw-ui";
@ -75,6 +76,15 @@ const useStyles = makeStyles(
{ name: "AttributeValues" }, { name: "AttributeValues" },
); );
const getSwatchCellStyle = (value: AttributeValueFragment) => {
if (!value) {
return;
}
return value.file
? { backgroundImage: `url(${value.file.url})` }
: { backgroundColor: value.value };
};
const AttributeValues: React.FC<AttributeValuesProps> = ({ const AttributeValues: React.FC<AttributeValuesProps> = ({
disabled, disabled,
onValueAdd, onValueAdd,
@ -179,11 +189,7 @@ const AttributeValues: React.FC<AttributeValuesProps> = ({
<div <div
data-test-id="swatch-image" data-test-id="swatch-image"
className={classes.swatch} className={classes.swatch}
style={ style={getSwatchCellStyle(value)}
value?.file
? { backgroundImage: `url(${value.file.url})` }
: { backgroundColor: value.value }
}
/> />
</TableCell> </TableCell>
)} )}