Skip to content

Conversation

rgommezz
Copy link
Contributor

@rgommezz rgommezz commented Jul 28, 2017

After sampling some images, I extrapolated some greyscale colors as defaults for each profile.
See #2

This PR merges the palette instance with the defaults, before the event emitter publish the change to all subscribers.

TODO

  • Validate this.props.defaults
  • Fix Flow
  • Unit test createMaterialPalette
  • Defaults should be only provided for the types passed
  • Unit test defaults merging in PaletteProvider

Note: I'll fix flow issues before merging this...couldn't run it again locally

@rgommezz rgommezz requested review from satya164 and zamotany July 28, 2017 12:31
Copy link
Contributor

@zamotany zamotany left a comment

Choose a reason for hiding this comment

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

Missing PaletteProvider test cases. Minimal CC - 100% 😛


_validateDefaults() {
if (this.props.defaults) {
if (typeof this.props.defaults !== 'object') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you flatten the conditionals?

if (this.props.defaults && typeof this.props.defaults !== 'object')

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 part is not finished, I am about to complete the defaults validation today

const paletteWithDefaults = this._mergeWithDefaults(palette);
execIfFunction(this.props.onFinish, paletteWithDefaults);
if (!this.props.forceRender) {
this.setState({ palette });
Copy link
Contributor

Choose a reason for hiding this comment

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

You should pass paletteWithDefaults instead of palette

),
};
return {
...Object.keys(palette)
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to spread the object inside object -> you're reducing it to object already.

Copy link
Member

Choose a reason for hiding this comment

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

@zamotany I think it's because he is merging it with defaults

Copy link
Contributor

Choose a reason for hiding this comment

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

a ok, haven't seen that ...defaults

@rgommezz rgommezz changed the title Default profile colors WIP - Default profile colors Jul 31, 2017
const defaultLightMuted = '#BDBDBD';
const defaultDarkMuted = '#616161';

export const validColorProfiles = [
Copy link
Member

Choose a reason for hiding this comment

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

You can use an object here and reuse it for the typedef:

const validColorProfiles = {
  vibrant: true,
  lightVibrant: true,
  darkVibrant: true,
  muted: true,
  lightMuted: true,
  darkMuted: true,
};

type ColorProfile = $Keys<typeof validColorProfiles>;

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 92.593% when pulling 6f59268 on default_profile_colors into 8ad6872 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 92.531% when pulling 0f1c7c1 on default_profile_colors into 8ad6872 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 92.531% when pulling c8de240 on default_profile_colors into 8ad6872 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 92.531% when pulling 3b70ee7 on default_profile_colors into 8ad6872 on master.

const validProfilesKeys = ['bodyTextColor', 'color', 'titleTextColor'];
(Object.keys((defaults: any)): ColorProfile[]).forEach(profile => {
if (!validColorProfiles.includes(profile)) {
if (!Object.keys(validColorProfiles).includes(profile)) {
Copy link
Member

Choose a reason for hiding this comment

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

Or profile in validColorProfiles

@coveralls
Copy link

Coverage Status

Coverage increased (+5.6%) to 97.51% when pulling 41c95bd on default_profile_colors into 8ad6872 on master.

@rgommezz rgommezz changed the title WIP - Default profile colors Default profile colors Aug 2, 2017
@rgommezz
Copy link
Contributor Author

rgommezz commented Aug 2, 2017

@satya164 @zamotany you can take another look 🤖

},
}));

createPalette({
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to return the Promise from createPalette otherwise the test will assume it's sync and won't wait for it.

@coveralls
Copy link

Coverage Status

Coverage increased (+5.6%) to 97.51% when pulling 95d5ae4 on default_profile_colors into 8ad6872 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+5.6%) to 97.51% when pulling f564ad1 on default_profile_colors into 8ad6872 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+5.6%) to 97.51% when pulling 8054f5b on default_profile_colors into 8ad6872 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+6.9%) to 98.77% when pulling 6ba98c4 on default_profile_colors into 8ad6872 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+7.3%) to 99.18% when pulling 1578bf5 on default_profile_colors into 8ad6872 on master.

@satya164
Copy link
Member

satya164 commented Aug 3, 2017

You guys are crazy

@coveralls
Copy link

Coverage Status

Coverage increased (+8.1%) to 100.0% when pulling 57e1576 on default_profile_colors into 8ad6872 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+8.1%) to 100.0% when pulling 993bfe1 on default_profile_colors into 8ad6872 on master.

@@ -0,0 +1,56 @@
/* eslint-disable import/first */
jest.mock('../validateCreatePaletteArgs', () => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

jest.mock('../validateCreatePaletteArgs') is sufficient

Copy link
Contributor

@zamotany zamotany left a comment

Choose a reason for hiding this comment

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

👍

@rgommezz rgommezz merged commit ec73f4c into master Aug 3, 2017
@rgommezz rgommezz deleted the default_profile_colors branch August 3, 2017 13:05
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.

4 participants