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';
|
Sidebar code mirror interactions (#2433)
* Lifting path clicked up to sidebar root
* Abstracting out path click to story (and app)
* Adding click to scroll, updating sidebar components
* Scroll fix for sidebar
* Cleaning up log
* PR feedback
* PR Feedback, fix schemas & request body rendering
* PR feedback & cleanup
* Prop value checking, selection positioning
* Pulling remote import
* Styled components into insomnia-app, obj destructuring, typing
* Refactoring item path mapping
* Abstracting the mapping of specs for position, bumping down styled components version.
* Directly passing ... rest args initial work
* Pulling logs, removing array concatenation
* Pulling click handler out of render method
* Rolling position mapping into scroll positining method
* Opening up type, could be number/string/array
* Update package-lock.json
* Grabbing height from window, typing API vars, checking path
* Creating scroll method dedicated to design mode
* Moving typing of spec related content to Props def.
* Type checking on sections, invalid section component
2020-08-03 17:57:12 +00:00
|
|
|
import StyledInvalidSection from './sidebar-invalid-section';
|
2020-07-22 13:13:06 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
schemas: Object,
|
Sidebar code mirror interactions (#2433)
* Lifting path clicked up to sidebar root
* Abstracting out path click to story (and app)
* Adding click to scroll, updating sidebar components
* Scroll fix for sidebar
* Cleaning up log
* PR feedback
* PR Feedback, fix schemas & request body rendering
* PR feedback & cleanup
* Prop value checking, selection positioning
* Pulling remote import
* Styled components into insomnia-app, obj destructuring, typing
* Refactoring item path mapping
* Abstracting the mapping of specs for position, bumping down styled components version.
* Directly passing ... rest args initial work
* Pulling logs, removing array concatenation
* Pulling click handler out of render method
* Rolling position mapping into scroll positining method
* Opening up type, could be number/string/array
* Update package-lock.json
* Grabbing height from window, typing API vars, checking path
* Creating scroll method dedicated to design mode
* Moving typing of spec related content to Props def.
* Type checking on sections, invalid section component
2020-08-03 17:57:12 +00:00
|
|
|
onClick: (section: string, ...args: any) => void,
|
2020-07-22 13:13:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// 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 => {
|
Sidebar code mirror interactions (#2433)
* Lifting path clicked up to sidebar root
* Abstracting out path click to story (and app)
* Adding click to scroll, updating sidebar components
* Scroll fix for sidebar
* Cleaning up log
* PR feedback
* PR Feedback, fix schemas & request body rendering
* PR feedback & cleanup
* Prop value checking, selection positioning
* Pulling remote import
* Styled components into insomnia-app, obj destructuring, typing
* Refactoring item path mapping
* Abstracting the mapping of specs for position, bumping down styled components version.
* Directly passing ... rest args initial work
* Pulling logs, removing array concatenation
* Pulling click handler out of render method
* Rolling position mapping into scroll positining method
* Opening up type, could be number/string/array
* Update package-lock.json
* Grabbing height from window, typing API vars, checking path
* Creating scroll method dedicated to design mode
* Moving typing of spec related content to Props def.
* Type checking on sections, invalid section component
2020-08-03 17:57:12 +00:00
|
|
|
const { schemas, onClick } = this.props;
|
|
|
|
|
|
|
|
if (Object.prototype.toString.call(schemas) !== '[object Object]') {
|
|
|
|
return <StyledInvalidSection name={'schema'} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
const filteredValues = Object.keys(schemas).filter(schema =>
|
2020-07-22 13:13:06 +00:00
|
|
|
schema.toLowerCase().includes(filter.toLocaleLowerCase()),
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!filteredValues.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{filteredValues.map(schema => (
|
2020-09-16 15:11:42 +00:00
|
|
|
<SidebarItem key={schema} onClick={() => onClick('components', 'schemas', schema)}>
|
2020-07-22 13:13:06 +00:00
|
|
|
<div>
|
|
|
|
<SvgIcon icon={IconEnum.brackets} />
|
|
|
|
</div>
|
2020-09-16 15:11:42 +00:00
|
|
|
<span>{schema}</span>
|
2020-07-22 13:13:06 +00:00
|
|
|
</SidebarItem>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <SidebarSection title="SCHEMAS" renderBody={this.renderBody} />;
|
|
|
|
}
|
|
|
|
}
|