Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product editor fixes #240

Merged
merged 29 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4603229
feat: highlight active tree item
mikemurray Mar 6, 2020
3dc222a
feat: add left spacing
mikemurray Mar 6, 2020
d212e7e
fix: use notistack snackbars
mikemurray Mar 6, 2020
25dc649
feat: add product variant GQL fragment
mikemurray Mar 10, 2020
40363ba
feat: add product with variants and options GQL fragment
mikemurray Mar 10, 2020
8b41548
feat: add archive product variants mutation definition
mikemurray Mar 10, 2020
51f18c6
feat: add clone product variants mutation definition
mikemurray Mar 10, 2020
0b8407a
feat: add create product variant mutation definition
mikemurray Mar 10, 2020
68c8d4c
feat: add update product variant mutation definition
mikemurray Mar 10, 2020
7747e9e
feat: add update product variant prices mutation definition
mikemurray Mar 10, 2020
7dd281a
feat: add product query definition
mikemurray Mar 10, 2020
b1686e6
refactor: import queries and mutations
mikemurray Mar 10, 2020
9ebd0b2
feat: use product with variants fragment
mikemurray Mar 10, 2020
ec8dd1c
chore: remove unused file
mikemurray Mar 10, 2020
cd27437
chore: remove unused file
mikemurray Mar 10, 2020
3b8646e
chore: remove unused file
mikemurray Mar 10, 2020
bd102d5
chore: remove unused file
mikemurray Mar 10, 2020
7d2c642
fix: skip query when `shopId` is undefined
mikemurray Mar 10, 2020
6cd0407
fix: skip queries when `shopId` is undefined
mikemurray Mar 10, 2020
b457733
chore: remove commented code
mikemurray Mar 10, 2020
fdb84e0
feat: adjust padding
mikemurray Mar 11, 2020
f897134
feat: adjust padding
mikemurray Mar 11, 2020
a7426e0
feat: update list item selected styles
mikemurray Mar 11, 2020
4181295
feat: remove padding
mikemurray Mar 11, 2020
1a91d68
fix: use variant fragment
mikemurray Mar 11, 2020
2904f3a
chore: update lockfile
mikemurray Mar 11, 2020
4f70af9
fix: padding
mikemurray Mar 12, 2020
0663feb
fix: styles
mikemurray Mar 12, 2020
50c4579
Merge branch 'trunk' into fix-237-mikemurray-product-editor
mikemurray Mar 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import { makeStyles, Box, Divider } from "@material-ui/core";
import useProduct from "../hooks/useProduct";

const useStyles = makeStyles((theme) => ({
root: {
paddingTop: theme.spacing(2),
paddingBottom: theme.spacing(2)
},
breadcrumbs: {
display: "flex",
alignItems: "center",
Expand Down Expand Up @@ -104,12 +100,10 @@ function ProductHeader({ shouldDisplayStatus }) {
}

return (
<div className={classes.root}>
<>
<Box
display="flex"
alignItems="center"
paddingRight={2}
paddingLeft={2}
>
<Box
display="flex"
Expand Down Expand Up @@ -184,7 +178,7 @@ function ProductHeader({ shouldDisplayStatus }) {
archiveMenuItem
}
</Menu>
</div>
</>
);
}

Expand Down
82 changes: 71 additions & 11 deletions imports/plugins/included/product-admin/client/blocks/VariantList.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,64 @@ const useStyles = makeStyles((theme) => ({
listItemContainer: {
"&:hover $listItemAction": {
display: "block"
},
[theme.breakpoints.up("md")]: {
paddingLeft: theme.spacing(2),
paddingRight: theme.spacing(2)
}
},
listItem: {
paddingLeft: theme.spacing(7)
"&$selected $listItemPrimaryText, &$selected:hover $listItemPrimaryText": {
fontWeight: theme.typography.fontWeightBold
},
[theme.breakpoints.up("xs")]: {
paddingLeft: theme.spacing(8)
},
[theme.breakpoints.up("md")]: {
"paddingLeft": theme.spacing(7),
"&$selected": {
backgroundColor: "transparent"
},
"&$selected:hover": {
backgroundColor: "white"
}
}
},
listItemButton: {
"transition": theme.transitions.create("background-color", {
duration: theme.transitions.duration.shortest
}),
"&:hover": {
"textDecoration": "none",
"backgroundColor": "white",
"boxShadow": theme.shadows[2],
"borderRadius": theme.shape.borderRadius,
"@media (hover: none)": {
backgroundColor: "transparent",
boxShadow: "none",
borderRadius: 0
}
}
},
nested: {
paddingLeft: theme.spacing(8)
[theme.breakpoints.up("md")]: {
paddingLeft: theme.spacing(6)
},
[theme.breakpoints.up("xs")]: {
paddingLeft: theme.spacing(4)
}
},
listItemAction: {
display: "none"
}
[theme.breakpoints.up("md")]: {
display: "none"
}
},
/* Pseudo-class applied to the `component`'s `focusVisibleClassName` prop if `button={true}`. */
focusVisible: {},
/* Pseudo-class applied to the `ListItemText`'s `primary label` when `selected`. */
listItemPrimaryText: {},
/* Pseudo-class applied to the root element if `selected={true}`. */
selected: {}
}));

/**
Expand All @@ -51,25 +98,26 @@ function getItemSecondaryLabel({ isVisible }) {
*/
export default function VariantList() {
const {
currentVariant,
onArchiveProductVariants,
onCreateVariant,
onToggleVariantVisibility,
onCloneProductVariants,
onRestoreProduct,
product,
variant: currentVariant
variant: variantProp
} = useProduct();
const classes = useStyles();
const history = useHistory();
const [expandedIds, setExpandedIds] = useState([]);


useEffect(() => {
if (currentVariant) {
setExpandedIds((prevState) => [...prevState, currentVariant._id]);
if (variantProp) {
setExpandedIds((prevState) => [...prevState, variantProp._id]);
}
}, [
currentVariant
variantProp
]);

const renderVariantTree = useCallback((variants, parentVariant) => {
Expand All @@ -95,17 +143,25 @@ export default function VariantList() {
<ListItem
component="nav"
ContainerProps={{
className: classes.listItemContainer,
className: clsx({
[classes.listItemContainer]: true,
[classes.nested]: Boolean(parentVariant)
}),
isExpanded,
hasChildren,
onArrowButtonClick: () => toggleExpand(variant._id)
}}
ContainerComponent={VariantListItemContainer}
classes={{
root: classes.listItem,
button: classes.listItemButton,
selected: classes.selected
}}
className={clsx({
[classes.listItem]: true,
[classes.nested]: Boolean(parentVariant)
// [classes.nested]: Boolean(parentVariant)
})}
button
selected={currentVariant && (currentVariant._id === variant._id)}
onClick={() => {
const url = getPDPUrl(product._id, variant._id, parentVariant && parentVariant._id);
history.push(url);
Expand All @@ -116,6 +172,9 @@ export default function VariantList() {
}}
>
<ListItemText
primaryTypographyProps={{
className: classes.listItemPrimaryText
}}
primary={variant.optionTitle || variant.title || "Untitled"}
secondary={getItemSecondaryLabel(variant)}
/>
Expand Down Expand Up @@ -153,6 +212,7 @@ export default function VariantList() {
}, [
expandedIds,
classes,
currentVariant,
product,
onArchiveProductVariants,
onCreateVariant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
import ChevronDown from "mdi-material-ui/ChevronDown";
import ChevronRight from "mdi-material-ui/ChevronRight";

const useStyles = makeStyles(() => ({
const useStyles = makeStyles((theme) => ({
expandButton: {
position: "absolute",
left: 0,
left: theme.spacing(2),
top: "50%",
transform: "translateY(-50%)",
zIndex: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import gql from "graphql-tag";

export default gql`
fragment ProductVariant on ProductVariant {
_id
attributeLabel
barcode
height
index
isDeleted
isVisible
length
metafields {
key
value
}
minOrderQuantity
optionTitle
originCountry
shop {
_id
}
sku
title
updatedAt
weight
width
isTaxable
taxCode
taxDescription
}
`;

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import gql from "graphql-tag";
import ProductVariant from "./productVariant";

export default gql`
fragment Product on Product {
_id
currentProductHash
description
isDeleted
isVisible
metaDescription
metafields {
key
value
}
originCountry
pageTitle
productType
publishedAt
publishedProductHash
shop {
_id
}
slug
socialMetadata {
message
service
}
supportedFulfillmentTypes
tagIds
tags {
nodes {
_id
name
}
}
title
updatedAt
vendor
variants {
...ProductVariant
options {
...ProductVariant
}
}
}
${ProductVariant}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import gql from "graphql-tag";

export default gql`
mutation archiveProductVariants($input: ArchiveProductVariantsInput!) {
archiveProductVariants(input: $input) {
variants {
_id
}
}
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import gql from "graphql-tag";

export default gql`
mutation cloneProductVariants($input: CloneProductVariantsInput!) {
cloneProductVariants(input: $input) {
variants {
_id
}
}
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import gql from "graphql-tag";
import ProductVariant from "../fragments/productVariant";

export default gql`
mutation createProductVariant($input: CreateProductVariantInput!) {
createProductVariant(input: $input) {
variant {
...ProductVariant
}
}
}
${ProductVariant}
`;
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import gql from "graphql-tag";
import Product from "../fragments/productWithVariants";

export default gql`
mutation updateProduct($input: UpdateProductInput!){
updateProduct(input: $input){
product {
isVisible
...Product
}
}
}
}
${Product}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import gql from "graphql-tag";
import ProductVariant from "../fragments/productVariant";

export default gql`
mutation updateProductVariant($input: UpdateProductVariantInput!) {
updateProductVariant(input: $input) {
variant {
...ProductVariant
}
}
}
${ProductVariant}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import gql from "graphql-tag";

export default gql`
mutation updateProductVariantPrices($input: UpdateProductVariantPricesInput!) {
updateProductVariantPrices(input: $input) {
variant {
_id
price
compareAtPrice
}
}
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import gql from "graphql-tag";
import Product from "../fragments/productWithVariants";

export default gql`
query product($productId: ID!, $shopId: ID!) {
product(productId: $productId, shopId: $shopId) {
...Product
}
}
${Product}
`;
Loading