import React from 'react';
import EditorComponent from '@prisma-cms/front-editor/lib/components/App/components/';
import { Button } from 'material-ui';
import { ObjectContext } from '@prisma-cms/front-editor/lib/components/App/components/public/Connectors/Connector/ListView';
import { EditableObjectContext } from '@prisma-cms/front-editor/lib/components/App/context';
export class SetServiceCategory extends EditorComponent {
static Name = 'SetServiceCategory';
renderPanelView() {
const {
classes,
} = this.getEditorContext();
return super.renderPanelView(
<div
className={classes.panelButton}
>
SetServiceCategory
</div>
);
}
canBeChild(child) {
return false;
}
renderChildren() {
return <ObjectContext.Consumer>
{context => {
const {
object,
...otherContext
} = context;
if (!object) {
return null;
}
let output = null;
const {
id: objectId,
name,
} = object;
if (!objectId) {
return null;
}
output = <EditableObjectContext.Consumer>
{editableObjectContext => {
const {
updateObject,
getEditor,
inEditMode,
canEdit,
getObjectWithMutations,
} = editableObjectContext;
const object = getObjectWithMutations();
if (!object) {
return null;
}
const {
Category,
} = object;
const categoryId = Category ? (Category.id || (Category.connect && Category.connect.id)) : null;
return getEditor({
Editor: (props) => {
return <Button
size="small"
variant={categoryId && categoryId === objectId ? "raised" : undefined}
onClick={event => {
updateObject({
Category: {
connect: {
id: objectId,
},
},
});
}}
>
{name}
</Button>
},
});
}}
</EditableObjectContext.Consumer>
return output;
}}
</ObjectContext.Consumer>;
}
}
export default SetServiceCategory;