From f78851922ed2809d74c2ad40a4dd498b72d60129 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Fri, 10 Jan 2020 05:16:54 -0800 Subject: [PATCH] Make InspectorSidebar a functional component Summary: Refactoring a bit to make a change easier. Reviewed By: jknoxville Differential Revision: D19330542 fbshipit-source-id: 5926b110d04d73e109ea287cacd4e120ea8c9986 --- src/plugins/layout/InspectorSidebar.tsx | 100 +++++++++++------------- 1 file changed, 47 insertions(+), 53 deletions(-) diff --git a/src/plugins/layout/InspectorSidebar.tsx b/src/plugins/layout/InspectorSidebar.tsx index ee8bc2e21..43733500e 100644 --- a/src/plugins/layout/InspectorSidebar.tsx +++ b/src/plugins/layout/InspectorSidebar.tsx @@ -94,68 +94,62 @@ type Props = { logger: Logger; }; -export default class Sidebar extends Component { - render() { - const {element} = this.props; - if (!element || !element.data) { - return No data; - } +const Sidebar: React.FC = (props: Props) => { + const {element} = props; + if (!element || !element.data) { + return No data; + } - const sections: Array = - (SidebarExtensions && - SidebarExtensions.map(ext => - ext( - this.props.client, - this.props.realClient, - element.id, - this.props.logger, - ), - )) || - []; + const sections: Array = + (SidebarExtensions && + SidebarExtensions.map(ext => + ext(props.client, props.realClient, element.id, props.logger), + )) || + []; - for (const key in element.data) { - if (key === 'Extra Sections') { - for (const extraSection in element.data[key]) { - const section = element.data[key][extraSection]; - let data = {}; + for (const key in element.data) { + if (key === 'Extra Sections') { + for (const extraSection in element.data[key]) { + const section = element.data[key][extraSection]; + let data = {}; - // data might be sent as stringified JSON, we want to parse it for a nicer persentation. - if (typeof section === 'string') { - try { - data = JSON.parse(section); - } catch (e) { - // data was not a valid JSON, type is required to be an object - console.error( - `ElementsInspector unable to parse extra section: ${extraSection}`, - ); - data = {}; - } - } else { - data = section; + // data might be sent as stringified JSON, we want to parse it for a nicer persentation. + if (typeof section === 'string') { + try { + data = JSON.parse(section); + } catch (e) { + // data was not a valid JSON, type is required to be an object + console.error( + `ElementsInspector unable to parse extra section: ${extraSection}`, + ); + data = {}; } - sections.push( - , - ); + } else { + data = section; } - } else { sections.push( , ); } + } else { + sections.push( + , + ); } - - return sections; } -} + + return <>{sections}; +}; +export default Sidebar;