Skip to content

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

Add basic view

dominik-zeglenb2e53af7c61e
diff --git a/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/MenuDetailsPage.tsx b/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/MenuDetailsPage.tsx
index 6eeb81002d..c4146348b8 100644
--- a/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/MenuDetailsPage.tsx
+++ b/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/MenuDetailsPage.tsx
@@ -71,7 +71,10 @@ const MenuDetailsPage: React.StatelessComponent<MenuDetailsPageProps> = ({
/>
<CardSpacer />
<MenuItems
- items={computeTree(maybe(() => menu.items), treePermutations)}
+ items={computeTree(
+ maybe(() => menu.items, []),
+ treePermutations
+ )}
onChange={permutation =>
!!permutation
? setTreePermutations([...treePermutations, permutation])
diff --git a/saleor/static/dashboard-next/navigation/components/MenuItems/MenuItems.tsx b/saleor/static/dashboard-next/navigation/components/MenuItems/MenuItems.tsx
index bfc14ac289..8b83a20c42 100644
--- a/saleor/static/dashboard-next/navigation/components/MenuItems/MenuItems.tsx
+++ b/saleor/static/dashboard-next/navigation/components/MenuItems/MenuItems.tsx
@@ -7,10 +7,12 @@ import {
WithStyles
} from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
+import classNames from "classnames";
import * as React from "react";
import SortableTree, { NodeRendererProps } from "react-sortable-tree";
import CardTitle from "../../../components/CardTitle";
+import useTheme from "../../../hooks/useTheme";
import i18n from "../../../i18n";
import Draggable from "../../../icons/Draggable";
import { MenuDetails_menu_items } from "../../types/MenuDetails";
@@ -32,6 +34,9 @@ export interface MenuItemsProps {
const styles = (theme: Theme) =>
createStyles({
+ darkRoot: {
+ background: `${theme.palette.grey[800]} !important`
+ },
dragIcon: {
cursor: "grab"
},
@@ -54,73 +59,82 @@ const styles = (theme: Theme) =>
height: NODE_HEIGHT,
justifyContent: "flex-start",
paddingLeft: theme.spacing.unit * 3,
- transition: theme.transitions.duration.standard + "ms"
+ transition: `margin ${theme.transitions.duration.standard}ms`
}
});
-const Node: React.FC<NodeRendererProps & WithStyles<typeof styles>> = ({
- classes,
- node,
- path,
- connectDragPreview,
- connectDragSource
-}) => {
- return (
- <>
- {connectDragPreview(
- <div>
- <Paper
- className={classes.row}
- elevation={0}
- style={{
- marginLeft: NODE_MARGIN * (path.length - 1)
- }}
- >
- {connectDragSource(
- <div>
- <Draggable className={classes.dragIcon} />
- </div>
- )}
- <Typography className={classes.nodeTitle}>{node.title}</Typography>
- </Paper>
- </div>
- )}
- </>
- );
-};
+class Node extends React.Component<NodeRendererProps> {
+ render() {
+ return <NodeComponent {...this.props} />;
+ }
+}
+
+const NodeComponent = withStyles(styles, {
+ name: "NodeComponent"
+})(
+ ({
+ classes,
+ node,
+ path,
+ connectDragPreview,
+ connectDragSource
+ }: NodeRendererProps & WithStyles<typeof styles>) =>
+ connectDragPreview(
+ <div>
+ <Paper
+ className={classes.row}
+ elevation={0}
+ style={{
+ marginLeft: NODE_MARGIN * (path.length - 1)
+ }}
+ >
+ {connectDragSource(
+ <div>
+ <Draggable className={classes.dragIcon} />
+ </div>
+ )}
+ <Typography className={classes.nodeTitle}>{node.title}</Typography>
+ </Paper>
+ </div>
+ )
+);
const MenuItems = withStyles(styles, { name: "MenuItems" })(
({
classes,
items,
onChange
- }: MenuItemsProps & WithStyles<typeof styles>) => (
- <Card>
- <CardTitle title={i18n.t("Menu Items")} />
- <div style={{ height: getNodeQuantity(items) * NODE_HEIGHT }}>
- <SortableTree
- className={classes.root}
- generateNodeProps={({ path }) => ({
- className: classes.row,
- style: {
- marginLeft: NODE_MARGIN * (path.length - 1)
+ }: MenuItemsProps & WithStyles<typeof styles>) => {
+ const { isDark } = useTheme();
+
+ return (
+ <Card>
+ <CardTitle title={i18n.t("Menu Items")} />
+ <div style={{ height: getNodeQuantity(items) * NODE_HEIGHT }}>
+ <SortableTree
+ className={classNames(classes.root, {
+ [classes.darkRoot]: isDark
+ })}
+ generateNodeProps={({ path }) => ({
+ className: classes.row,
+ style: {
+ marginLeft: NODE_MARGIN * (path.length - 1)
+ }
+ })}
+ isVirtualized={false}
+ rowHeight={NODE_HEIGHT}
+ treeData={items.map(getNodeData)}
+ theme={{
+ nodeContentRenderer: Node
+ }}
+ onChange={newTree =>
+ onChange(getDiff(items.map(getNodeData), newTree as TreeNode[]))
}
- })}
- isVirtualized={false}
- rowHeight={NODE_HEIGHT}
- treeData={items.map(getNodeData)}
- theme={{
- nodeContentRenderer: (props => (
- <Node {...props} classes={classes} />
- )) as any
- }}
- onChange={newTree =>
- onChange(getDiff(items.map(getNodeData), newTree as TreeNode[]))
- }
- />
- </div>
- </Card>
- )
+ />
+ </div>
+ </Card>
+ );
+ }
);
MenuItems.displayName = "MenuItems";
export default MenuItems;
diff --git a/saleor/static/dashboard-next/navigation/index.tsx b/saleor/static/dashboard-next/navigation/index.tsx
index 8f67d22873..46ea8411cb 100644
--- a/saleor/static/dashboard-next/navigation/index.tsx
+++ b/saleor/static/dashboard-next/navigation/index.tsx
@@ -2,7 +2,8 @@ import { parse as parseQs } from "qs";
import * as React from "react";
import { Route, RouteComponentProps, Switch } from "react-router-dom";
-import { menuListPath } from "./urls";
+import { menuListPath, menuPath } from "./urls";
+import MenuDetailsComponent from "./views/MenuDetails";
import MenuListComponent from "./views/MenuList";
const MenuList: React.FC<RouteComponentProps<{}>> = ({ location }) => {
@@ -10,9 +11,23 @@ const MenuList: React.FC<RouteComponentProps<{}>> = ({ location }) => {
return <MenuListComponent params={qs} />;
};
+const MenuDetails: React.FC<RouteComponentProps<{ id: string }>> = ({
+ location,
+ match
+}) => {
+ const qs = parseQs(location.search.substr(1));
+ return (
+ <MenuDetailsComponent
+ id={decodeURIComponent(match.params.id)}
+ params={qs}
+ />
+ );
+};
+
const NavigationRouter: React.FC = () => (
<Switch>
<Route exact component={MenuList} path={menuListPath} />
+ <Route component={MenuDetails} path={menuPath(":id")} />
</Switch>
);
diff --git a/saleor/static/dashboard-next/navigation/views/MenuDetails.tsx b/saleor/static/dashboard-next/navigation/views/MenuDetails.tsx
new file mode 100644
index 0000000000..a2726d9958
--- /dev/null
+++ b/saleor/static/dashboard-next/navigation/views/MenuDetails.tsx
@@ -0,0 +1,50 @@
+import * as React from "react";
+
+import useNavigator from "../../hooks/useNavigator";
+import useNotifier from "../../hooks/useNotifier";
+import { maybe } from "../../misc";
+import MenuDetailsPage from "../components/MenuDetailsPage";
+import { MenuDetailsQuery } from "../queries";
+import { menuListUrl, menuUrl, MenuUrlQueryParams } from "../urls";
+
+interface MenuDetailsProps {
+ id: string;
+ params: MenuUrlQueryParams;
+}
+
+const MenuDetails: React.FC<MenuDetailsProps> = ({ id, params }) => {
+ const navigate = useNavigator();
+ const notify = useNotifier();
+
+ const closeModal = () =>
+ navigate(
+ menuUrl(id, {
+ ...params,
+ action: undefined,
+ id: undefined
+ }),
+ true
+ );
+
+ return (
+ <MenuDetailsQuery variables={{ id }}>
+ {({ data, loading }) => {
+ return (
+ <>
+ <MenuDetailsPage
+ disabled={loading}
+ menu={maybe(() => data.menu)}
+ onBack={() => navigate(menuListUrl())}
+ onDelete={() => undefined}
+ onSubmit={() => undefined}
+ saveButtonState="default"
+ />
+ </>
+ );
+ }}
+ </MenuDetailsQuery>
+ );
+};
+MenuDetails.displayName = "MenuDetails";
+
+export default MenuDetails;