Skip to content

Desktop: Expose prompt to plugins as a command#5058

Merged
laurent22 merged 4 commits intolaurent22:devfrom
nishantwrp:showprompt-command
Jun 10, 2021
Merged

Desktop: Expose prompt to plugins as a command#5058
laurent22 merged 4 commits intolaurent22:devfrom
nishantwrp:showprompt-command

Conversation

@nishantwrp
Copy link
Contributor

Adds a command to show the prompt and get the user input so that it can be used by plugins.

comp.setState({
promptOptions: {
...config,
label: _(config.label),
Copy link
Owner

Choose a reason for hiding this comment

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

Please remove this line - only literal strings can be wrapped in _(). It means the calling code will have to do their own translations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, ok. done

answer: answer,
buttonType: buttonType,
});
comp.setState({ promptOptions: null });
Copy link
Owner

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Done.

'toggleSafeMode',
'showShareNoteDialog',
'showShareFolderDialog',
'showPrompt',
Copy link
Owner

Choose a reason for hiding this comment

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

As the name says, these commands are those that show up in the menu, but this one shouldn't so you can remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, done.


export const runtime = (comp: any): CommandRuntime => {
return {
execute: async (_context: CommandContext, config: any) => {
Copy link
Owner

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done.

@nishantwrp
Copy link
Contributor Author

This PR is ready for another review.


interface PromptConfig {
label: string;
inputType?: 'dropdown' | 'datetime' | 'tags' | 'text';
Copy link
Owner

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah okay. Done.

Comment on lines 7 to 12
enum PromptInputType {
Dropdown = 'dropdown',
Datetime = 'datetime',
Tags = 'tags',
Text = 'text',
}
Copy link
Owner

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

@nishantwrp nishantwrp Jun 10, 2021

Choose a reason for hiding this comment

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

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.

@nishantwrp
Copy link
Contributor Author

This PR is ready for another review.

@laurent22
Copy link
Owner

Looks good now, thanks for the update.

@laurent22 laurent22 merged commit c5c38a3 into laurent22:dev Jun 10, 2021
@nishantwrp nishantwrp deleted the showprompt-command branch June 11, 2021 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants