Refactor Listview to make it agnostic to the export logic

Summary: This diff makes Listview agnostic to the logic of the sharing.

Reviewed By: mweststrate

Differential Revision: D18711095

fbshipit-source-id: 75541dee0b5740c9951c46118d96292e28979507
This commit is contained in:
Pritesh Nandgaonkar
2019-11-27 08:44:31 -08:00
committed by Facebook Github Bot
parent 32a02f7f99
commit 0a311def8f
2 changed files with 108 additions and 94 deletions

View File

@@ -23,7 +23,8 @@ import {
} from '../reducers/application'; } from '../reducers/application';
import ListView from './ListView'; import ListView from './ListView';
import {Dispatch, Action} from 'redux'; import {Dispatch, Action} from 'redux';
import {unsetShare} from '../reducers/application';
import {FlexColumn, styled} from 'flipper';
type OwnProps = { type OwnProps = {
onHide: () => void; onHide: () => void;
}; };
@@ -41,13 +42,25 @@ type DispatchFromProps = {
file: string; file: string;
closeOnFinish: boolean; closeOnFinish: boolean;
}) => void; }) => void;
unsetShare: () => void;
}; };
type Props = OwnProps & StateFromProps & DispatchFromProps; type Props = OwnProps & StateFromProps & DispatchFromProps;
const Container = styled(FlexColumn)({
width: 700,
maxHeight: 700,
});
class ExportDataPluginSheet extends Component<Props> { class ExportDataPluginSheet extends Component<Props> {
render() { render() {
const {plugins, pluginStates, onHide} = this.props; const {plugins, pluginStates, onHide} = this.props;
const onHideWithUnsettingShare = () => {
this.props.unsetShare();
onHide();
};
return ( return (
<Container>
<ListView <ListView
type="multiple" type="multiple"
title="Select the plugins for which you want to export the data" title="Select the plugins for which you want to export the data"
@@ -90,8 +103,10 @@ class ExportDataPluginSheet extends Component<Props> {
} }
return acc; return acc;
}, new Set([]) as Set<string>)} }, new Set([]) as Set<string>)}
onHide={onHide} onHide={onHideWithUnsettingShare}
showNavButtons={true}
/> />
</Container>
); );
} }
} }
@@ -115,5 +130,8 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
}) => { }) => {
dispatch(getExportDataToFileActiveSheetAction(payload)); dispatch(getExportDataToFileActiveSheetAction(payload));
}, },
unsetShare: () => {
dispatch(unsetShare());
},
}), }),
)(ExportDataPluginSheet); )(ExportDataPluginSheet);

View File

@@ -18,7 +18,6 @@ import {
colors, colors,
View, View,
} from 'flipper'; } from 'flipper';
import {unsetShare} from '../reducers/application';
import React, {Component} from 'react'; import React, {Component} from 'react';
import {ReactReduxContext} from 'react-redux'; import {ReactReduxContext} from 'react-redux';
@@ -38,7 +37,8 @@ type Props = {
onSelect: (elements: Array<string>) => void; onSelect: (elements: Array<string>) => void;
onHide: () => any; onHide: () => any;
elements: Array<string>; elements: Array<string>;
title: string; title?: string;
showNavButtons: boolean;
} & SubType; } & SubType;
const Title = styled(Text)({ const Title = styled(Text)({
@@ -51,8 +51,6 @@ type State = {
const Container = styled(FlexColumn)({ const Container = styled(FlexColumn)({
padding: 8, padding: 8,
width: 700,
maxHeight: 700,
}); });
const Line = styled(View)({ const Line = styled(View)({
@@ -137,37 +135,36 @@ export default class ListView extends Component<Props, State> {
} }
handleChange = (id: string, selected: boolean) => { handleChange = (id: string, selected: boolean) => {
let selectedElements: Set<string> = new Set([]);
if (this.props.type === 'single') { if (this.props.type === 'single') {
if (!selected) { if (!selected) {
this.setState({selectedElements: new Set([])}); this.setState({selectedElements: selectedElements});
} else { } else {
this.setState({selectedElements: new Set([id])}); selectedElements.add(id);
this.setState({selectedElements: selectedElements});
} }
} else { } else {
if (selected) { if (selected) {
selectedElements = new Set([...this.state.selectedElements, id]);
this.setState({ this.setState({
selectedElements: new Set([...this.state.selectedElements, id]), selectedElements: selectedElements,
}); });
} else { } else {
const selectedElements = new Set([...this.state.selectedElements]); selectedElements = new Set([...this.state.selectedElements]);
selectedElements.delete(id); selectedElements.delete(id);
this.setState({selectedElements}); this.setState({selectedElements});
} }
} }
if (!this.props.showNavButtons) {
this.props.onSelect([...selectedElements]);
}
}; };
render() { render() {
return (
<ReactReduxContext.Consumer>
{({store}) => {
const onHide = () => {
store.dispatch(unsetShare());
this.props.onHide();
};
return ( return (
<Container> <Container>
<FlexColumn> <FlexColumn>
<Title>{this.props.title}</Title> {this.props.title && <Title>{this.props.title}</Title>}
<RowComponentContainer> <RowComponentContainer>
{this.props.elements.map(id => { {this.props.elements.map(id => {
return ( return (
@@ -181,10 +178,11 @@ export default class ListView extends Component<Props, State> {
})} })}
</RowComponentContainer> </RowComponentContainer>
</FlexColumn> </FlexColumn>
{this.props.showNavButtons && (
<Padder paddingTop={8} paddingBottom={2}> <Padder paddingTop={8} paddingBottom={2}>
<FlexRow> <FlexRow>
<Spacer /> <Spacer />
<Button compact padded onClick={onHide}> <Button compact padded onClick={this.props.onHide}>
Close Close
</Button> </Button>
<Button <Button
@@ -198,10 +196,8 @@ export default class ListView extends Component<Props, State> {
</Button> </Button>
</FlexRow> </FlexRow>
</Padder> </Padder>
)}
</Container> </Container>
); );
}}
</ReactReduxContext.Consumer>
);
} }
} }