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:
committed by
Facebook Github Bot
parent
32a02f7f99
commit
0a311def8f
@@ -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,57 +42,71 @@ 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 (
|
||||||
<ListView
|
<Container>
|
||||||
type="multiple"
|
<ListView
|
||||||
title="Select the plugins for which you want to export the data"
|
type="multiple"
|
||||||
onSelect={selectedArray => {
|
title="Select the plugins for which you want to export the data"
|
||||||
this.props.selectedPlugins(selectedArray);
|
onSelect={selectedArray => {
|
||||||
const {share} = this.props;
|
this.props.selectedPlugins(selectedArray);
|
||||||
if (!share) {
|
const {share} = this.props;
|
||||||
console.error(
|
if (!share) {
|
||||||
'applications.share is undefined, whereas it was expected to be defined',
|
console.error(
|
||||||
);
|
'applications.share is undefined, whereas it was expected to be defined',
|
||||||
} else {
|
);
|
||||||
switch (share.type) {
|
} else {
|
||||||
case 'link':
|
switch (share.type) {
|
||||||
this.props.setActiveSheet(ACTIVE_SHEET_SHARE_DATA);
|
case 'link':
|
||||||
break;
|
this.props.setActiveSheet(ACTIVE_SHEET_SHARE_DATA);
|
||||||
case 'file': {
|
break;
|
||||||
const file = share.file;
|
case 'file': {
|
||||||
if (file) {
|
const file = share.file;
|
||||||
this.props.setExportDataToFileActiveSheet({
|
if (file) {
|
||||||
file,
|
this.props.setExportDataToFileActiveSheet({
|
||||||
closeOnFinish: true,
|
file,
|
||||||
});
|
closeOnFinish: true,
|
||||||
} else {
|
});
|
||||||
console.error('share.file is undefined');
|
} else {
|
||||||
|
console.error('share.file is undefined');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}}
|
||||||
}}
|
elements={getActivePersistentPlugins(pluginStates, plugins)}
|
||||||
elements={getActivePersistentPlugins(pluginStates, plugins)}
|
selectedElements={getActivePersistentPlugins(
|
||||||
selectedElements={getActivePersistentPlugins(
|
pluginStates,
|
||||||
pluginStates,
|
plugins,
|
||||||
plugins,
|
).reduce((acc, plugin) => {
|
||||||
).reduce((acc, plugin) => {
|
if (
|
||||||
if (
|
plugins.selectedPlugins.length <= 0 ||
|
||||||
plugins.selectedPlugins.length <= 0 ||
|
plugins.selectedPlugins.includes(plugin)
|
||||||
plugins.selectedPlugins.includes(plugin)
|
) {
|
||||||
) {
|
acc.add(plugin);
|
||||||
acc.add(plugin);
|
}
|
||||||
}
|
return acc;
|
||||||
return acc;
|
}, new Set([]) as Set<string>)}
|
||||||
}, new Set([]) as Set<string>)}
|
onHide={onHideWithUnsettingShare}
|
||||||
onHide={onHide}
|
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);
|
||||||
|
|||||||
@@ -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,71 +135,69 @@ 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 (
|
return (
|
||||||
<ReactReduxContext.Consumer>
|
<Container>
|
||||||
{({store}) => {
|
<FlexColumn>
|
||||||
const onHide = () => {
|
{this.props.title && <Title>{this.props.title}</Title>}
|
||||||
store.dispatch(unsetShare());
|
<RowComponentContainer>
|
||||||
this.props.onHide();
|
{this.props.elements.map(id => {
|
||||||
};
|
return (
|
||||||
return (
|
<RowComponent
|
||||||
<Container>
|
name={id}
|
||||||
<FlexColumn>
|
key={id}
|
||||||
<Title>{this.props.title}</Title>
|
selected={this.state.selectedElements.has(id)}
|
||||||
<RowComponentContainer>
|
onChange={this.handleChange}
|
||||||
{this.props.elements.map(id => {
|
/>
|
||||||
return (
|
);
|
||||||
<RowComponent
|
})}
|
||||||
name={id}
|
</RowComponentContainer>
|
||||||
key={id}
|
</FlexColumn>
|
||||||
selected={this.state.selectedElements.has(id)}
|
{this.props.showNavButtons && (
|
||||||
onChange={this.handleChange}
|
<Padder paddingTop={8} paddingBottom={2}>
|
||||||
/>
|
<FlexRow>
|
||||||
);
|
<Spacer />
|
||||||
})}
|
<Button compact padded onClick={this.props.onHide}>
|
||||||
</RowComponentContainer>
|
Close
|
||||||
</FlexColumn>
|
</Button>
|
||||||
<Padder paddingTop={8} paddingBottom={2}>
|
<Button
|
||||||
<FlexRow>
|
compact
|
||||||
<Spacer />
|
padded
|
||||||
<Button compact padded onClick={onHide}>
|
type="primary"
|
||||||
Close
|
onClick={() => {
|
||||||
</Button>
|
this.props.onSelect([...this.state.selectedElements]);
|
||||||
<Button
|
}}>
|
||||||
compact
|
Submit
|
||||||
padded
|
</Button>
|
||||||
type="primary"
|
</FlexRow>
|
||||||
onClick={() => {
|
</Padder>
|
||||||
this.props.onSelect([...this.state.selectedElements]);
|
)}
|
||||||
}}>
|
</Container>
|
||||||
Submit
|
|
||||||
</Button>
|
|
||||||
</FlexRow>
|
|
||||||
</Padder>
|
|
||||||
</Container>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
</ReactReduxContext.Consumer>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user