Skip to content

Commit

Permalink
[frontend] duplicate a feed (#7400)
Browse files Browse the repository at this point in the history
  • Loading branch information
CelineSebe committed Sep 24, 2024
1 parent d507f71 commit 1034b26
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ interface FeedAddInput {
}

interface FeedCreationFormProps {
paginationOptions: PaginationOptions
paginationOptions: PaginationOptions;
open: boolean;
isDuplicated: boolean;
onDrawerClose: () => void;
}

const feedCreationValidation = (t_i18n: (s: string) => string) => Yup.object().shape({
Expand All @@ -154,7 +157,7 @@ const feedCreationValidation = (t_i18n: (s: string) => string) => Yup.object().s
});

const FeedCreation: FunctionComponent<FeedCreationFormProps> = (props) => {
const { paginationOptions } = props;
const { onDrawerClose, open, paginationOptions, isDuplicated } = props;
const classes = useStyles();
const { t_i18n } = useFormatter();
const [selectedTypes, setSelectedTypes] = useState<string[]>([]);
Expand All @@ -173,6 +176,9 @@ const FeedCreation: FunctionComponent<FeedCreationFormProps> = (props) => {
setSelectedTypes([]);
helpers.handleClearAllFilters();
setFeedAttributes({ 0: {} });
if (!isDuplicated) {
onDrawerClose();
}
};

const handleSelectTypes = (types: string[]) => {
Expand Down Expand Up @@ -303,11 +309,12 @@ const FeedCreation: FunctionComponent<FeedCreationFormProps> = (props) => {
);
setFeedAttributes(R.assoc(i, newFeedAttribute, feedAttributes));
};

console.log('OPEN', open);
return (
<Drawer
title={t_i18n('Create a feed')}
variant={DrawerVariant.createWithPanel}
title={isDuplicated ? (t_i18n('Duplicate a feed')) : (t_i18n('Create a feed'))}
variant={isDuplicated ? undefined : DrawerVariant.createWithPanel}
open={open}
onClose={handleClose}
>
{({ onClose }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ConnectionHandler } from 'relay-runtime';
import inject18n from '../../../../components/i18n';
import { commitMutation, QueryRenderer } from '../../../../relay/environment';
import FeedEdition from './FeedEdition';
import FeedCreation from './FeedCreation';

const styles = () => ({
container: {
Expand Down Expand Up @@ -53,6 +54,7 @@ class FeedPopover extends Component {
displayUpdate: false,
displayDelete: false,
deleting: false,
displayDuplicate: false,
};
}

Expand All @@ -73,6 +75,15 @@ class FeedPopover extends Component {
this.setState({ displayUpdate: false });
}

handleOpenDuplicate() {
this.setState({ displayDuplicate: true });
this.handleClose();
}

handleCloseDuplicate() {
this.setState({ displayDuplicate: false });
}

handleOpenDelete() {
this.setState({ displayDelete: true });
this.handleClose();
Expand Down Expand Up @@ -127,6 +138,9 @@ class FeedPopover extends Component {
<MenuItem onClick={this.handleOpenUpdate.bind(this)}>
{t('Update')}
</MenuItem>
<MenuItem onClick={this.handleOpenDuplicate.bind(this)}>
{t('Duplicate')}
</MenuItem>
<MenuItem onClick={this.handleOpenDelete.bind(this)}>
{t('Delete')}
</MenuItem>
Expand All @@ -137,11 +151,20 @@ class FeedPopover extends Component {
render={({ props }) => {
if (props) {
return (
<FeedEdition
feed={props.feed}
handleClose={this.handleCloseUpdate.bind(this)}
open={this.state.displayUpdate}
/>
<>
<FeedEdition
feed={props.feed}
handleClose={this.handleCloseUpdate.bind(this)}
open={this.state.displayUpdate}
/>
<FeedCreation
feed={props.feed}
onDrawerClose={this.handleCloseDuplicate.bind(this)}
open={this.state.displayDuplicate}
paginationOptions={this.props.paginationOptions}
isDuplicated={true}
/>
</>
);
}
return <div />;
Expand Down

0 comments on commit 1034b26

Please sign in to comment.