/** * Copyright 2018-present Facebook. * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * @format */ import { Text, FlexColumn, styled, FlexRow, Button, Spacer, Checkbox, colors, View, } from 'flipper'; import React, {Component} from 'react'; export type PluginSelection = Map; type Props = { onSelect: (plugins: Array) => void; onHide: () => any; plugins: PluginSelection; }; const Title = styled(Text)({ margin: 6, }); type State = { plugins: PluginSelection; }; const Container = styled(FlexColumn)({ padding: 8, width: 700, maxHeight: 700, }); const Line = styled(View)({ backgroundColor: colors.greyTint2, height: 1, width: 'auto', flexShrink: 0, }); const PluginRowComponentContainer = styled(FlexColumn)({ overflow: 'scroll', height: 'auto', backgroundColor: colors.white, maxHeight: 500, }); const Padder = styled('div')( ({paddingLeft, paddingRight, paddingBottom, paddingTop}) => ({ paddingLeft: paddingLeft || 0, paddingRight: paddingRight || 0, paddingBottom: paddingBottom || 0, paddingTop: paddingTop || 0, }), ); type PluginRowComponentProps = { name: string; selected: boolean; onChange: (name: string, selected: boolean) => void; }; class PluginRowComponent extends Component { render() { const {name, selected, onChange} = this.props; return ( {name} { onChange(name, selected); }} /> ); } } export default class SelectPluginSheet extends Component { state = {plugins: new Map()}; static getDerivedStateFromProps(props: Props, state: State) { if (state.plugins.size > 0) { return null; } return {plugins: props.plugins}; } onSubmit(plugins: PluginSelection) { const selectedArray = Array.from(plugins.entries()).reduce( (acc, [plugin, selected]) => { if (selected) { acc.push(plugin); } return acc; }, [], ); this.props.onSelect(selectedArray); } render() { const {onHide} = this.props; const {plugins} = this.state; return ( Select the plugins for which you want to export the data {Array.from(plugins.entries()).map(([pluginID, selected]) => { return ( { plugins.set(id, selected); this.setState({plugins}); }} /> ); })} ); } }