Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add visibility fields

dominik-zeglen6048a65ffa86
diff --git a/saleor/static/dashboard-next/attributes/components/AttributeList/AttributeList.tsx b/saleor/static/dashboard-next/attributes/components/AttributeList/AttributeList.tsx
index b0f01f25e1..e764e9a637 100644
--- a/saleor/static/dashboard-next/attributes/components/AttributeList/AttributeList.tsx
+++ b/saleor/static/dashboard-next/attributes/components/AttributeList/AttributeList.tsx
@@ -14,6 +14,7 @@ import TablePagination from "@saleor/components/TablePagination";
import i18n from "@saleor/i18n";
import { renderCollection } from "@saleor/misc";
import { ListActions, ListProps } from "@saleor/types";
+import { translateBoolean } from "@saleor/utils/i18n";
import { AttributeList_attributes_edges_node } from "../../types/AttributeList";
export interface AttributeListProps extends ListProps, ListActions {
@@ -22,15 +23,33 @@ export interface AttributeListProps extends ListProps, ListActions {
const useStyles = makeStyles((theme: Theme) => ({
[theme.breakpoints.up("lg")]: {
+ colFaceted: {
+ width: 150
+ },
colName: {
width: "auto"
},
+ colSearchable: {
+ width: 150
+ },
colSlug: {
width: 200
+ },
+ colVisible: {
+ width: 150
}
},
+ colFaceted: {
+ textAlign: "center"
+ },
colName: {},
+ colSearchable: {
+ textAlign: "center"
+ },
colSlug: {},
+ colVisible: {
+ textAlign: "center"
+ },
link: {
cursor: "pointer"
}
@@ -66,11 +85,24 @@ const AttributeList: React.StatelessComponent<AttributeListProps> = ({
<TableCell className={classes.colName}>
{i18n.t("Default Label", { context: "attribute name" })}
</TableCell>
+ <TableCell className={classes.colVisible}>
+ {i18n.t("Visible", { context: "attribute visibility" })}
+ </TableCell>
+ <TableCell className={classes.colSearchable}>
+ {i18n.t("Searchable", {
+ context: "attribute can be searched in dashboard"
+ })}
+ </TableCell>
+ <TableCell className={classes.colFaceted}>
+ {i18n.t("Use in faceted search", {
+ context: "attribute can be searched in storefront"
+ })}
+ </TableCell>
</TableHead>
<TableFooter>
<TableRow>
<TablePagination
- colSpan={3}
+ colSpan={6}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
onNextPage={onNextPage}
hasPreviousPage={
@@ -107,6 +139,27 @@ const AttributeList: React.StatelessComponent<AttributeListProps> = ({
<TableCell className={classes.colName}>
{attribute ? attribute.name : <Skeleton />}
</TableCell>
+ <TableCell className={classes.colVisible}>
+ {attribute ? (
+ translateBoolean(attribute.visibleInStorefront)
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.colSearchable}>
+ {attribute ? (
+ translateBoolean(attribute.filterableInDashboard)
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.colFaceted}>
+ {attribute ? (
+ translateBoolean(attribute.filterableInStorefront)
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
</TableRow>
);
},
diff --git a/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx b/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx
index b5449cd108..d101b84446 100644
--- a/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx
+++ b/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx
@@ -17,6 +17,7 @@ import {
AttributeDetailsFragment_values
} from "../../types/AttributeDetailsFragment";
import AttributeDetails from "../AttributeDetails";
+import AttributeProperties from "../AttributeProperties";
import AttributeValues from "../AttributeValues";
export interface AttributePageProps {
@@ -34,9 +35,13 @@ export interface AttributePageProps {
}
export interface AttributePageFormData {
+ filterableInDashboard: boolean;
inputType: AttributeInputTypeEnum;
+ filterableInStorefront: boolean;
name: string;
slug: string;
+ storefrontSearchPosition: string;
+ visibleInStorefront: boolean;
}
const AttributePage: React.FC<AttributePageProps> = ({
@@ -55,17 +60,34 @@ const AttributePage: React.FC<AttributePageProps> = ({
const initialForm: AttributePageFormData =
attribute === null
? {
+ filterableInDashboard: false,
+ filterableInStorefront: false,
inputType: AttributeInputTypeEnum.DROPDOWN,
name: "",
- slug: ""
+ slug: "",
+ storefrontSearchPosition: "",
+ visibleInStorefront: false
}
: {
+ filterableInDashboard: maybe(
+ () => attribute.filterableInDashboard,
+ false
+ ),
+ filterableInStorefront: maybe(
+ () => attribute.filterableInStorefront,
+ false
+ ),
inputType: maybe(
() => attribute.inputType,
AttributeInputTypeEnum.DROPDOWN
),
name: maybe(() => attribute.name, ""),
- slug: maybe(() => attribute.slug, "")
+ slug: maybe(() => attribute.slug, ""),
+ storefrontSearchPosition: maybe(
+ () => attribute.storefrontSearchPosition.toString(),
+ ""
+ ),
+ visibleInStorefront: maybe(() => attribute.visibleInStorefront, false)
};
return (
@@ -100,14 +122,14 @@ const AttributePage: React.FC<AttributePageProps> = ({
onValueUpdate={onValueUpdate}
/>
</div>
- {/* TODO: Uncomment after restricting some attributes to be only product attributes */}
- {/* <div>
+ <div>
<AttributeProperties
data={data}
+ errors={formErrors}
disabled={disabled}
onChange={change}
/>
- </div> */}
+ </div>
</Grid>
<SaveButtonBar
disabled={disabled}
diff --git a/saleor/static/dashboard-next/attributes/components/AttributeProperties/AttributeProperties.tsx b/saleor/static/dashboard-next/attributes/components/AttributeProperties/AttributeProperties.tsx
index ab27bc82e6..078d168825 100644
--- a/saleor/static/dashboard-next/attributes/components/AttributeProperties/AttributeProperties.tsx
+++ b/saleor/static/dashboard-next/attributes/components/AttributeProperties/AttributeProperties.tsx
@@ -1,29 +1,35 @@
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
+import TextField from "@material-ui/core/TextField";
import Typography from "@material-ui/core/Typography";
import React from "react";
-import CardSpacer from "../../../components/CardSpacer";
-import CardTitle from "../../../components/CardTitle";
-import ControlledSwitch from "../../../components/ControlledSwitch";
-import Hr from "../../../components/Hr";
-import i18n from "../../../i18n";
+import CardSpacer from "@saleor/components/CardSpacer";
+import CardTitle from "@saleor/components/CardTitle";
+import ControlledSwitch from "@saleor/components/ControlledSwitch";
+import FormSpacer from "@saleor/components/FormSpacer";
+import Hr from "@saleor/components/Hr";
+import i18n from "@saleor/i18n";
+import { FormErrors } from "@saleor/types";
import { AttributePageFormData } from "../AttributePage";
export interface AttributePropertiesProps {
data: AttributePageFormData;
disabled: boolean;
+ errors: FormErrors<"storefrontSearchPosition">;
onChange: (event: React.ChangeEvent<any>) => void;
}
const AttributeProperties: React.FC<AttributePropertiesProps> = ({
+ data,
+ errors,
disabled,
onChange
}) => (
<Card>
<CardTitle title={i18n.t("Properties")} />
<CardContent>
- <Typography variant="subtitle1">
+ {/* <Typography variant="subtitle1">
{i18n.t("General Properties")}
</Typography>
<Hr />
@@ -43,6 +49,61 @@ const AttributeProperties: React.FC<AttributePropertiesProps> = ({
</>
}
onChange={onChange}
+ /> */}
+
+ <Typography variant="subtitle1">
+ {i18n.t("Storefront Properties")}
+ </Typography>
+ <Hr />
+ <ControlledSwitch
+ name={"filterableInStorefront" as keyof AttributePageFormData}
+ checked={data.filterableInStorefront}
+ disabled={disabled}
+ label={i18n.t("Use in faceted navigation")}
+ onChange={onChange}
+ />
+ {data.filterableInStorefront && (
+ <TextField
+ disabled={disabled}
+ error={!!errors.storefrontSearchPosition}
+ fullWidth
+ helperText={errors.storefrontSearchPosition}
+ name={"storefrontSearchPosition" as keyof AttributePageFormData}
+ label={i18n.t("Position in faceted navigation")}
+ value={data.storefrontSearchPosition}
+ onChange={onChange}
+ />
+ )}
+ <FormSpacer />
+ <ControlledSwitch
+ name={"visibleInStorefront" as keyof AttributePageFormData}
+ checked={data.visibleInStorefront}
+ disabled={disabled}
+ label={i18n.t("Visible on Product Page in Storefront", {
+ context: "attribute"
+ })}
+ onChange={onChange}
+ />
+ <CardSpacer />
+
+ <Typography variant="subtitle1">
+ {i18n.t("Dashboard Properties")}
+ </Typography>
+ <Hr />
+ <CardSpacer />
+ <ControlledSwitch
+ name={"filterableInDashboard" as keyof AttributePageFormData}
+ checked={data.filterableInDashboard}
+ disabled={disabled}
+ label={i18n.t("Use in Filtering")}
+ secondLabel={
+ <Typography variant="caption">
+ {i18n.t(
+ "If enabled, you’ll be able to use this attribute to filter products in product list."
+ )}
+ </Typography>
+ }
+ onChange={onChange}
/>
</CardContent>
</Card>
diff --git a/saleor/static/dashboard-next/attributes/fixtures.ts b/saleor/static/dashboard-next/attributes/fixtures.ts
index c4b4d95730..dd79b3f998 100644
--- a/saleor/static/dashboard-next/attributes/fixtures.ts
+++ b/saleor/static/dashboard-next/attributes/fixtures.ts
@@ -6,10 +6,13 @@ import { AttributeList_attributes_edges_node } from "./types/AttributeList";
export const attribute = {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: false,
+ filterableInStorefront: true,
id: "UHJvZHVjdEF0dHJpYnV0ZTo5",
inputType: AttributeInputTypeEnum.DROPDOWN,
name: "Author",
slug: "author",
+ storefrontSearchPosition: 2,
values: [
{
__typename: "AttributeValue" as "AttributeValue",
@@ -29,13 +32,16 @@ export const attribute = {
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: true
};
export const attributes: AttributeList_attributes_edges_node[] = [
{
node: {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: true,
+ filterableInStorefront: false,
id: "UHJvZHVjdEF0dHJpYnV0ZTo5",
name: "Author",
slug: "author",
@@ -58,12 +64,15 @@ export const attributes: AttributeList_attributes_edges_node[] = [
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: true
}
},
{
node: {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: true,
+ filterableInStorefront: false,
id: "UHJvZHVjdEF0dHJpYnV0ZTo2",
name: "Box Size",
slug: "box-size",
@@ -104,12 +113,15 @@ export const attributes: AttributeList_attributes_edges_node[] = [
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: false
}
},
{
node: {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: false,
+ filterableInStorefront: true,
id: "UHJvZHVjdEF0dHJpYnV0ZToz",
name: "Brand",
slug: "brand",
@@ -123,12 +135,15 @@ export const attributes: AttributeList_attributes_edges_node[] = [
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: false
}
},
{
node: {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: true,
+ filterableInStorefront: true,
id: "UHJvZHVjdEF0dHJpYnV0ZTo4",
name: "Candy Box Size",
slug: "candy-box-size",
@@ -160,12 +175,15 @@ export const attributes: AttributeList_attributes_edges_node[] = [
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: false
}
},
{
node: {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: true,
+ filterableInStorefront: true,
id: "UHJvZHVjdEF0dHJpYnV0ZTo1",
name: "Coffee Genre",
slug: "coffee-genre",
@@ -188,12 +206,15 @@ export const attributes: AttributeList_attributes_edges_node[] = [
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: true
}
},
{
node: {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: false,
+ filterableInStorefront: true,
id: "UHJvZHVjdEF0dHJpYnV0ZToy",
name: "Collar",
slug: "collar",
@@ -225,12 +246,15 @@ export const attributes: AttributeList_attributes_edges_node[] = [
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: true
}
},
{
node: {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: false,
+ filterableInStorefront: false,
id: "UHJvZHVjdEF0dHJpYnV0ZTox",
name: "Color",
slug: "color",
@@ -253,12 +277,15 @@ export const attributes: AttributeList_attributes_edges_node[] = [
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: true
}
},
{
node: {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: true,
+ filterableInStorefront: false,
id: "UHJvZHVjdEF0dHJpYnV0ZToxMg==",
name: "Cover",
slug: "cover",
@@ -317,12 +344,15 @@ export const attributes: AttributeList_attributes_edges_node[] = [
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: false
}
},
{
node: {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: true,
+ filterableInStorefront: true,
id: "UHJvZHVjdEF0dHJpYnV0ZTo3",
name: "Flavor",
slug: "flavor",
@@ -345,12 +375,15 @@ export const attributes: AttributeList_attributes_edges_node[] = [
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: true
}
},
{
node: {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: false,
+ filterableInStorefront: true,
id: "UHJvZHVjdEF0dHJpYnV0ZToxMQ==",
name: "Language",
slug: "language",
@@ -373,12 +406,15 @@ export const attributes: AttributeList_attributes_edges_node[] = [
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: true
}
},
{
node: {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: true,
+ filterableInStorefront: true,
id: "UHJvZHVjdEF0dHJpYnV0ZToxMA==",
name: "Publisher",
slug: "publisher",
@@ -401,12 +437,15 @@ export const attributes: AttributeList_attributes_edges_node[] = [
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: true
}
},
{
node: {
__typename: "Attribute" as "Attribute",
+ filterableInDashboard: true,
+ filterableInStorefront: true,
id: "UHJvZHVjdEF0dHJpYnV0ZTo0",
name: "Size",
slug: "size",
@@ -465,7 +504,8 @@ export const attributes: AttributeList_attributes_edges_node[] = [
type: AttributeValueType.STRING,
value: ""
}
- ]
+ ],
+ visibleInStorefront: true
}
}
].map(edge => edge.node);
diff --git a/saleor/static/dashboard-next/attributes/views/AttributeCreate/AttributeCreate.tsx b/saleor/static/dashboard-next/attributes/views/AttributeCreate/AttributeCreate.tsx
index 557b201554..a1f2e9c83f 100644
--- a/saleor/static/dashboard-next/attributes/views/AttributeCreate/AttributeCreate.tsx
+++ b/saleor/static/dashboard-next/attributes/views/AttributeCreate/AttributeCreate.tsx
@@ -99,6 +99,10 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ params }) => {
variables: {
input: {
...input,
+ storefrontSearchPosition: parseInt(
+ input.storefrontSearchPosition,
+ 0
+ ),
values: values.map(value => ({
name: value.name,
value: value.slug
diff --git a/saleor/static/dashboard-next/attributes/views/AttributeDetails/AttributeDetails.tsx b/saleor/static/dashboard-next/attributes/views/AttributeDetails/AttributeDetails.tsx
index 6c8b8d045e..ca1f2191af 100644
--- a/saleor/static/dashboard-next/attributes/views/AttributeDetails/AttributeDetails.tsx
+++ b/saleor/static/dashboard-next/attributes/views/AttributeDetails/AttributeDetails.tsx
@@ -168,8 +168,11 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ id, params }) => {
variables: {
id,
input: {
- name: input.name,
- slug: input.slug
+ ...input,
+ storefrontSearchPosition: parseInt(
+ input.storefrontSearchPosition,
+ 0
+ )
}
}
})
diff --git a/saleor/static/dashboard-next/components/ControlledSwitch.tsx b/saleor/static/dashboard-next/components/ControlledSwitch.tsx
index 87b308ba27..07a244006b 100644
--- a/saleor/static/dashboard-next/components/ControlledSwitch.tsx
+++ b/saleor/static/dashboard-next/components/ControlledSwitch.tsx
@@ -7,6 +7,9 @@ const styles = (theme: Theme) =>
createStyles({
label: {
marginLeft: theme.spacing.unit * 2
+ },
+ labelText: {
+ fontSize: 14
}
});
@@ -15,7 +18,7 @@ interface ControlledSwitchProps extends WithStyles<typeof styles> {
disabled?: boolean;
label: string | React.ReactNode;
name: string;
- secondLabel?: string;
+ secondLabel?: string | React.ReactNode;
uncheckedLabel?: string | React.ReactNode;
onChange?(event: React.ChangeEvent<any>);
}
@@ -46,7 +49,17 @@ export const ControlledSwitch = withStyles(styles, {
}
label={
<div className={classes.label}>
- {uncheckedLabel ? (checked ? label : uncheckedLabel) : label}
+ {uncheckedLabel ? (
+ checked ? (
+ label
+ ) : (
+ uncheckedLabel
+ )
+ ) : typeof label === "string" ? (
+ <span className={classes.labelText}>{label}</span>
+ ) : (
+ label
+ )}
<div>{secondLabel ? secondLabel : null}</div>
</div>
}
diff --git a/saleor/static/dashboard-next/storybook/stories/attributes/AttributePage.tsx b/saleor/static/dashboard-next/storybook/stories/attributes/AttributePage.tsx
index 82e4d30589..1537be1b4e 100644
--- a/saleor/static/dashboard-next/storybook/stories/attributes/AttributePage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/attributes/AttributePage.tsx
@@ -36,7 +36,10 @@ storiesOf("Views / Attributes / Attribute details", module)
))
.add("no values", () => <AttributePage {...props} values={undefined} />)
.add("form errors", () => (
- <AttributePage {...props} errors={["name", "slug"].map(formError)} />
+ <AttributePage
+ {...props}
+ errors={["name", "slug", "storefrontSearchPosition"].map(formError)}
+ />
))
.add("multiple select input", () => (
<AttributePage
diff --git a/saleor/static/dashboard-next/utils/i18n.ts b/saleor/static/dashboard-next/utils/i18n.ts
new file mode 100644
index 0000000000..2781c00564
--- /dev/null
+++ b/saleor/static/dashboard-next/utils/i18n.ts
@@ -0,0 +1,5 @@
+import i18n from "@saleor/i18n";
+
+export function translateBoolean(value: boolean): string {
+ return value ? i18n.t("Yes") : i18n.t("No");
+}