Skip to content

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

Fix page views

dominik-zeglen3c091e3969b3
diff --git a/package.json b/package.json
index 2cab410263..3258c69aa9 100644
--- a/package.json
+++ b/package.json
@@ -83,6 +83,7 @@
"react-sortable-hoc": "^0.6.8",
"react-svg": "^2.2.11",
"select2": "^4.0.5",
+ "slugify": "^1.3.4",
"sortablejs": "^1.5.0-rc1",
"string-similarity": "^1.2.0",
"svg-injector-2": "^2.0.35",
diff --git a/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx b/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx
index 757d60ec75..db7acbe142 100644
--- a/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx
+++ b/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx
@@ -1,4 +1,4 @@
-import { RawDraftContentState } from "draft-js";
+import { ContentState, convertToRaw, RawDraftContentState } from "draft-js";
import * as React from "react";
import AppHeader from "../../../components/AppHeader";
@@ -49,7 +49,10 @@ const PageDetailsPage: React.StatelessComponent<PageDetailsPageProps> = ({
}) => {
const initialForm: FormData = {
availableOn: maybe(() => page.availableOn, ""),
- content: maybe(() => JSON.parse(page.contentJson)),
+ content: maybe(
+ () => JSON.parse(page.contentJson),
+ convertToRaw(ContentState.createFromText(""))
+ ),
isVisible: maybe(() => page.isVisible, false),
seoDescription: maybe(() => page.seoDescription, ""),
seoTitle: maybe(() => page.seoTitle, ""),
@@ -112,7 +115,7 @@ const PageDetailsPage: React.StatelessComponent<PageDetailsPageProps> = ({
disabled={disabled || !hasChanged}
state={saveButtonBarState}
onCancel={onBack}
- onDelete={onRemove}
+ onDelete={page === null ? undefined : onRemove}
onSave={submit}
/>
</Container>
diff --git a/saleor/static/dashboard-next/pages/components/PageSlug/PageSlug.tsx b/saleor/static/dashboard-next/pages/components/PageSlug/PageSlug.tsx
index f8013d58a8..42bbef7e4e 100644
--- a/saleor/static/dashboard-next/pages/components/PageSlug/PageSlug.tsx
+++ b/saleor/static/dashboard-next/pages/components/PageSlug/PageSlug.tsx
@@ -2,6 +2,7 @@ import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import TextField from "@material-ui/core/TextField";
import * as React from "react";
+import slugify from "slugify";
import CardTitle from "../../../components/CardTitle";
import i18n from "../../../i18n";
@@ -32,7 +33,7 @@ const PageSlug: React.StatelessComponent<PageSlugProps> = ({
errors.slug ||
i18n.t("If empty, URL will be autogenerated from Page Name")
}
- placeholder={data.title.toLowerCase()}
+ placeholder={slugify(data.title)}
value={data.slug}
onChange={onChange}
fullWidth
diff --git a/saleor/static/dashboard-next/pages/views/PageCreate.tsx b/saleor/static/dashboard-next/pages/views/PageCreate.tsx
index c71c7653c0..282ed52ffb 100644
--- a/saleor/static/dashboard-next/pages/views/PageCreate.tsx
+++ b/saleor/static/dashboard-next/pages/views/PageCreate.tsx
@@ -68,7 +68,7 @@ export const PageCreate: React.StatelessComponent<PageCreateProps> = () => (
description: formData.seoDescription,
title: formData.seoTitle
},
- slug: formData.slug,
+ slug: formData.slug === "" ? null : formData.slug,
title: formData.title
}
}
diff --git a/saleor/static/dashboard-next/pages/views/PageDetails.tsx b/saleor/static/dashboard-next/pages/views/PageDetails.tsx
index b50f2e91ce..455addd5e1 100644
--- a/saleor/static/dashboard-next/pages/views/PageDetails.tsx
+++ b/saleor/static/dashboard-next/pages/views/PageDetails.tsx
@@ -8,7 +8,7 @@ import Navigator from "../../components/Navigator";
import i18n from "../../i18n";
import { getMutationState, maybe } from "../../misc";
import { PageInput } from "../../types/globalTypes";
-import PageDetailsPage,{FormData} from "../components/PageDetailsPage";
+import PageDetailsPage, { FormData } from "../components/PageDetailsPage";
import { TypedPageRemove, TypedPageUpdate } from "../mutations";
import { TypedPageDetailsQuery } from "../queries";
import { PageRemove } from "../types/PageRemove";
@@ -19,13 +19,10 @@ export interface PageDetailsProps {
}
const createPageInput = (data: FormData): PageInput => ({
- contentJson: JSON.stringify(
- data.content
- ),
+ contentJson: JSON.stringify(data.content),
isPublished: data.isVisible
? true
- : data.availableOn === "" ||
- data.availableOn === null
+ : data.availableOn === "" || data.availableOn === null
? false
: true,
publicationDate: data.isVisible
@@ -37,9 +34,9 @@ const createPageInput = (data: FormData): PageInput => ({
description: data.seoDescription,
title: data.seoTitle
},
- slug: data.slug,
+ slug: data.slug === "" ? null : data.slug,
title: data.title
-})
+});
export const PageDetails: React.StatelessComponent<PageDetailsProps> = ({
id
diff --git a/saleor/static/dashboard-next/theme.ts b/saleor/static/dashboard-next/theme.ts
index e0ce68c0c4..e41b0a99b3 100644
--- a/saleor/static/dashboard-next/theme.ts
+++ b/saleor/static/dashboard-next/theme.ts
@@ -41,6 +41,9 @@ export default createMuiTheme({
input: {
"&:-webkit-autofill": {
boxShadow: "inset 0 0 0px 9999px #EFF8F2"
+ },
+ "&::placeholder": {
+ opacity: "initial !important" as "initial"
}
},
root: {