Skip to content

Commit

Permalink
feat: add button to copy multiple files at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-Torrent committed Aug 17, 2021
1 parent bfc7357 commit 38b9d5e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/context/CopyItemModalContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const CopyItemModalContext = React.createContext();

const CopyItemModalProvider = ({ children }) => {
const { t } = useTranslation();
const { mutate: copyItem } = useMutation(MUTATION_KEYS.COPY_ITEM);
const { mutate: copyItem } = useMutation(MUTATION_KEYS.COPY_ITEMS);
const [open, setOpen] = useState(false);
const [itemId, setItemId] = useState(false);

Expand Down
47 changes: 47 additions & 0 deletions src/components/main/CopyButtons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import Tooltip from '@material-ui/core/Tooltip';
import PropTypes from 'prop-types';
import IconButton from '@material-ui/core/IconButton';
import { FilterNone } from '@material-ui/icons';
import { ITEM_COPY_BUTTON_CLASS } from '../../config/selectors';
import { CopyItemModalContext } from '../context/CopyItemModalContext';

const CopyButton = ({ itemIds, color, id }) => {
const { t } = useTranslation();

const { openModal: openCopyModal } = useContext(CopyItemModalContext);

const handleCopy = () => {
openCopyModal(itemIds);
};

return (
<>
<Tooltip title={t('Copy')}>
<IconButton
id={id}
color={color}
className={ITEM_COPY_BUTTON_CLASS}
aria-label="copy"
onClick={handleCopy}
>
<FilterNone />
</IconButton>
</Tooltip>
</>
);
};

CopyButton.propTypes = {
itemIds: PropTypes.arrayOf(PropTypes.string).isRequired,
color: PropTypes.string,
id: PropTypes.string,
};

CopyButton.defaultProps = {
color: 'default',
id: '',
};

export default CopyButton
8 changes: 8 additions & 0 deletions src/components/main/TableToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useTranslation } from 'react-i18next';
import { ITEMS_TABLE_DELETE_SELECTED_ITEMS_ID } from '../../config/selectors';
import DeleteButton from '../common/DeleteButton';
import NewItemButton from './NewItemButton';
import CopyButton from './CopyButtons';

const useToolbarStyles = makeStyles((theme) => ({
root: {
Expand Down Expand Up @@ -60,6 +61,13 @@ const TableToolbar = (props) => {
</>
)}

{numSelected > 0 && (
<CopyButton
id="copy"
color="secondary"
itemIds={selected}
/>
)}
{numSelected > 0 && (
<DeleteButton
id={ITEMS_TABLE_DELETE_SELECTED_ITEMS_ID}
Expand Down
1 change: 1 addition & 0 deletions src/config/selectors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const parseStringForId = (string) => string.replaceAll('+', '');

export const ITEM_DELETE_BUTTON_CLASS = 'itemDeleteButton';
export const ITEM_COPY_BUTTON_CLASS = 'itemCopyButton';
export const CONFIRM_DELETE_BUTTON_ID = 'confirmDeleteButton';
export const buildItemCard = (id) => `itemCard-${id}`;
export const CREATE_ITEM_BUTTON_ID = 'createItemButton';
Expand Down

0 comments on commit 38b9d5e

Please sign in to comment.