import React, { useRef, useEffect, useCallback } from 'react'; import { UncontrolledPopover } from 'reactstrap'; import PropTypes from 'prop-types'; import Icon from '../../../../../components/icon'; import { gettext } from '../../../../../utils/constants'; import { VIEW_TYPE, VIEW_TYPE_ICON } from '../../../../constants'; import '../index.css'; const VIEW_OPTIONS = [ { key: 'table', type: VIEW_TYPE.TABLE, }, { key: 'gallery', type: VIEW_TYPE.GALLERY, }, { key: 'kanban', type: VIEW_TYPE.KANBAN, }, { key: 'map', type: VIEW_TYPE.MAP, } ]; const AddView = ({ target, toggle, onOptionClick }) => { const popoverRef = useRef(null); const handleClickOutside = useCallback((event) => { if (popoverRef.current && !popoverRef.current.contains(event.target)) { toggle(event); } }, [toggle]); useEffect(() => { if (popoverRef.current) { document.addEventListener('click', handleClickOutside, true); } return () => { document.removeEventListener('click', handleClickOutside, true); }; }, [handleClickOutside]); const translateLabel = useCallback((type) => { switch (type) { case VIEW_TYPE.TABLE: return gettext('Table'); case VIEW_TYPE.GALLERY: return gettext('Gallery'); case VIEW_TYPE.KANBAN: return gettext('Kanban'); case VIEW_TYPE.MAP: return gettext('Map'); default: return type; } }, []); return (
{gettext('New view')}
{VIEW_OPTIONS.map((item, index) => { return ( ); })}
); }; AddView.propTypes = { target: PropTypes.string.isRequired, toggle: PropTypes.func.isRequired, onOptionClick: PropTypes.func.isRequired, }; export default AddView;