Skip to content

Commit

Permalink
Merge pull request #6232 from storybooks/5256-fix-ungrouped-knobs
Browse files Browse the repository at this point in the history
Knobs: Rename ALL panel to Other for ungrouped knobs
  • Loading branch information
ndelangen authored Mar 25, 2019
2 parents 496408c + 3d8b8bc commit 313c84e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion addons/knobs/src/components/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import PropForm from './PropForm';

const getTimestamp = () => +new Date();

const DEFAULT_GROUP_ID = 'ALL';
const DEFAULT_GROUP_ID = 'Other';

const PanelWrapper = styled(({ children, className }) => (
<ScrollArea horizontal vertical className={className}>
Expand Down Expand Up @@ -197,6 +197,9 @@ export default class KnobPanel extends PureComponent {
}

const entries = Object.entries(groups);
// Always sort 'Other' (ungrouped) tab last without changing the remaining tabs
entries.sort((a, b) => (a[0] === 'Other' ? 1 : 0)); // eslint-disable-line no-unused-vars

return (
<Fragment>
<PanelWrapper>
Expand Down
8 changes: 4 additions & 4 deletions addons/knobs/src/components/__tests__/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('Panel', () => {
root.unmount();
});

it('should have one tab per groupId and an empty ALL tab when all are defined', () => {
it('should have one tab per groupId and an empty Other tab when all are defined', () => {
const root = mount(
<ThemeProvider theme={convert(themes.light)}>
<Panel channel={testChannel} api={testApi} active />
Expand Down Expand Up @@ -263,7 +263,7 @@ describe('Panel', () => {
root.unmount();
});

it('the ALL tab should have its own additional content when there are knobs both with and without a groupId', () => {
it('the Other tab should have its own additional content when there are knobs both with and without a groupId', () => {
const root = mount(
<ThemeProvider theme={convert(themes.light)}>
<Panel channel={testChannel} api={testApi} active />
Expand Down Expand Up @@ -293,10 +293,10 @@ describe('Panel', () => {
.find(TabsState)
.find('button')
.map(child => child.prop('children'));
expect(titles).toEqual(['foo', 'ALL']);
expect(titles).toEqual(['foo', 'Other']);

const knobs = wrapper.find(PropForm).map(propForm => propForm.prop('knobs'));
// there are props with no groupId so ALL should also have its own PropForm
// there are props with no groupId so Other should also have its own PropForm
expect(knobs.length).toEqual(titles.length);
expect(knobs).toMatchSnapshot();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Array [
]
`;

exports[`Panel groups should have one tab per groupId and an empty ALL tab when all are defined 1`] = `
exports[`Panel groups should have one tab per groupId and an empty Other tab when all are defined 1`] = `
Array [
.emotion-2 {
box-sizing: border-box;
Expand Down Expand Up @@ -212,7 +212,7 @@ Array [
]
`;

exports[`Panel groups the ALL tab should have its own additional content when there are knobs both with and without a groupId 1`] = `
exports[`Panel groups the Other tab should have its own additional content when there are knobs both with and without a groupId 1`] = `
Array [
Array [
Object {
Expand Down
2 changes: 1 addition & 1 deletion addons/ondevice-knobs/src/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PropForm from './PropForm';

const getTimestamp = () => +new Date();

const DEFAULT_GROUP_ID = 'ALL';
const DEFAULT_GROUP_ID = 'Other';

export default class Panel extends React.Component {
constructor(props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ exports[`Storyshots Addons|Knobs.withKnobs tweaks static values organized in gro
Whiskey
</li>
</ul>
<p>
When I'm by myself, I say: "Mumble"
</p>
</div>
`;

Expand Down
4 changes: 4 additions & 0 deletions examples/official-storybook/stories/addon-knobs.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ storiesOf('Addons|Knobs.withKnobs', module)
GROUP_IDS.DISPLAY
);

// Ungrouped
const ungrouped = text('Ungrouped', 'Mumble');

const style = { backgroundColor, ...otherStyles };

const salutation = nice ? 'Nice to meet you!' : 'Leave me alone!';
Expand All @@ -178,6 +181,7 @@ storiesOf('Addons|Knobs.withKnobs', module)
<li key={`${item}`}>{item}</li>
))}
</ul>
<p>When I'm by myself, I say: "{ungrouped}"</p>
</div>
);
})
Expand Down

0 comments on commit 313c84e

Please sign in to comment.