-
Notifications
You must be signed in to change notification settings - Fork 13
Adding a New Item type to Shape
Shape uses single-table inheritance for its Item
class, allowing broad extension to many kinds of items such as ::TextItem
, ::ImageItem
, and so on. To make a new kind of Item
in Shape, you'll need to create a model in the models/item/
directory, like:
class Item
class YourItem < Item
end
end
Collection
s and Item
s are both created using thin *Creator
components in the blankContentTool
directory which are selected by a switch
statement in GridCardBlank.js
. These creators use GridCardBlank.createCard
to make an API call to the CollectionCardController
.
Items in Shape are generally created through CollectionCardController
because CollectionCard
s accept nested attributes for their associated Item
. In order to take advantage of this, however, you'll need to add your new type of Item
to:
- create a
serializable_your_item.rb
in/serializers
and define anyattributes
you'll want to send via JSON - add the serializer you created to
BaseController#jsonapi_class
-
ITEM_TYPES
invariables.js
CollectionCardBuilder
handles incoming params
for creating a new CollectionCard
and its associated Item
. If YourItem
requires any additional backend operations to occur while being created, you'll most likely want them to occur here (possibly extracting them to a separate service based on how extensive they are).
At this point you should be able to create new kind of Item
in the rails console
. If you're unable to, double check that you're gone through the steps above. If it's still unclear what the issue is, ask another engineer.
Once you have instances of YourItem
(and their related CollectionCard
) being created in the database, you're ready to proceed.
You're getting close to having YourItem
available in the Shape GUI!