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
Refactor draftail ModalWorkflowSource for extensibility #6651
Conversation
4b0ce3d
to
1cddb9c
Compare
…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.
1cddb9c
to
71912ea
Compare
Manage this branch in SquashTest this branch here: https://gasmancleanupmodalworkflowsour-pvtxo.squash.io |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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 :-)
Currently, the important work in draftail's ModalWorkflowSource.js is handled by two functions
getChooserConfig
andfilterEntityData
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...