Desktop: Expose prompt to plugins as a command#5058
Desktop: Expose prompt to plugins as a command#5058laurent22 merged 4 commits intolaurent22:devfrom nishantwrp:showprompt-command
Conversation
| comp.setState({ | ||
| promptOptions: { | ||
| ...config, | ||
| label: _(config.label), |
There was a problem hiding this comment.
Please remove this line - only literal strings can be wrapped in _(). It means the calling code will have to do their own translations.
| answer: answer, | ||
| buttonType: buttonType, | ||
| }); | ||
| comp.setState({ promptOptions: null }); |
There was a problem hiding this comment.
I'd put that before resolve otherwise if the calling code changes something to the UI, for example going to a different screen, you might call setState on an unmounted component.
| 'toggleSafeMode', | ||
| 'showShareNoteDialog', | ||
| 'showShareFolderDialog', | ||
| 'showPrompt', |
There was a problem hiding this comment.
As the name says, these commands are those that show up in the menu, but this one shouldn't so you can remove this.
|
|
||
| export const runtime = (comp: any): CommandRuntime => { | ||
| return { | ||
| execute: async (_context: CommandContext, config: any) => { |
There was a problem hiding this comment.
Would you mind defining an interface for the config? It's not too hard to do and it would make the command more usable. It would start like this:
interface PromptConfig {
label: string;
description?: string;
// etc.
}If you search for promptOptions: in the codebase you'll find the possible properties.
|
This PR is ready for another review. |
|
|
||
| interface PromptConfig { | ||
| label: string; | ||
| inputType?: 'dropdown' | 'datetime' | 'tags' | 'text'; |
There was a problem hiding this comment.
Your code is correct, but TypeScript has various issues with fields defined as string options like this. So instead it's better to create an enum type that has all the possible values.
So inputType?: PromptInputType
And then:
enum PromptInputType {
Dropdown = 'dropdown',
// etc.
}| enum PromptInputType { | ||
| Dropdown = 'dropdown', | ||
| Datetime = 'datetime', | ||
| Tags = 'tags', | ||
| Text = 'text', | ||
| } |
There was a problem hiding this comment.
Use tabs. Could you make sure you have the commit hook installed as it's quite annoying having to ask for something like this. Or maybe you made changes directly on GitHub without testing which is even worse.
There was a problem hiding this comment.
Done. That's weird, I don't know why this happened. Usually, the hook runs every time for me. I guess I committed while being in packages/app-desktop directory. Maybe that's why the hooks didn't run.
|
This PR is ready for another review. |
|
Looks good now, thanks for the update. |
Adds a command to show the prompt and get the user input so that it can be used by plugins.