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 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>
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Reference in a new issue