Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor draftail ModalWorkflowSource for extensibility #6651

Merged
merged 2 commits into from Jun 28, 2021

Conversation

gasman
Copy link
Collaborator

@gasman gasman commented Dec 18, 2020

Currently, the important work in draftail's ModalWorkflowSource.js is handled by two functions getChooserConfig and filterEntityData which consist of a switch/case over the four built-in entity types: images, embeds, links and documents. This makes it impossible to extend draftail with new modal-powered entity types without editing (or duplicating) this file. To address this, I've refactored ModalWorkflowSource into an abstract class which is subclassed for each entity type.

Along the way I've relaxed the no-unused-vars eslint rule so that it doesn't complain about unused function parameters - I think this is needlessly restrictive, since a case like this (where multiple classes are implementing the same interface) is a valid place where unused parameters can arise. Now rebased to use "args": "after-used" and eslint-ignore as per Slack discussion...

@gasman gasman force-pushed the cleanup/modalworkflowsource-subclass branch from 4b0ce3d to 1cddb9c Compare December 23, 2020 00:24
Base automatically changed from master to main March 3, 2021 17:08
@thibaudcolas thibaudcolas removed their request for review April 14, 2021 08:14
…WorkflowSource

This means we're not artificially forcing four different entity types into the same code path, and makes it possible to define new entity types outside of this module.

Also relax the eslint no-unused-vars to allow unused function parameters - having multiple classes following the same interface is a legitimate use of this.
@gasman gasman force-pushed the cleanup/modalworkflowsource-subclass branch from 1cddb9c to 71912ea Compare June 18, 2021 17:39
@squash-labs
Copy link

squash-labs bot commented Jun 18, 2021

Manage this branch in Squash

Test this branch here: https://gasmancleanupmodalworkflowsour-pvtxo.squash.io

@gasman gasman requested a review from kaedroho June 18, 2021 17:46
@kaedroho kaedroho requested review from jacobtoppm and removed request for kaedroho June 22, 2021 08:09
Copy link
Member

@jacobtoppm jacobtoppm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me, though I think an alternative approach would be to use Typescript abstract classes

@@ -161,10 +29,20 @@ class ModalWorkflowSource extends Component {
this.onClose = this.onClose.bind(this);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
getChooserConfig(entity, selectedText) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth using Typescript abstract class for this, and making this an abstract method for instance? See https://www.typescriptlang.org/docs/handbook/2/classes.html#abstract-classes-and-members

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good - will give that a go!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave it a try, but npm run test says it isn't valid outside of a Typescript file, and if I rename the file to ModalWorkflowSource.ts I get failures elsewhere (Property 'jQuery' does not exist on type 'Global & typeof globalThis'). I'll leave that improvement for someone who knows Typescript :-)

@gasman gasman merged commit 5bb9e05 into wagtail:main Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants