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

React Native: On Device Knobs Groups Fix #8694

Merged
merged 2 commits into from
Nov 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions addons/ondevice-knobs/src/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,39 @@ export default class Panel extends React.Component {
return null;
}

const { knobs, groupId } = this.state;
const { knobs, groupId: stateGroupId } = this.state;

const groups = {};
const groupIds = [];

let knobsArray = Object.keys(knobs);

knobsArray
.filter(key => knobs[key].groupId)
.forEach(key => {
const knobKeyGroupId = knobs[key].groupId;
groupIds.push(knobKeyGroupId);
groups[knobKeyGroupId] = {
render: () => <Text id={knobKeyGroupId}>{knobKeyGroupId}</Text>,
title: knobKeyGroupId,
};
});
const knobsWithGroups = knobsArray.filter(key => knobs[key].groupId);

if (groupIds.length > 0) {
groups[DEFAULT_GROUP_ID] = {
render: () => <Text id={DEFAULT_GROUP_ID}>{DEFAULT_GROUP_ID}</Text>,
title: DEFAULT_GROUP_ID,
knobsWithGroups.forEach(key => {
const knobKeyGroupId = knobs[key].groupId;
groupIds.push(knobKeyGroupId);
groups[knobKeyGroupId] = {
render: () => <Text id={knobKeyGroupId}>{knobKeyGroupId}</Text>,
title: knobKeyGroupId,
};
});

const allHaveGroups = groupIds.length > 0 && knobsArray.length === knobsWithGroups.length;

// If all of the knobs are assigned to a group, we don't need the default group.
const groupId =
stateGroupId === DEFAULT_GROUP_ID && allHaveGroups
? knobs[knobsWithGroups[0]].groupId
: stateGroupId;

if (groupIds.length > 0) {
if (!allHaveGroups) {
groups[DEFAULT_GROUP_ID] = {
render: () => <Text id={DEFAULT_GROUP_ID}>{DEFAULT_GROUP_ID}</Text>,
title: DEFAULT_GROUP_ID,
};
}

if (groupId === DEFAULT_GROUP_ID) {
knobsArray = knobsArray.filter(key => !knobs[key].groupId);
Expand Down