Skip to content

Commit

Permalink
Merge branch 'development' of github.com:Webiny/webiny-js into develo…
Browse files Browse the repository at this point in the history
…pment
  • Loading branch information
Pavel910 committed Feb 14, 2019
2 parents 56d9f57 + 2f6dbae commit da31c55
Show file tree
Hide file tree
Showing 53 changed files with 605 additions and 382 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,5 @@ export default {
errorPolicy: "all"
}
}
}),
components: {
Image: {
presets: {
avatar: { width: 128 }
},
plugin: "image-component"
},
withFileUpload: {
plugin: ["with-file-upload", { uri: "/files" }]
}
}
})
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,5 @@ export default {
addTypename: true,
dataIdFromObject: obj => obj.id || null
})
}),
components: {
Image: {
presets: {
avatar: { width: 128 }
},
plugin: "image-component"
},
withFileUpload: {
plugin: ["with-file-upload", { uri: "/files" }]
}
}
})
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { withSnackbar } from "webiny-admin/components";
import { RadioGroup, Radio } from "webiny-ui/Radio";
import graphql from "./graphql";
import showCookiePolicy from "./../../utils/showCookiePolicy";
import { CircularProgress } from "webiny-ui/Progress";

import {
SimpleForm,
Expand All @@ -29,9 +30,9 @@ const positionOptions = [
const CookiePolicySettings = ({ showSnackbar }) => {
return (
<Query query={graphql.query}>
{({ data }) => (
{({ data, loading: queryInProgress }) => (
<Mutation mutation={graphql.mutation}>
{update => (
{(update, { loading: mutationInProgress }) => (
<Form
data={data.settings}
onSubmit={async data => {
Expand All @@ -45,6 +46,9 @@ const CookiePolicySettings = ({ showSnackbar }) => {
>
{({ Bind, form, data }) => (
<SimpleForm>
{(queryInProgress || mutationInProgress) && (
<CircularProgress />
)}
<SimpleFormHeader title="Cookie Policy Settings">
<Bind
name={"cookiePolicy.enabled"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Query, Mutation } from "react-apollo";
import { withSnackbar } from "webiny-admin/components";
import { Input } from "webiny-ui/Input";
import graphql from "./graphql";
import { CircularProgress } from "webiny-ui/Progress";

import {
SimpleForm,
Expand All @@ -19,9 +20,9 @@ import {
const GoogleTagManagerSettings = ({ showSnackbar }) => {
return (
<Query query={graphql.query}>
{({ data }) => (
{({ data, loading: queryInProgress }) => (
<Mutation mutation={graphql.mutation}>
{update => (
{(update, { loading: mutationInProgress }) => (
<Form
data={data.settings}
onSubmit={async data => {
Expand All @@ -35,6 +36,9 @@ const GoogleTagManagerSettings = ({ showSnackbar }) => {
>
{({ Bind, form, data }) => (
<SimpleForm>
{(queryInProgress || mutationInProgress) && (
<CircularProgress />
)}
<SimpleFormHeader title="Google Tag Manager Settings">
<Bind
name={"googleTagManager.enabled"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ButtonPrimary } from "webiny-ui/Button";
import { Query, Mutation } from "react-apollo";
import { withSnackbar } from "webiny-admin/components";
import graphql from "./graphql";
import { CircularProgress } from "webiny-ui/Progress";

import {
SimpleForm,
Expand All @@ -19,9 +20,9 @@ import {
const MailchimpSettings = ({ showSnackbar }) => {
return (
<Query query={graphql.query}>
{({ data }) => (
{({ data, loading: queryInProgress }) => (
<Mutation mutation={graphql.mutation}>
{update => (
{(update, { loading: mutationInProgress }) => (
<Form
data={data.settings}
onSubmit={async data => {
Expand All @@ -35,6 +36,9 @@ const MailchimpSettings = ({ showSnackbar }) => {
>
{({ Bind, form, data }) => (
<SimpleForm>
{(queryInProgress || mutationInProgress) && (
<CircularProgress />
)}
<SimpleFormHeader title="Mailchimp Settings">
<Bind
name={"mailchimp.enabled"}
Expand Down
45 changes: 28 additions & 17 deletions packages/webiny-admin/src/components/withCrud.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type WithCrudListProps = WithCrudBaseProps & {

export type WithCrudFormProps = WithCrudBaseProps & {
invalidFields: Object,
loading: boolean,
onSubmit: (data: Object) => void,
data: Object,
error: Object | null
Expand Down Expand Up @@ -70,19 +71,22 @@ const withSaveHandler = ({ create, update, response, variables, snackbar }): Fun
return compose(
setDisplayName("saveHandler"),
withState("invalidFields", "setInvalidFields", {}),
withState("mutationInProgress", "setMutationInProgress", false),
graphql(create, { name: "createRecord" }),
graphql(update, { name: "updateRecord" }),
withHandlers({
saveRecord: ({
createRecord,
updateRecord,
setMutationInProgress,
setInvalidFields,
showSnackbar,
showDialog,
router,
dataList,
id
}: Object) => {
setMutationInProgress(true);
return async (formData: Object) => {
// Reset errors
setInvalidFields(null);
Expand All @@ -91,24 +95,29 @@ const withSaveHandler = ({ create, update, response, variables, snackbar }): Fun
const operation = id
? updateRecord({ variables: { id, ...gqlVariables } })
: createRecord({ variables: gqlVariables });
return operation.then(res => {
const { data, error } = response(res.data);
if (error) {
if (error.code === "INVALID_ATTRIBUTES") {
showSnackbar("Some of your form input is incorrect!");
setInvalidFields(error.data.invalidAttributes);
return;
} else {
showDialog(error.message, {
title: "Something unexpected happened"
});
return;
return operation
.then(res => {
const { data, error } = response(res.data);
if (error) {
if (error.code === "INVALID_ATTRIBUTES") {
showSnackbar("Some of your form input is incorrect!");
setInvalidFields(error.data.invalidAttributes);
return;
} else {
showDialog(error.message, {
title: "Something unexpected happened"
});
return;
}
}
}
showSnackbar(snackbar(data));
router.goToRoute({ params: { id: data.id }, merge: true });
!id && dataList.refresh();
});
showSnackbar(snackbar(data));
router.goToRoute({ params: { id: data.id }, merge: true });
!id && dataList.refresh();
})
.then(res => {
setMutationInProgress(false);
return res;
});
};
}
})
Expand Down Expand Up @@ -163,6 +172,7 @@ export const withCrud = ({ list, form }: Object): Function => {
dataList,
saveRecord,
formData,
mutationInProgress,
invalidFields,
showSnackbar,
showDialog,
Expand All @@ -184,6 +194,7 @@ export const withCrud = ({ list, form }: Object): Function => {
...formData,
invalidFields,
onSubmit: saveRecord,
loading: formData && formData.loading || mutationInProgress,
router,
showSnackbar,
showDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const process = ({ data, form }: Object) => {
const getFormData = ({ data, form }: Object) => {
const formData = process({ data, form });
return {
loading: get(data, "loading") || false,
data: get(formData, "data") || {},
error: get(formData, "error") || null
};
Expand Down
5 changes: 3 additions & 2 deletions packages/webiny-api-cms/src/entities/CmsSettings.entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { settingsFactory } from "webiny-api/entities";
import { Model } from "webiny-model";
import FileModel from "./File.model";

class SocialMedia extends Model {
class SocialMediaModel extends Model {
constructor() {
super();
this.attr("facebook").char();
this.attr("twitter").char();
this.attr("instagram").char();
this.attr("image").model(FileModel);
}
}

Expand All @@ -31,7 +32,7 @@ const cmsSettingsModelFactory = () => {
this.attr("domain").char();
this.attr("favicon").model(FileModel);
this.attr("logo").model(FileModel);
this.attr("social").model(SocialMedia);
this.attr("social").model(SocialMediaModel);
}
};
};
Expand Down
4 changes: 2 additions & 2 deletions packages/webiny-api-cms/src/install/plugins/importData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import setupEntities from "./setupEntities";
import createDefaultPages from "./importData/createDefaultPages";
import createDefaultBlocks from "./importData/createDefaultBlocks";
import * as data from "./data";

import {get} from "lodash";
export default async (context: Object) => {
setupEntities(context);
const { Category, Menu, CmsSettings } = context.cms.entities;
Expand Down Expand Up @@ -65,7 +65,7 @@ export default async (context: Object) => {
// Settings init.
const cmsSettings = new CmsSettings();
await createDefaultPages(context, { categories, cmsSettings });
cmsSettings.data.domain = "http://localhost:3002";
cmsSettings.data.domain = get(context, "cms.siteUrl");

await cmsSettings.save();
};
2 changes: 2 additions & 0 deletions packages/webiny-api-cms/src/plugins/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default [
facebook: String
twitter: String
instagram: String
image: File
}
type CmsSettings {
Expand Down Expand Up @@ -38,6 +39,7 @@ export default [
facebook: String
twitter: String
instagram: String
image: FileInput
}
input CmsDefaultPageInput {
Expand Down
24 changes: 22 additions & 2 deletions packages/webiny-app-cms/src/admin/plugins/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from "react";
import AdminLayout from "webiny-admin/components/Layouts/AdminLayout";
import Categories from "webiny-app-cms/admin/views/Categories/Categories";
// import Menus from "webiny-app-cms/admin/views/Menus/Menus";
import Menus from "webiny-app-cms/admin/views/Menus/Menus";
import Pages from "webiny-app-cms/admin/views/Pages/Pages";
import Editor from "webiny-app-cms/admin/views/Pages/Editor";
import { SecureRoute } from "webiny-app-security/components";
Expand All @@ -29,7 +29,27 @@ export default [
}
}
},

{
name: "route-cms-menus",
type: "route",
route: {
name: "Cms.Menus",
path: "/cms/menus",
exact: true,
render() {
return (
<SecureRoute roles={["cms-menus"]}>
<Helmet>
<title>CMS - Menus</title>
</Helmet>
<AdminLayout>
<Menus />
</AdminLayout>
</SecureRoute>
);
}
}
},
{
name: "route-cms-pages",
type: "route",
Expand Down
Loading

0 comments on commit da31c55

Please sign in to comment.