insomnia/packages/insomnia-components/components/sidebar/sidebar-schemas.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

Design sidebar (#2328) * updated lock file * Rolling sidebar from SB into application * Type fix on the method label output * Update packages/insomnia-components/components/sidebar.js Co-authored-by: Opender Singh <opender94@gmail.com> * PR Feedback - Keys, useCallback Hook * stubbing component breakout * PR Feedback - Breaking out most UI elements into components - Filter component in place - Various CSS tweaks * Removing unused file * Updating toggle * Resuable sidebar section (#2359) * Introduce resuable sidebar section * Stop eslint complaining * add react-use * Lint fixes * Make the storybook story less wide * Component development Abstracting out line level components i.e. Section > Header > Filter > Panel > Items Various code fixes * Cleaning up section visibility state * Reverting visibiilty state updater * Adding paths on click for spec scrolling * refreshing package-lock to resolve conflict * PR feedback for sidebar components * Update packages/insomnia-components/components/sidebar/sidebar-header.js Co-authored-by: Opender Singh <opender94@gmail.com> * Including lock * Merge fix * Component structuring, prop clean-up, css updates * Cleaning up components, pr feedback, fixing styling * array index reference clean-up/clarity * Leveraging useToggle rather than manual useState toggling * Cleaning up logs * Hide info section if missing from spec. * Update packages/insomnia-components/components/sidebar/sidebar-responses.js Co-authored-by: Opender Singh <opender94@gmail.com> * Update packages/insomnia-components/components/sidebar/sidebar-schemas.js Co-authored-by: Opender Singh <opender94@gmail.com> * Pull fragment * Destructuring and filter cleanup * Clearing filter value and DOM on section collapse * Merge latest * Merge conflict cleanup Co-authored-by: Opender Singh <opender94@gmail.com>
2020-07-22 13:13:06 +00:00
// @flow
import * as React from 'react';
import SidebarItem from './sidebar-item';
import SvgIcon, { IconEnum } from '../svg-icon';
import SidebarSection from './sidebar-section';
type Props = {
schemas: Object,
};
let itemPath = [];
const handleClick = items => {
itemPath.push('schema');
itemPath.push.apply(itemPath, items);
itemPath = [];
};
// Implemented as a class component because of a caveat with render props
// https://reactjs.org/docs/render-props.html#be-careful-when-using-render-props-with-reactpurecomponent
export default class SidebarSchemas extends React.Component<Props> {
renderBody = (filter: string): null | React.Node => {
const filteredValues = Object.keys(this.props.schemas).filter(schema =>
schema.toLowerCase().includes(filter.toLocaleLowerCase()),
);
if (!filteredValues.length) {
return null;
}
return (
<div>
{filteredValues.map(schema => (
<SidebarItem key={schema}>
<div>
<SvgIcon icon={IconEnum.brackets} />
</div>
<span onClick={() => handleClick([schema])}>{schema}</span>
</SidebarItem>
))}
</div>
);
};
render() {
return <SidebarSection title="SCHEMAS" renderBody={this.renderBody} />;
}
}