Skip to content

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

Add page list

dominik-zegleneff160cc25c0
diff --git a/saleor/static/dashboard-next/pages/components/PageList/PageList.tsx b/saleor/static/dashboard-next/pages/components/PageList/PageList.tsx
new file mode 100644
index 0000000000..6e274cf485
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/components/PageList/PageList.tsx
@@ -0,0 +1,116 @@
+import Card from "@material-ui/core/Card";
+import {
+ createStyles,
+ Theme,
+ withStyles,
+ WithStyles
+} from "@material-ui/core/styles";
+import Table from "@material-ui/core/Table";
+import TableBody from "@material-ui/core/TableBody";
+import TableCell from "@material-ui/core/TableCell";
+import TableFooter from "@material-ui/core/TableFooter";
+import TableHead from "@material-ui/core/TableHead";
+import TableRow from "@material-ui/core/TableRow";
+import * as React from "react";
+
+import Skeleton from "../../../components/Skeleton";
+import StatusLabel from "../../../components/StatusLabel";
+import TablePagination from "../../../components/TablePagination";
+import i18n from "../../../i18n";
+import { maybe, renderCollection } from "../../../misc";
+import { ListProps } from "../../../types";
+import { PageList_pages_edges_node } from "../../types/PageList";
+
+export interface PageListProps extends ListProps {
+ pages: PageList_pages_edges_node[];
+}
+
+const styles = createStyles({
+ link: {
+ cursor: "pointer"
+ }
+});
+const PageList = withStyles(styles, { name: "PageList" })(
+ ({
+ classes,
+ pages,
+ disabled,
+ onNextPage,
+ pageInfo,
+ onRowClick,
+ onPreviousPage
+ }: PageListProps & WithStyles<typeof styles>) => (
+ <Card>
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell padding="dense">
+ {i18n.t("Title", { context: "table header" })}
+ </TableCell>
+ <TableCell padding="dense">
+ {i18n.t("Slug", { context: "table header" })}
+ </TableCell>
+ <TableCell padding="dense">
+ {i18n.t("Visibility", { context: "table header" })}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableFooter>
+ <TableRow>
+ <TablePagination
+ colSpan={3}
+ hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
+ onNextPage={onNextPage}
+ hasPreviousPage={
+ pageInfo && !disabled ? pageInfo.hasPreviousPage : false
+ }
+ onPreviousPage={onPreviousPage}
+ />
+ </TableRow>
+ </TableFooter>
+ <TableBody>
+ {renderCollection(
+ pages,
+ page => (
+ <TableRow
+ hover={!!page}
+ className={!!page ? classes.link : undefined}
+ onClick={page ? onRowClick(page.id) : undefined}
+ key={page ? page.id : "skeleton"}
+ >
+ <TableCell>
+ {maybe<React.ReactNode>(() => page.title, <Skeleton />)}
+ </TableCell>
+ <TableCell>
+ {maybe<React.ReactNode>(() => page.slug, <Skeleton />)}
+ </TableCell>
+ <TableCell>
+ {maybe<React.ReactNode>(
+ () => (
+ <StatusLabel
+ label={
+ page.isVisible
+ ? i18n.t("Published")
+ : i18n.t("Not Published")
+ }
+ status={page.isVisible ? "success" : "error"}
+ />
+ ),
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={3}>{i18n.t("No pages found")}</TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+);
+PageList.displayName = "PageList";
+export default PageList;
diff --git a/saleor/static/dashboard-next/pages/components/PageList/index.ts b/saleor/static/dashboard-next/pages/components/PageList/index.ts
new file mode 100644
index 0000000000..0b888e9dbd
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/components/PageList/index.ts
@@ -0,0 +1,2 @@
+export { default } from './PageList';
+export * from './PageList';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/pages/components/PageListPage/PageListPage.tsx b/saleor/static/dashboard-next/pages/components/PageListPage/PageListPage.tsx
new file mode 100644
index 0000000000..89e8bdc449
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/components/PageListPage/PageListPage.tsx
@@ -0,0 +1,48 @@
+import Button from "@material-ui/core/Button";
+import AddIcon from "@material-ui/icons/Add";
+import * as React from "react";
+
+import Container from "../../../components/Container";
+import PageHeader from "../../../components/PageHeader";
+import i18n from "../../../i18n";
+import { PageListProps } from "../../../types";
+import { PageList_pages_edges_node } from "../../types/PageList";
+import PageList from "../PageList/PageList";
+
+export interface PageListPageProps extends PageListProps {
+ pages: PageList_pages_edges_node[];
+}
+
+const PageListPage: React.StatelessComponent<PageListPageProps> = ({
+ disabled,
+ onAdd,
+ onNextPage,
+ onPreviousPage,
+ onRowClick,
+ pageInfo,
+ pages
+}) => (
+ <Container width="md">
+ <PageHeader title={i18n.t("Pages")}>
+ <Button
+ disabled={disabled}
+ onClick={onAdd}
+ variant="contained"
+ color="secondary"
+ >
+ {i18n.t("Add page")}
+ <AddIcon />
+ </Button>
+ </PageHeader>
+ <PageList
+ disabled={disabled}
+ pages={pages}
+ onNextPage={onNextPage}
+ onPreviousPage={onPreviousPage}
+ onRowClick={onRowClick}
+ pageInfo={pageInfo}
+ />
+ </Container>
+);
+PageListPage.displayName = "PageListPage";
+export default PageListPage;
diff --git a/saleor/static/dashboard-next/pages/components/PageListPage/index.ts b/saleor/static/dashboard-next/pages/components/PageListPage/index.ts
new file mode 100644
index 0000000000..c5d5899744
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/components/PageListPage/index.ts
@@ -0,0 +1,2 @@
+export { default } from './PageListPage';
+export * from './PageListPage';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/pages/fixtures.ts b/saleor/static/dashboard-next/pages/fixtures.ts
new file mode 100644
index 0000000000..f40ea09d83
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/fixtures.ts
@@ -0,0 +1,32 @@
+import { PageList_pages_edges_node } from "./types/PageList";
+
+export const pageList: PageList_pages_edges_node[] = [
+ {
+ __typename: "Page",
+ id: "Jzx123sEt==",
+ isVisible: true,
+ slug: "about",
+ title: "About"
+ },
+ {
+ __typename: "Page",
+ id: "Jzx123sEx==",
+ isVisible: false,
+ slug: "about",
+ title: "About"
+ },
+ {
+ __typename: "Page",
+ id: "Jzx123sEu==",
+ isVisible: true,
+ slug: "about",
+ title: "About"
+ },
+ {
+ __typename: "Page",
+ id: "Jzx123sEm==",
+ isVisible: true,
+ slug: "about",
+ title: "About"
+ }
+];
diff --git a/saleor/static/dashboard-next/pages/queries.ts b/saleor/static/dashboard-next/pages/queries.ts
new file mode 100644
index 0000000000..1233f48e01
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/queries.ts
@@ -0,0 +1,33 @@
+import gql from "graphql-tag";
+
+import { TypedQuery } from "../queries";
+import { PageList, PageListVariables } from "./types/PageList";
+
+export const pageFragment = gql`
+ fragment PageFragment on Page {
+ id
+ title
+ slug
+ isVisible
+ }
+`;
+
+const pageList = gql`
+ ${pageFragment}
+ query PageList($first: Int, $after: String, $last: Int, $before: String) {
+ pages(before: $before, after: $after, first: $first, last: $last) {
+ edges {
+ node {
+ ...PageFragment
+ }
+ }
+ pageInfo {
+ hasPreviousPage
+ hasNextPage
+ startCursor
+ endCursor
+ }
+ }
+ }
+`;
+export const TypedPageList = TypedQuery<PageList, PageListVariables>(pageList);
diff --git a/saleor/static/dashboard-next/pages/types/PageFragment.ts b/saleor/static/dashboard-next/pages/types/PageFragment.ts
new file mode 100644
index 0000000000..7bf3bee226
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/types/PageFragment.ts
@@ -0,0 +1,14 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL fragment: PageFragment
+// ====================================================
+
+export interface PageFragment {
+ __typename: "Page";
+ id: string;
+ title: string;
+ slug: string;
+ isVisible: boolean;
+}
diff --git a/saleor/static/dashboard-next/pages/types/PageList.ts b/saleor/static/dashboard-next/pages/types/PageList.ts
new file mode 100644
index 0000000000..c594a22750
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/types/PageList.ts
@@ -0,0 +1,44 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL query operation: PageList
+// ====================================================
+
+export interface PageList_pages_edges_node {
+ __typename: "Page";
+ id: string;
+ title: string;
+ slug: string;
+ isVisible: boolean;
+}
+
+export interface PageList_pages_edges {
+ __typename: "PageCountableEdge";
+ node: PageList_pages_edges_node;
+}
+
+export interface PageList_pages_pageInfo {
+ __typename: "PageInfo";
+ hasPreviousPage: boolean;
+ hasNextPage: boolean;
+ startCursor: string | null;
+ endCursor: string | null;
+}
+
+export interface PageList_pages {
+ __typename: "PageCountableConnection";
+ edges: PageList_pages_edges[];
+ pageInfo: PageList_pages_pageInfo;
+}
+
+export interface PageList {
+ pages: PageList_pages | null;
+}
+
+export interface PageListVariables {
+ first?: number | null;
+ after?: string | null;
+ last?: number | null;
+ before?: string | null;
+}
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index cf0ff3f2e7..bfac4846b1 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -69,6 +69,9 @@ function loadStories() {
require("./stories/staff/StaffListPage");
require("./stories/staff/StaffDetailsPage");
+ // Pages
+ require("./stories/pages/PageListPage")
+
// Products
require("./stories/products/ProductCreatePage");
require("./stories/products/ProductImagePage");
diff --git a/saleor/static/dashboard-next/storybook/stories/pages/PageListPage.tsx b/saleor/static/dashboard-next/storybook/stories/pages/PageListPage.tsx
new file mode 100644
index 0000000000..814240f2c5
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/pages/PageListPage.tsx
@@ -0,0 +1,22 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import { pageListProps } from "../../../fixtures";
+import PageListPage, {
+ PageListPageProps
+} from "../../../pages/components/PageListPage";
+import { pageList } from "../../../pages/fixtures";
+import Decorator from "../../Decorator";
+
+const props: PageListPageProps = {
+ ...pageListProps.default,
+ pages: pageList
+};
+
+storiesOf("Views / Pages / Page list", module)
+ .addDecorator(Decorator)
+ .add("default", () => <PageListPage {...props} />)
+ .add("loading", () => (
+ <PageListPage {...props} disabled={true} pages={undefined} />
+ ))
+ .add("no data", () => <PageListPage {...props} pages={[]} />);