Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add content model group selector #1591

Merged
merged 2 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from "react";
import { Grid, Cell } from "@webiny/ui/Grid";
import { Input } from "@webiny/ui/Input";
import { validation } from "@webiny/validation";
import { BindComponent } from "@webiny/form";
import GroupSelect from "./GroupSelect";

const GeneralSettings = ({ Bind }) => {
interface GeneralSettingsProps {
Bind: BindComponent;
}

const GeneralSettings = ({ Bind }: GeneralSettingsProps) => {
return (
<React.Fragment>
<Grid>
Expand All @@ -21,6 +28,11 @@ const GeneralSettings = ({ Bind }) => {
<Input rows={5} label={"Content model description"} />
</Bind>
</Cell>
<Cell span={12}>
<Bind name={"group"} validators={validation.create("required")}>
<GroupSelect />
</Bind>
</Cell>
</Grid>
</React.Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { useMemo } from "react";
import { Select } from "@webiny/ui/Select";
import { FormComponentProps } from "@webiny/ui/types";
import { LIST_MENU_CONTENT_GROUPS_MODELS } from "~/admin/viewsGraphql";
import { useQuery } from "~/admin/hooks";

export default function GroupSelect({ value, ...props }: FormComponentProps) {
const { data, loading } = useQuery(LIST_MENU_CONTENT_GROUPS_MODELS);

const groups = loading && !data ? [] : data.listContentModelGroups.data;
const options = useMemo(() => {
return groups.map(item => ({ value: item.id, label: item.name }));
}, [groups]);

const selectValue = typeof value === "string" ? value : value.id;

return (
<Select
{...props}
value={loading ? "" : selectValue}
label={"Content model group"}
options={options}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const FIELDS_FIELDS = `

export const MODEL_FIELDS = `
name
group {
id
name
}
description
modelId
savedOn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from "react";
import shortid from "shortid";
import ApolloClient from "apollo-client";
import { get, cloneDeep, pick } from "lodash";
import { plugins } from "@webiny/plugins";
import { GET_CONTENT_MODEL, UPDATE_CONTENT_MODEL } from "./graphql";
import { getFieldPosition, moveField, moveRow, deleteField } from "./functions";
import { plugins } from "@webiny/plugins";

import {
CmsEditorFieldsLayout,
Expand All @@ -13,11 +14,11 @@ import {
CmsEditorFieldTypePlugin,
CmsEditorContentModel
} from "~/types";
import ApolloClient from "apollo-client";
import { LIST_MENU_CONTENT_GROUPS_MODELS } from "~/admin/viewsGraphql";

type PickedCmsEditorContentModel = Pick<
CmsEditorContentModel,
"layout" | "fields" | "name" | "settings" | "description" | "titleFieldId"
"layout" | "fields" | "name" | "settings" | "description" | "titleFieldId" | "group"
>;
/**
* cleanup is required because backend always expects string value in predefined values entries
Expand Down Expand Up @@ -121,6 +122,7 @@ export default ContentModelEditorContext => {
},
saveContentModel: async (data = state.data) => {
const modelData: PickedCmsEditorContentModel = pick(data, [
"group",
"layout",
"fields",
"name",
Expand All @@ -133,7 +135,8 @@ export default ContentModelEditorContext => {
variables: {
modelId: data.modelId,
data: cleanupModelData(modelData)
}
},
refetchQueries: [{ query: LIST_MENU_CONTENT_GROUPS_MODELS }]
});

setPristine(true);
Expand Down