import { useContext, useLayoutEffect } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { Link } from 'react-router-dom'; import { Button, List, Tooltip, IconButton, ListItem } from '@material-ui/core'; import useMediaQuery from '@material-ui/core/useMediaQuery'; import { Add } from '@material-ui/icons'; import FeatureToggleListItem from './FeatureToggleListItem'; import SearchField from '../../common/SearchField/SearchField'; import FeatureToggleListActions from './FeatureToggleListActions'; import ConditionallyRender from '../../common/ConditionallyRender/ConditionallyRender'; import PageContent from '../../common/PageContent/PageContent'; import HeaderTitle from '../../common/HeaderTitle'; import loadingFeatures from './loadingFeatures'; import { CREATE_FEATURE } from '../../AccessProvider/permissions'; import AccessContext from '../../../contexts/AccessContext'; import { useStyles } from './styles'; import ListPlaceholder from '../../common/ListPlaceholder/ListPlaceholder'; import { getCreateTogglePath } from '../../../utils/route-path-helpers'; const FeatureToggleList = ({ fetcher, features, settings, revive, currentProjectId, updateSetting, featureMetrics, toggleFeature, archive, loading, }) => { const { hasAccess } = useContext(AccessContext); const styles = useStyles(); const smallScreen = useMediaQuery('(max-width:800px)'); const mobileView = useMediaQuery('(max-width:600px)'); useLayoutEffect(() => { fetcher(); }, [fetcher]); const toggleMetrics = () => { updateSetting('showLastHour', !settings.showLastHour); }; const setSort = v => { updateSetting('sort', typeof v === 'string' ? v.trim() : ''); }; const createURL = getCreateTogglePath(currentProjectId); const renderFeatures = () => { features.forEach(e => { e.reviveName = e.name; }); if (loading) { return loadingFeatures.map(feature => ( )); } return ( 0} show={features.map(feature => ( ))} elseShow={ No archived features. } elseShow={ } /> } /> ); }; const headerTitle = archive ? 'Archived Features' : 'Features'; return (
Archive} />
} /> } elseShow={ } /> } />
} /> } > {renderFeatures()} ); }; FeatureToggleList.propTypes = { features: PropTypes.array.isRequired, featureMetrics: PropTypes.object.isRequired, fetcher: PropTypes.func, revive: PropTypes.func, updateSetting: PropTypes.func.isRequired, toggleFeature: PropTypes.func, settings: PropTypes.object, history: PropTypes.object.isRequired, loading: PropTypes.bool, currentProjectId: PropTypes.string.isRequired, }; export default FeatureToggleList;