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

Add plugin settings #230

Merged
merged 16 commits into from
Apr 7, 2017
Merged

Conversation

BrainMaestro
Copy link
Contributor

@BrainMaestro BrainMaestro commented Mar 10, 2017

This is to implement #222

Currently it looks like this
screen shot 2017-03-10 at 10 34 10 am

There's support for strings, number, array, options as different settings types. Each setting can also include a description and default value.

  • Add plugin settings for those that specify on startup
  • Render plugin settings in settings UI
  • Save changed plugin settings
  • Provide access to specified settings to plugins. i.e something similar to term or display that is passed in to a plugin's function
  • Add support for default values
  • Update plugin documentation

It'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

@KELiON
Copy link
Collaborator

KELiON commented Mar 10, 2017

@BrainMaestro this is awesome! Great job! 👏 👏

@BrainMaestro
Copy link
Contributor Author

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.

@BrainMaestro
Copy link
Contributor Author

This feature is ready for review now

Copy link
Collaborator

@KELiON KELiON left a 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

const settings = externalSettings[name]
if (settings) {
Object.keys(settings).forEach(key => {
settings[key] = settings[key].value
Copy link
Collaborator

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?

Copy link
Contributor Author

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?

Copy link
Collaborator

@KELiON KELiON Mar 14, 2017

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

Copy link
Contributor Author

@BrainMaestro BrainMaestro Mar 14, 2017

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,
Copy link
Collaborator

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?

Copy link
Contributor Author

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'
Copy link
Collaborator

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)}
Copy link
Collaborator

@KELiON KELiON Mar 13, 2017

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
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's excellent!

@KELiON
Copy link
Collaborator

KELiON commented Mar 13, 2017

Also I've just tested it locally: we should provide default value for external key in config, because I don't have it in my config.json and rendering of settings raises an exception:

screen shot 2017-03-13 at 15 41 37

To do it you can just add external: {} to config.js file

@KELiON
Copy link
Collaborator

KELiON commented Mar 13, 2017

Any idea why? This bug was not introduced by my changes.

After git bisect I found that issue was introduced when we switched to yarn instead of npm. I'll try to investigate, but I bet the problem in some package update (probably react)

@KELiON
Copy link
Collaborator

KELiON commented Mar 13, 2017

Ok #238 should fix this issue

@BrainMaestro
Copy link
Contributor Author

Should be good now

@footnoise
Copy link
Contributor

@BrainMaestro @KELiON where can you guys merge it to master. I need this settings extension ASAP :-)

@KELiON
Copy link
Collaborator

KELiON commented Mar 16, 2017

@BrainMaestro I've changed few small things in branch feature/plugin-settings, I've opened PR in your repo so you can review progress there. Main thing – I've changed structure of objects that we store in config: we can remove duplication of settings definition and always get it from plugin object, and store in config only real values.

Also, now I'm thinking about moving plugin settings from Settings to plugin preview. So, if some plugin is installed – when you type plugins name and you see preview of this plugin, below description we can show its settings. What do you think? I'd also add there one general checkbox for all plugins – disable.

@BrainMaestro
Copy link
Contributor Author

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 disable checkbox is a great idea.

@KELiON
Copy link
Collaborator

KELiON commented Mar 17, 2017

@BrainMaestro when we search for plugins and focus on installed plugin, we can show settings above uninstall/details buttons.

image

Somethin similar Atom do, but they have separate button for settings and show them above Readme:

@BrainMaestro
Copy link
Contributor Author

Oh. Yeah I like that idea. Do you want to implement it? or should I?

@KELiON
Copy link
Collaborator

KELiON commented Mar 17, 2017

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

@BrainMaestro
Copy link
Contributor Author

Alright. I'll take a look. Any idea why the tests are failing?

@KELiON
Copy link
Collaborator

KELiON commented Mar 20, 2017

@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 target option there

@BrainMaestro
Copy link
Contributor Author

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.

@KELiON KELiON mentioned this pull request Mar 20, 2017
@BrainMaestro
Copy link
Contributor Author

BrainMaestro commented Mar 21, 2017

@KELiON I made the change to move the settings to the plugin view. Looks like this now:
screen shot 2017-03-21 at 10 35 29 am
Any style changes?

Also, I was thinking about throttling the onChange function for the Input settings component. So every keystroke doesn't get saved. Would that make sense?

@KELiON
Copy link
Collaborator

KELiON commented Mar 21, 2017

@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

@BrainMaestro
Copy link
Contributor Author

Alright. I'll add the settings documentation later, but I guess this is good to merge now?

@KELiON
Copy link
Collaborator

KELiON commented Mar 21, 2017

@BrainMaestro going to test it later today. Looks awesome!

@KELiON
Copy link
Collaborator

KELiON commented Apr 3, 2017

@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?

@BrainMaestro
Copy link
Contributor Author

I left a comment there a few days ago. Not sure if you've seen it.

@KELiON
Copy link
Collaborator

KELiON commented Apr 6, 2017

@BrainMaestro I don't see any comments there

@BrainMaestro
Copy link
Contributor Author

Oh I added it as a review comment by mistake. Should be there now.

@BrainMaestro BrainMaestro force-pushed the add-plugin-settings branch 2 times, most recently from 8da7b49 to 6c7817d Compare April 6, 2017 16:42
@BrainMaestro BrainMaestro force-pushed the add-plugin-settings branch from 6c7817d to 7d644e0 Compare April 6, 2017 16:45
@BrainMaestro
Copy link
Contributor Author

Looks great

@KELiON
Copy link
Collaborator

KELiON commented Apr 7, 2017

Ok, now we only need to add it to documentation! Thank you @BrainMaestro for this big step!:)

@KELiON KELiON merged commit 19c50bb into cerebroapp:master Apr 7, 2017
@BrainMaestro BrainMaestro deleted the add-plugin-settings branch April 7, 2017 16:03
@BrainMaestro BrainMaestro mentioned this pull request Apr 11, 2017
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.

3 participants