Skip to content

Adding a New Item type to Shape

Matthew Villwock edited this page Mar 15, 2019 · 3 revisions

Adding a subclass

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

Make a new Creator component

Collections and Items 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.

Adding Code Dependencies

Items in Shape are generally created through CollectionCardController because CollectionCards 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 any attributes you'll want to send via JSON
  • add the serializer you created to BaseController#jsonapi_class
  • ITEM_TYPES in variables.js

Updating the CollectionCardBuilder

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).

Try creating YourItem

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.

Updating CoverRenderer

You're getting close to having YourItem available in the Shape GUI!

To Be Continued...

Clone this wiki locally