Skip to content

Commit

Permalink
Migrate product variant page (#4209)
Browse files Browse the repository at this point in the history
Co-authored-by: wojteknowacki <[email protected]>
  • Loading branch information
poulch and wojteknowacki authored Oct 5, 2023
1 parent a6a6152 commit 29b8740
Show file tree
Hide file tree
Showing 36 changed files with 532 additions and 506 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-toys-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Migrate product variant page to new macaw
9 changes: 6 additions & 3 deletions cypress/support/pages/catalog/products/VariantsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ export function fillUpVariantDetails({
price,
variantName,
}) {
if (variantName) {
cy.get(VARIANTS_SELECTORS.variantNameInput).type(variantName, {
force: true,
});
}
selectAttributeWithType({ attributeType, attributeName });

cy.get(PRICE_LIST.priceInput)
.each(input => {
cy.wrap(input).type(price, { force: true });
Expand All @@ -80,9 +86,6 @@ export function fillUpVariantDetails({
.each(input => {
cy.wrap(input).type(costPrice, { force: true });
});
if (variantName) {
cy.get(VARIANTS_SELECTORS.variantNameInput).type(variantName);
}
if (sku) {
cy.get(VARIANTS_SELECTORS.skuTextField).click({ force: true }).type(sku);
}
Expand Down
15 changes: 7 additions & 8 deletions locale/defaultMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3177,10 +3177,6 @@
"KN7zKn": {
"string": "Error"
},
"KQSONM": {
"context": "tabel column header",
"string": "Cost"
},
"KRqgfo": {
"string": "User is out of your permissions scope"
},
Expand Down Expand Up @@ -3460,6 +3456,10 @@
"context": "customer details, header",
"string": "{fullName} Details"
},
"MwfSVA": {
"context": "input helper text",
"string": "Customers can not add quantities to a single cart above the limit when value is provided."
},
"MxhVZv": {
"string": "Are you sure you want to delete collection's image?"
},
Expand Down Expand Up @@ -7147,10 +7147,6 @@
"context": "WarehousesSection select field add text",
"string": "Add New Warehouse"
},
"n3+6w5": {
"context": "input helper text",
"string": "Your customer won't be allowed to buy bigger quantity per checkout than shown here."
},
"n5vskv": {
"context": "customer's address book, header",
"string": "{fullName}'s Address Book"
Expand Down Expand Up @@ -8386,6 +8382,9 @@
"vprU7C": {
"string": "Select visible order channels"
},
"vuKrlW": {
"string": "Stock"
},
"vwMO04": {
"context": "draft order",
"string": "Created"
Expand Down
40 changes: 20 additions & 20 deletions src/components/Datagrid/customCells/Money/MoneyCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,29 @@ export const moneyCellRenderer = (
return true;
}

const codeFormatter = new Intl.NumberFormat(locale, {
style: "currency",
currencyDisplay: "code",
currency,
});

const symbolFormatter = new Intl.NumberFormat(locale, {
style: "currency",
currencyDisplay: "symbol",
currency,
});

if (!("formatRangeToParts" in codeFormatter)) {
return true;
}

const format = isRange
? new Intl.NumberFormat(locale, {
style: "currency",
currencyDisplay: "code",
currency,
}).formatRangeToParts(value[0], value[1])
: new Intl.NumberFormat(locale, {
style: "currency",
currencyDisplay: "code",
currency,
}).formatToParts(displayValue);
? codeFormatter.formatRangeToParts(value[0], value[1])
: codeFormatter.formatToParts(displayValue);

const shortFormat = isRange
? new Intl.NumberFormat(locale, {
style: "currency",
currencyDisplay: "symbol",
currency,
}).formatRangeToParts(value[0], value[1])
: new Intl.NumberFormat(locale, {
style: "currency",
currencyDisplay: "symbol",
currency,
}).formatToParts(displayValue);
? symbolFormatter.formatRangeToParts(value[0], value[1])
: symbolFormatter.formatToParts(displayValue);

// TODO: replace with macaw-ui theme font weight values
ctx.font = `550 ${theme.baseFontStyle} ${theme.fontFamily}`;
Expand Down
15 changes: 15 additions & 0 deletions src/components/Divider/Divider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Box, BoxProps } from "@saleor/macaw-ui/next";
import React from "react";

export const Divider = (props: BoxProps) => {
return (
<Box
width="100%"
borderBottomStyle="solid"
borderBottomWidth={1}
borderColor="neutralPlain"
height={1}
{...props}
/>
);
};
1 change: 1 addition & 0 deletions src/components/Divider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Divider";
18 changes: 16 additions & 2 deletions src/components/MediaTile/MediaTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ const useStyles = makeStyles(
top: 0,
width: 148,
},
disableOverlay: {
"&$mediaOverlay": {
display: "none !important",
},
},
mediaOverlayShadow: {
"&mediaOverlay": {
$mediaOverlay: {
alignItems: "center",
display: "flex",
justifyContent: "center",
Expand Down Expand Up @@ -76,6 +81,7 @@ interface MediaTileBaseProps {
type?: string;
oembedData?: string;
};
disableOverlay?: boolean;
loading?: boolean;
onDelete?: () => void;
onEdit?: (event: React.ChangeEvent<any>) => void;
Expand All @@ -94,7 +100,14 @@ export type MediaTileProps = MediaTileBaseProps &
);

const MediaTile: React.FC<MediaTileProps> = props => {
const { loading, onDelete, onEdit, editHref, media } = props;
const {
loading,
onDelete,
onEdit,
editHref,
media,
disableOverlay = false,
} = props;
const classes = useStyles(props);
const parsedMediaOembedData = media?.oembedData
? JSON.parse(media.oembedData)
Expand All @@ -106,6 +119,7 @@ const MediaTile: React.FC<MediaTileProps> = props => {
<div
className={clsx(classes.mediaOverlay, {
[classes.mediaOverlayShadow]: loading,
[classes.disableOverlay]: disableOverlay,
})}
>
{loading ? (
Expand Down
5 changes: 3 additions & 2 deletions src/components/SortableTable/SortableHandle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TableCell } from "@material-ui/core";
import { DragIcon, makeStyles } from "@saleor/macaw-ui";
import { makeStyles } from "@saleor/macaw-ui";
import { GripIcon } from "@saleor/macaw-ui/next";
import React from "react";
import { SortableHandle as SortableHandleHoc } from "react-sortable-hoc";

Expand All @@ -22,7 +23,7 @@ const SortableHandle = SortableHandleHoc(() => {

return (
<TableCell className={classes.columnDrag}>
<DragIcon color="primary" />
<GripIcon />
</TableCell>
);
});
Expand Down
4 changes: 3 additions & 1 deletion src/components/TableCellAvatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface AvatarProps {
avatarProps?: string;
children?: React.ReactNode | React.ReactNode[];
badge?: React.ReactNode;
className?: string;
}

const Avatar: React.FC<AvatarProps> = ({
Expand All @@ -22,12 +23,13 @@ const Avatar: React.FC<AvatarProps> = ({
thumbnail,
avatarProps,
badge,
className,
}) => {
const classes = useAvatarStyles();

return (
<div
className={clsx(classes.content, {
className={clsx(classes.content, className, {
[classes.alignRight]: alignRight,
})}
>
Expand Down
5 changes: 3 additions & 2 deletions src/components/TableCellAvatar/TableCellAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ interface TableCellAvatarProps
extends TableCellProps,
Omit<AvatarProps, "children"> {
className?: string;
avatarClassName?: string;
}

const TableCellAvatar: React.FC<TableCellAvatarProps> = props => {
const { className, ...rest } = props;
const { className, avatarClassName, ...rest } = props;

const classes = useStyles(props);

Expand All @@ -23,7 +24,7 @@ const TableCellAvatar: React.FC<TableCellAvatarProps> = props => {
data-test-id="table-cell-avatar"
{...rest}
>
<Avatar {...rest} />
<Avatar className={avatarClassName} {...rest} />
</TableCell>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/fragments/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export const fragmentVariant = gql`
sku
media {
id
url
url(size: 200)
type
oembedData
}
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/hooks.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2589,7 +2589,7 @@ export const ProductVariantFragmentDoc = gql`
sku
media {
id
url
url(size: 200)
type
oembedData
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const TransactionCard: React.FC<TransactionCardProps> = ({
const id = useId();

const user = useUser();
const isStaffUser = hasPermissions(user?.user?.userPermissions, [
const isStaffUser = hasPermissions(user?.user?.userPermissions ?? [], [
PermissionEnum.MANAGE_STAFF,
]);

Expand Down
2 changes: 1 addition & 1 deletion src/orders/views/OrderDetails/OrderDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const OrderDetails: React.FC<OrderDetailsProps> = ({ id, params }) => {
const intl = useIntl();

const user = useUser();
const isStaffUser = hasPermissions(user?.user?.userPermissions, [
const isStaffUser = hasPermissions(user?.user?.userPermissions ?? [], [
PermissionEnum.MANAGE_STAFF,
]);

Expand Down
Loading

0 comments on commit 29b8740

Please sign in to comment.