2017-01-25 13:58:02 +09:00
|
|
|
|
|
|
|
export function getCategories (apolloClient) {
|
|
|
|
|
|
|
|
// get the current data of the store
|
|
|
|
const apolloData = apolloClient.store.getState().apollo.data;
|
|
|
|
|
|
|
|
// filter these data based on their typename: we are interested in the categories data
|
|
|
|
const categories = _.filter(apolloData, (object, key) => {
|
|
|
|
return object.__typename === 'Category'
|
|
|
|
});
|
|
|
|
|
|
|
|
// give the form component (here: checkboxgroup) exploitable data
|
|
|
|
const categoriesOptions = categories.map(function (category) {
|
|
|
|
return {
|
|
|
|
value: category._id,
|
|
|
|
label: category.name,
|
|
|
|
// slug: category.slug, // note: it may be used to look up from prefilled props
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return categoriesOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-23 15:11:56 +09:00
|
|
|
// category schema
|
2016-11-22 18:14:51 -05:00
|
|
|
const schema = {
|
2016-11-08 15:16:58 +09:00
|
|
|
_id: {
|
|
|
|
type: String,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-08 15:16:58 +09:00
|
|
|
optional: true,
|
|
|
|
publish: true
|
|
|
|
},
|
2016-06-23 15:11:56 +09:00
|
|
|
name: {
|
|
|
|
type: String,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
|
|
|
insertableBy: ['members'],
|
|
|
|
editableBy: ['members'],
|
2016-06-23 15:11:56 +09:00
|
|
|
publish: true
|
|
|
|
},
|
|
|
|
description: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
|
|
|
insertableBy: ['members'],
|
|
|
|
editableBy: ['members'],
|
2016-06-23 15:11:56 +09:00
|
|
|
publish: true,
|
2016-10-05 08:43:13 +02:00
|
|
|
form: {
|
2016-06-23 15:11:56 +09:00
|
|
|
rows: 3
|
|
|
|
}
|
|
|
|
},
|
|
|
|
order: {
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
|
|
|
insertableBy: ['members'],
|
|
|
|
editableBy: ['members'],
|
2016-06-23 15:11:56 +09:00
|
|
|
publish: true
|
|
|
|
},
|
|
|
|
slug: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
|
|
|
insertableBy: ['members'],
|
|
|
|
editableBy: ['members'],
|
2016-11-15 15:59:34 +09:00
|
|
|
publish: true,
|
2016-06-23 15:11:56 +09:00
|
|
|
},
|
|
|
|
image: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
|
|
|
insertableBy: ['members'],
|
|
|
|
editableBy: ['members'],
|
2016-06-23 15:11:56 +09:00
|
|
|
publish: true
|
|
|
|
},
|
2017-01-25 13:58:02 +09:00
|
|
|
parentId: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
control: "select",
|
|
|
|
viewableBy: ['guests'],
|
|
|
|
insertableBy: ['members'],
|
|
|
|
editableBy: ['members'],
|
|
|
|
publish: true,
|
|
|
|
resolveAs: 'parent: Category',
|
|
|
|
form: {
|
|
|
|
options: formProps => getCategories(formProps.client)
|
|
|
|
}
|
|
|
|
}
|
2016-11-22 18:14:51 -05:00
|
|
|
};
|
2016-06-23 15:11:56 +09:00
|
|
|
|
2016-12-08 23:48:16 +01:00
|
|
|
export default schema;
|