saleor-dashboard/src/attributes/components/AttributeValues/AttributeValues.tsx
Dominik Żegleń f8254fd11b
Bump macaw to 0.3 (#1807)
* Update to new design theme (#1631)

* Update macaw to 0.3.0 (#1623)

* Update macaw to 0.3

* Use proper pagination component

* Fix type errors

* Remove leftover import

* Remove variant and color from confirm button

* Remove alias

* Update macaw

* Fix button type

* Random fixes (#1633)

* Improve layout components

* Use colored svgs

* Minor fixes

* Fix autocomplete loaders

* Fix padding

* Fix button variant

* Remove codegen file

* Fixes after bumping macaw to 0.3 part 2 (#1638)

* Fix various visual bugs

* Fix type errors

* Bump macaw

* Random fixes part 3 (#1647)

* wip

* Fix mismatched paddings

* Fix actions container padding

* Put story in the right directory

* Fix shipping zone picker

* Fix minor visual bugs

* Remove unused imports

* Move styles to separate file

* Random fixes part 4 (#1641)

* Fix various visual bugs

* Fix type errors

* Fix last table item padding

* Add outline on hover

* Fix spaces

* Fix spaces

* Remove dead code

* Fix elevation

* Remove dead code

* Fix shadows

* Add outline to expand button

* Fix spacing

* Fix spacings

* Fix selectable tables hover

* Use proper delete icon

* Fix ConfirmButtonTransitionState imports

* Update src/apps/components/CustomApps/CustomApps.tsx

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>

* Rework error page (#1670)

* Remake error page

* Fix types

* Update error id styles

* Fix types

* Login page rework (#1703)

* Rework login page

* Remove outline

* Fix logo and footer placement

* Sort imports

* Random fixes part 5 (#1669)

* Fix text color in dark mode

* Update password reset pages (#1714)

* Update password reset pages

* Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx

Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>

Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>

* Fix collection page

* Update dark mode logo

* Bring back "create app" button

* Fix spacings

* Fix selects

* Fix login e2e test

* Fix not found page displaying

* Update selector

* Add missing package

* Let dropdown overflow through card

* Fix scroll

* Fix scroll

* Fix overflow on grid element

* Fix e2e tests

* Fix data-test-id

* Update snapshots

* Update messages

* Update macaw

* Update snapshots

* Use stable macaw version

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>

* Update to new design theme (#1631)

* Update macaw to 0.3.0 (#1623)

* Update macaw to 0.3

* Use proper pagination component

* Fix type errors

* Remove leftover import

* Remove variant and color from confirm button

* Remove alias

* Update macaw

* Fix button type

* Random fixes (#1633)

* Improve layout components

* Use colored svgs

* Minor fixes

* Fix autocomplete loaders

* Fix padding

* Fix button variant

* Remove codegen file

* Fixes after bumping macaw to 0.3 part 2 (#1638)

* Fix various visual bugs

* Fix type errors

* Bump macaw

* Random fixes part 3 (#1647)

* wip

* Fix mismatched paddings

* Fix actions container padding

* Put story in the right directory

* Fix shipping zone picker

* Fix minor visual bugs

* Remove unused imports

* Move styles to separate file

* Random fixes part 4 (#1641)

* Fix various visual bugs

* Fix type errors

* Fix last table item padding

* Add outline on hover

* Fix spaces

* Fix spaces

* Remove dead code

* Fix elevation

* Remove dead code

* Fix shadows

* Add outline to expand button

* Fix spacing

* Fix spacings

* Fix selectable tables hover

* Use proper delete icon

* Fix ConfirmButtonTransitionState imports

* Update src/apps/components/CustomApps/CustomApps.tsx

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>

* Rework error page (#1670)

* Remake error page

* Fix types

* Update error id styles

* Fix types

* Login page rework (#1703)

* Rework login page

* Remove outline

* Fix logo and footer placement

* Sort imports

* Random fixes part 5 (#1669)

* Fix text color in dark mode

* Update password reset pages (#1714)

* Update password reset pages

* Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx

Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>

Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>

* Fix collection page

* Update dark mode logo

* Bring back "create app" button

* Fix spacings

* Fix selects

* Fix login e2e test

* Fix not found page displaying

* Update selector

* Add missing package

* Let dropdown overflow through card

* Fix scroll

* Fix scroll

* Fix overflow on grid element

* Fix e2e tests

* Fix data-test-id

* Update snapshots

* Update messages

* Update macaw

* Update snapshots

* Use stable macaw version

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>

* Fix visual bugs and artifacts

* Fix dropdown menus being clipped (#1762)

* wip

* Fix clipped select menus

* Remove unused import

* Fix spacing

* Fix tests

* Fix select content appearing under dialogs (#1777)

* Fix type errors

* Fix bulk delete button placement

* Fix filter arrow buttons

* Fix messages

* Remove backling from pages list

* Move status above events

* Update messages and snapshots

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2022-01-28 13:34:20 +01:00

210 lines
6.3 KiB
TypeScript

import {
Card,
TableCell,
TableFooter,
TableHead,
TableRow
} from "@material-ui/core";
import CardTitle from "@saleor/components/CardTitle";
import ResponsiveTable from "@saleor/components/ResponsiveTable";
import Skeleton from "@saleor/components/Skeleton";
import {
SortableTableBody,
SortableTableRow
} from "@saleor/components/SortableTable";
import TablePagination from "@saleor/components/TablePagination";
import { AttributeValueListFragment_edges_node } from "@saleor/fragments/types/AttributeValueListFragment";
import { Button, DeleteIcon, IconButton, makeStyles } from "@saleor/macaw-ui";
import { renderCollection, stopPropagation } from "@saleor/misc";
import { ListProps, ReorderAction } from "@saleor/types";
import { AttributeInputTypeEnum } from "@saleor/types/globalTypes";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
export interface AttributeValuesProps
extends Pick<ListProps, Exclude<keyof ListProps, "onRowClick">> {
disabled: boolean;
values: AttributeValueListFragment_edges_node[];
onValueAdd: () => void;
onValueDelete: (id: string) => void;
onValueReorder: ReorderAction;
onValueUpdate: (id: string) => void;
inputType: AttributeInputTypeEnum;
}
const useStyles = makeStyles(
theme => ({
columnSwatch: {
width: 100
},
columnAdmin: {
width: 300
},
columnDrag: {
width: theme.spacing(6 + 1.5)
},
columnStore: {
width: "auto"
},
dragIcon: {
cursor: "grab"
},
iconCell: {
width: 84
},
link: {
cursor: "pointer"
},
swatch: {
width: 32,
height: 32,
borderRadius: 4,
backgroundSize: "cover",
backgroundPosition: "center"
}
}),
{ name: "AttributeValues" }
);
const AttributeValues: React.FC<AttributeValuesProps> = ({
disabled,
onValueAdd,
onValueDelete,
onValueReorder,
onValueUpdate,
values,
settings,
onUpdateListSettings,
pageInfo,
onNextPage,
onPreviousPage,
inputType
}) => {
const classes = useStyles({});
const intl = useIntl();
const isSwatch = inputType === AttributeInputTypeEnum.SWATCH;
const numberOfColumns = isSwatch ? 5 : 4;
return (
<Card>
<CardTitle
title={intl.formatMessage({
defaultMessage: "Attribute Values",
description: "section header"
})}
toolbar={
<Button
disabled={disabled}
variant="tertiary"
onClick={onValueAdd}
data-test-id="assignValueButton"
>
<FormattedMessage
defaultMessage="Assign value"
description="assign attribute value button"
/>
</Button>
}
/>
<ResponsiveTable>
<TableHead>
<TableRow>
<TableCell className={classes.columnDrag} />
{isSwatch && (
<TableCell className={classes.columnSwatch}>
<FormattedMessage
defaultMessage="Swatch"
description="attribute values list: slug column header"
/>
</TableCell>
)}
<TableCell className={classes.columnAdmin}>
<FormattedMessage
defaultMessage="Admin"
description="attribute values list: slug column header"
/>
</TableCell>
<TableCell className={classes.columnStore}>
<FormattedMessage
defaultMessage="Default Store View"
description="attribute values list: name column header"
/>
</TableCell>
<TableCell className={classes.iconCell} />
</TableRow>
</TableHead>
<TableFooter>
<TableRow>
<TablePagination
colSpan={numberOfColumns}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
onNextPage={onNextPage}
hasPreviousPage={
pageInfo && !disabled ? pageInfo.hasPreviousPage : false
}
onPreviousPage={onPreviousPage}
settings={settings}
onUpdateListSettings={onUpdateListSettings}
/>
</TableRow>
</TableFooter>
<SortableTableBody onSortEnd={onValueReorder}>
{renderCollection(
values,
(value, valueIndex) => (
<SortableTableRow
className={!!value ? classes.link : undefined}
hover={!!value}
onClick={!!value ? () => onValueUpdate(value.id) : undefined}
key={value?.id}
index={valueIndex || 0}
>
{isSwatch && (
<TableCell className={classes.columnSwatch}>
<div
data-test-id="swatch-image"
className={classes.swatch}
style={
value?.file
? { backgroundImage: `url(${value.file.url})` }
: { backgroundColor: value.value }
}
/>
</TableCell>
)}
<TableCell className={classes.columnAdmin}>
{value?.slug ?? <Skeleton />}
</TableCell>
<TableCell className={classes.columnStore}>
{value?.name ?? <Skeleton />}
</TableCell>
<TableCell className={classes.iconCell}>
<IconButton
variant="secondary"
disabled={disabled}
onClick={stopPropagation(() => onValueDelete(value.id))}
>
<DeleteIcon />
</IconButton>
</TableCell>
</SortableTableRow>
),
() => (
<TableRow>
<TableCell colSpan={numberOfColumns}>
<FormattedMessage
defaultMessage="No values found"
description="No attribute values found"
/>
</TableCell>
</TableRow>
)
)}
</SortableTableBody>
</ResponsiveTable>
</Card>
);
};
AttributeValues.displayName = "AttributeValues";
export default AttributeValues;