-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
As part of the Wikimedia Commons integration project, there is an interest (@trnstlntk @lozanaross ) in customizing the cell rendering to include thumbnails of the media files being uploaded (or edited): OpenRefine/CommonsExtension#34.
There is currently no official way for an extension to customize how the cells of a particular column are rendered. Therefore, implementing this would first require introducing the corresponding extension point in OpenRefine itself.
Introducing extension points is a subtle thing to do, as we need to care about the following aspects:
- The introduction of the extension points commits us to maintaining such an interface in a stable way in the future, to some extent. For instance, if we wanted to rewrite the grid rendering in a different framework, this would likely imply changing this extension point, hence breaking extensions which rely on it;
- The use case that motivates the introduction of the extension point should be generalized sufficiently for the extension point to be useful to other use cases: we need to make a good effort at thinking about in which other use cases one might want to customize the way cells are rendered.
Proposed solution
We first need to enable extensions to store column-specific metadata which controls how the column is rendered. Introduce for this a JSON field in the column metadata object, where extensions can store arbitrary JSON.
Then, add a new extension point which lets extensions register cell rendering callbacks. A cell rendering callback is a javascript function, which takes as arguments:
- a cell object (as a JSON-deserialized object, which came from the backend)
- the column metadata for the column in which it is being rendered
The callback is expected to return:
- either a DOM element, which then becomes the rendered cell value (on top of which is added the "edit" button, still managed by the core software)
- or
null, meaning that the callback is not attempting to override the rendering of this cell and delegates its rendering to other callbacks or the core software
When cell rendering callbacks are registered, they are also attributed a priority (an integer) by the registrant. When rendering a cell, cell rendering callbacks are executed in order of decreasing priority. The first callback that returns a DOM element determines how the cell is rendered. If all callbacks return null, then the core software is used to render the cell.
Alternatives considered
Do not build an extension point for cell rendering, and instead build this feature in the core software, with the understanding that rendering file paths of images as thumbnails is a feature that would be useful to a wide enough community.
Feedback welcome
@elebitzero @tfmorris Can you think of other ways to support this?
Metadata
Metadata
Assignees
Labels
Type
Projects
Status