Skip to content

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

Add basic attribute details view

dominik-zeglen8979501392a5
diff --git a/saleor/static/dashboard-next/attributes/components/AttributeDeleteDialog/AttributeDeleteDialog.tsx b/saleor/static/dashboard-next/attributes/components/AttributeDeleteDialog/AttributeDeleteDialog.tsx
new file mode 100644
index 0000000000..105a74030c
--- /dev/null
+++ b/saleor/static/dashboard-next/attributes/components/AttributeDeleteDialog/AttributeDeleteDialog.tsx
@@ -0,0 +1,39 @@
+import DialogContentText from "@material-ui/core/DialogContentText";
+import * as React from "react";
+
+import ActionDialog from "@saleor/components/ActionDialog";
+import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
+import i18n from "@saleor/i18n";
+
+export interface AttributeDeleteDialogProps {
+ confirmButtonState: ConfirmButtonTransitionState;
+ open: boolean;
+ onConfirm: () => void;
+ onClose: () => void;
+ attributeName: string;
+}
+
+const AttributeDeleteDialog: React.FC<AttributeDeleteDialogProps> = () => (
+ <ActionDialog
+ open={params.action === "remove"}
+ onClose={() => navigate(productUrl(id), true)}
+ confirmButtonState={deleteTransitionState}
+ onConfirm={() => deleteProduct.mutate({ id })}
+ variant="delete"
+ title={i18n.t("Remove product")}
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to remove <strong>{{ name }}</strong>?",
+ {
+ name: product ? product.name : undefined
+ }
+ )
+ }}
+ />
+ </ActionDialog>
+);
+
+AttributeDeleteDialog.displayName = "AttributeDeleteDialog";
+export default AttributeDeleteDialog;
diff --git a/saleor/static/dashboard-next/attributes/components/AttributeDeleteDialog/index.ts b/saleor/static/dashboard-next/attributes/components/AttributeDeleteDialog/index.ts
new file mode 100644
index 0000000000..d3f62c3dfc
--- /dev/null
+++ b/saleor/static/dashboard-next/attributes/components/AttributeDeleteDialog/index.ts
@@ -0,0 +1,2 @@
+export { default } from './AttributeDeleteDialog';
+export * from './AttributeDeleteDialog';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/attributes/components/AttributeValues/AttributeValues.tsx b/saleor/static/dashboard-next/attributes/components/AttributeValues/AttributeValues.tsx
index 500cd38ad2..2c2d7148e4 100644
--- a/saleor/static/dashboard-next/attributes/components/AttributeValues/AttributeValues.tsx
+++ b/saleor/static/dashboard-next/attributes/components/AttributeValues/AttributeValues.tsx
@@ -76,7 +76,9 @@ const AttributeValues: React.FC<AttributeValuesProps> = ({
</TableHead>
<TableBody>
{renderCollection(
- values.sort((a, b) => (a.sortOrder > b.sortOrder ? 1 : -1)),
+ values
+ ? values.sort((a, b) => (a.sortOrder > b.sortOrder ? 1 : -1))
+ : undefined,
value => (
<TableRow
className={!!value ? classes.link : undefined}
diff --git a/saleor/static/dashboard-next/attributes/index.tsx b/saleor/static/dashboard-next/attributes/index.tsx
index 9aa9ffb435..cedfe155d7 100644
--- a/saleor/static/dashboard-next/attributes/index.tsx
+++ b/saleor/static/dashboard-next/attributes/index.tsx
@@ -7,8 +7,11 @@ import i18n from "../i18n";
import {
attributeAddPath,
attributeListPath,
- AttributeListUrlQueryParams
+ AttributeListUrlQueryParams,
+ attributePath,
+ AttributeUrlQueryParams
} from "./urls";
+import AttributeDetailsComponent from "./views/AttributeDetails";
import AttributeListComponent from "./views/AttributeList";
const AttributeList: React.FC<RouteComponentProps<{}>> = ({ location }) => {
@@ -17,11 +20,21 @@ const AttributeList: React.FC<RouteComponentProps<{}>> = ({ location }) => {
return <AttributeListComponent params={params} />;
};
+const AttributeDetails: React.FC<RouteComponentProps<{ id: string }>> = ({
+ location,
+ match
+}) => {
+ const qs = parseQs(location.search.substr(1));
+ const params: AttributeUrlQueryParams = qs;
+ return <AttributeDetailsComponent id={match.params.id} params={params} />;
+};
+
export const AttributeSection: React.FC = () => (
<>
<WindowTitle title={i18n.t("Attributes")} />
<Switch>
<Route exact path={attributeListPath} component={AttributeList} />
+ <Route path={attributePath(":id")} component={AttributeDetails} />
</Switch>
</>
);
diff --git a/saleor/static/dashboard-next/attributes/urls.ts b/saleor/static/dashboard-next/attributes/urls.ts
index bb50944e51..361e7df6b3 100644
--- a/saleor/static/dashboard-next/attributes/urls.ts
+++ b/saleor/static/dashboard-next/attributes/urls.ts
@@ -15,6 +15,7 @@ export const attributeListUrl = (params?: AttributeListUrlQueryParams) =>
export type AttributeAddUrlDialog =
| "add-value"
+ | "edit-value"
| "remove-value"
| "remove-values";
export type AttributeAddUrlQueryParams = Dialog<AttributeAddUrlDialog>;
@@ -22,6 +23,13 @@ export const attributeAddPath = urlJoin(attributeSection, "add");
export const attributeAddUrl = (params?: AttributeAddUrlQueryParams) =>
attributeAddPath + "?" + stringifyQs(params);
+export type AttributeUrlDialog =
+ | "add-value"
+ | "edit-value"
+ | "remove"
+ | "remove-value"
+ | "remove-values";
+export type AttributeUrlQueryParams = BulkAction & Dialog<AttributeUrlDialog>;
export const attributePath = (id: string) => urlJoin(attributeSection, id);
-export const attributeUrl = (id: string) =>
- attributePath(encodeURIComponent(id));
+export const attributeUrl = (id: string, params?: AttributeUrlQueryParams) =>
+ attributePath(encodeURIComponent(id)) + "?" + stringifyQs(params);
diff --git a/saleor/static/dashboard-next/attributes/views/AttributeDetails/AttributeDetails.tsx b/saleor/static/dashboard-next/attributes/views/AttributeDetails/AttributeDetails.tsx
new file mode 100644
index 0000000000..e76bc50103
--- /dev/null
+++ b/saleor/static/dashboard-next/attributes/views/AttributeDetails/AttributeDetails.tsx
@@ -0,0 +1,72 @@
+import * as React from "react";
+
+import useNavigator from "@saleor/hooks/useNavigator";
+import useNotifier from "@saleor/hooks/useNotifier";
+import i18n from "@saleor/i18n";
+import { maybe } from "../../../misc";
+import AttributePage from "../../components/AttributePage";
+import { AttributeDetailsQuery } from "../../queries";
+import {
+ attributeListUrl,
+ attributeUrl,
+ AttributeUrlDialog,
+ AttributeUrlQueryParams
+} from "../../urls";
+
+interface AttributeDetailsProps {
+ id: string;
+ params: AttributeUrlQueryParams;
+}
+
+const AttributeDetails: React.FC<AttributeDetailsProps> = ({ id, params }) => {
+ const navigate = useNavigator();
+ const notify = useNotifier();
+
+ const closeModal = () =>
+ navigate(
+ attributeListUrl({
+ ...params,
+ action: undefined,
+ ids: undefined
+ }),
+ true
+ );
+
+ const openModal = (action: AttributeUrlDialog) =>
+ navigate(
+ attributeUrl(id, {
+ ...params,
+ action
+ })
+ );
+
+ const handleDelete = () => {
+ notify({ text: i18n.t("Product removed") });
+ navigate(attributeListUrl());
+ };
+ const handleUpdate = () => notify({ text: i18n.t("Saved changes") });
+
+ return (
+ <AttributeDetailsQuery variables={{ id }}>
+ {({ data, loading }) => (
+ <>
+ <AttributePage
+ attribute={maybe(() => data.attribute)}
+ disabled={loading}
+ onBack={() => navigate(attributeListUrl())}
+ onDelete={() => openModal("remove")}
+ onSubmit={() => undefined}
+ onValueAdd={() => openModal("add-value")}
+ onValueDelete={() => openModal("remove-value")}
+ onValueUpdate={() => openModal("edit-value")}
+ saveButtonBarState={"default"}
+ values={maybe(() => data.attribute.values)}
+ />
+ </>
+ )}
+ </AttributeDetailsQuery>
+ );
+};
+AttributeDetails.displayName = "AttributeDetails";
+
+export default AttributeDetails;
diff --git a/saleor/static/dashboard-next/attributes/views/AttributeDetails/index.ts b/saleor/static/dashboard-next/attributes/views/AttributeDetails/index.ts
new file mode 100644
index 0000000000..f5f9c85b86
--- /dev/null
+++ b/saleor/static/dashboard-next/attributes/views/AttributeDetails/index.ts
@@ -0,0 +1,2 @@
+export * from "./AttributeDetails";
+export { default } from "./AttributeDetails";
diff --git a/saleor/static/dashboard-next/storybook/stories/attributes/AttributeDeleteDialog.tsx b/saleor/static/dashboard-next/storybook/stories/attributes/AttributeDeleteDialog.tsx
new file mode 100644
index 0000000000..dfb017543f
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/attributes/AttributeDeleteDialog.tsx
@@ -0,0 +1,15 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import AttributeDeleteDialog, {
+ AttributeDeleteDialogProps
+} from "../../../attributes/components/AttributeDeleteDialog";
+import Decorator from "../../Decorator";
+
+const props: AttributeDeleteDialogProps = {
+
+};
+
+storiesOf("Attributes / AttributeDeleteDialog", module)
+ .addDecorator(Decorator)
+ .add("default", () => <AttributeDeleteDialog {...props} />);