Skip to content

Conversation

@VeraZab
Copy link
Contributor

@VeraZab VeraZab commented Nov 2, 2018

No description provided.

@nicolaskruchten
Copy link
Contributor

To capture our verbal conversation: I think the ideal API here would be to pass in two arrays-of-strings, which would define the desired order, and that would be applied within PanelMenuWrapper.

@VeraZab VeraZab force-pushed the customize-default-editor branch from 5f21f1a to cbee36f Compare November 2, 2018 18:36
@VeraZab VeraZab changed the title WIP: allow custom ordering of default panels allow custom ordering of default panels Nov 2, 2018
@VeraZab
Copy link
Contributor Author

VeraZab commented Nov 2, 2018

@dmt0 @nicolaskruchten please review

@dmt0
Copy link
Contributor

dmt0 commented Nov 2, 2018

Code looks good!

@nicolaskruchten
Copy link
Contributor

A few test cases would be nice, including some edge cases like missing items in either the desired or actual order, mismatched group/name pairs, that sort of thing. Just to lock down the desired behaviour in a test :)

@VeraZab VeraZab force-pushed the customize-default-editor branch 2 times, most recently from ba8c0dc to 8bb6d10 Compare November 5, 2018 20:33
function sortAlphabetically(a, b) {
const sortByGroup = a.props.group === b.props.group ? 0 : a.props.group < b.props.group ? -1 : 1;
const sortByName = a.props.name === b.props.name ? 0 : a.props.name < b.props.name ? -1 : 1;
return sortByGroup || sortByName;
Copy link
Contributor

Choose a reason for hiding this comment

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

clever! took me a sec to think about how that works :)

const orderProp = [{group: 'DEV', name: 'JSON'}, {group: 'DEV', name: 'Inspector'}];
sortMenu(initialArray, orderProp);

expect(initialArray[0].props.name).toBe('JSON');
Copy link
Contributor

Choose a reason for hiding this comment

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

I would express these as expect(initialArray).toBe( ... the full array ... ) ... More readable and more complete IMO :)

describe('sortMenu', () => {
it('modifies original array to follow the group, then name order provided', () => {
const initialArray = [
{props: {group: 'DEV', name: 'Inspector'}},
Copy link
Contributor

Choose a reason for hiding this comment

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

I would consider making a helper here that takes in threes arrays of strings of form GROUP/NAME and does a split and does the comparison, just to have some very compact test cases below

)
);

const desiredGroupOrder = order.map(panel => panel.group).filter(getUniqueValues);
Copy link
Contributor

Choose a reason for hiding this comment

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

arguably this is unnecessary right? It won't change the order :)

DefaultEditor.propTypes = {
children: PropTypes.node,
logoSrc: PropTypes.string,
order: PropTypes.array,
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this should be called menuPanelOrder or something, for clarity

@nicolaskruchten
Copy link
Contributor

💃 ... all comments are just notes, not requests to change

@VeraZab VeraZab force-pushed the customize-default-editor branch from 3213d33 to bf7420c Compare November 5, 2018 21:24
@VeraZab VeraZab merged commit 9780ab1 into master Nov 5, 2018
@VeraZab VeraZab deleted the customize-default-editor branch November 5, 2018 21:31
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