-
Notifications
You must be signed in to change notification settings - Fork 456
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
Add plugin settings #230
Add plugin settings #230
Conversation
@BrainMaestro this is awesome! Great job! 👏 👏 |
Thanks!. I completely missed the lint issues, but I'll fix them later. Should I go ahead? Also, I noticed a bug with the settings plugin. It does not rerender settings that were changed as soon they were changed. Any idea why? This bug was not introduced by my changes. |
This feature is ready for review now |
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.
It looks great! Check out my comments and let me know if you think it is ok to fix them
app/main/actions/search.js
Outdated
const settings = externalSettings[name] | ||
if (settings) { | ||
Object.keys(settings).forEach(key => { | ||
settings[key] = settings[key].value |
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.
Why don't you store this settings as key=>value?
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.
You mean having the setting name at the top level instead of all of them nested under external
?
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.
@BrainMaestro no, I mean why do you need nested object with value => '...'
? Now externalSettings
is something like:
{
pluginName: {
language: {
value: 'en'
},
token: {
value: 'user-token'
}
}
}
But it could be simplified as:
{
pluginName: {
language: 'en',
token: 'user-token'
}
}
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.
Yes that's better, but for each setting we still need to keep a type
, description
, defaultValue
and other specific settings like multi
and options
. So the actual structure is closer to:
{
pluginName: {
language: {
type: 'option',
description: 'Your preferred language',
options: ['en', 'fr'],
value: 'en'
},
token: {
type: 'string',
value: 'user-token'
}
}
}
) | ||
|
||
Checkbox.propTypes = { | ||
value: PropTypes.any, |
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.
Do you see any cases to have non-boolean value here?
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.
Mistake from copying proptypes over from other components
@@ -0,0 +1,30 @@ | |||
import React, { PropTypes } from 'react' | |||
import styles from '../styles.css' | |||
import hotkeyStyles from '../Hotkey/styles.css' |
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.
I think it makes sense to move hotkey into components
directory and reuse styles for this component for all text inputs (so, we won't have separate css file for Hotkey
component)
key={label} | ||
label={label} | ||
value={value} | ||
onChange={({ target }) => this.changeSetting(plugin, label, target.value)} |
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 possible to change components a bit so all of them have the same API and onChange
function always called with new value, instead of Event or value? In this case we can do something like this:
const components = {
bool: Checkbox,
option: Options,
array: Select,
}
// ...
const { type, value, defaultValue, ...restProps } = setting
const FormComponent = components[type] || Input
return <FormComponent
value={value || defaultValue}
key={label}
label={label}
onChange={newValue => this.changeSetting(plugin, label, newValue)}
// ↓ this could contain `multi`, `options` or other specific fields
...restProps
}
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.
That's excellent!
Also I've just tested it locally: we should provide default value for To do it you can just add |
After |
Ok #238 should fix this issue |
ac89596
to
558914f
Compare
Should be good now |
@BrainMaestro @KELiON where can you guys merge it to |
@BrainMaestro I've changed few small things in branch Also, now I'm thinking about moving plugin settings from Settings to plugin preview. So, if some plugin is installed – when you type |
The PR was great! I'm not sure I understand your suggestion. You want to show the settings after the plugin preview? or as a separate entry in the search view under the plugin? The general |
@BrainMaestro when we search for plugins and focus on installed plugin, we can show settings above uninstall/details buttons. Somethin similar Atom do, but they have separate button for settings and show them above Readme: |
Oh. Yeah I like that idea. Do you want to implement it? or should I? |
@BrainMaestro I'm not sure I'll be able to do it until Monday, so feel free to implement it! We should also add information about settings to documentation and we're ready to go. |
Alright. I'll take a look. Any idea why the tests are failing? |
@BrainMaestro did you have any time to fix it? If not – I can do it on this week. Regarding tests – looks weird, I'll check it later, but I think it is related to test webpack config and |
Yeah I'm working on it. Quite a few things are broken though, so it's taking longer than I thought. It should be done by the end of the day. |
0be4992
to
4e900b7
Compare
@KELiON I made the change to move the settings to the plugin view. Looks like this now: Also, I was thinking about throttling the |
@BrainMaestro I think it looks good enough! Regarding throttling – I'd leave basic functionality for now. We can add it later if we find any problems |
Alright. I'll add the settings documentation later, but I guess this is good to merge now? |
@BrainMaestro going to test it later today. Looks awesome! |
@BrainMaestro Hey! I hope in this PR we have latest changes related to settings and can finally release it. Can you review my changes there? |
I left a comment there a few days ago. Not sure if you've seen it. |
@BrainMaestro I don't see any comments there |
Oh I added it as a review comment by mistake. Should be there now. |
8da7b49
to
6c7817d
Compare
Do not store settings structure in config, always get it from plugin object
6c7817d
to
7d644e0
Compare
Looks great |
Ok, now we only need to add it to documentation! Thank you @BrainMaestro for this big step!:) |
This is to implement #222
Currently it looks like this
There's support for
strings
,number
,array
,options
as different settings types. Each setting can also include a description and default value.term
ordisplay
that is passed in to a plugin's functionIt's still a work in progress, but I didn't feel comfortable doing so much without showing you. Just in case you don't agree with the way it is implemented or have other suggestions.
Fixes #222