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:
parent
5dbd6fed8a
commit
88a0db22e1
1 changed files with 11 additions and 5 deletions
|
@ -16,6 +16,7 @@ import {
|
|||
import TablePagination from "@saleor/components/TablePagination";
|
||||
import {
|
||||
AttributeInputTypeEnum,
|
||||
AttributeValueFragment,
|
||||
AttributeValueListFragment,
|
||||
} from "@saleor/graphql";
|
||||
import { DeleteIcon, IconButton, makeStyles } from "@saleor/macaw-ui";
|
||||
|
@ -75,6 +76,15 @@ const useStyles = makeStyles(
|
|||
{ 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> = ({
|
||||
disabled,
|
||||
onValueAdd,
|
||||
|
@ -179,11 +189,7 @@ const AttributeValues: React.FC<AttributeValuesProps> = ({
|
|||
<div
|
||||
data-test-id="swatch-image"
|
||||
className={classes.swatch}
|
||||
style={
|
||||
value?.file
|
||||
? { backgroundImage: `url(${value.file.url})` }
|
||||
: { backgroundColor: value.value }
|
||||
}
|
||||
style={getSwatchCellStyle(value)}
|
||||
/>
|
||||
</TableCell>
|
||||
)}
|
||||
|
|
Loading…
Reference in a new issue