1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

Merge pull request #495 from Unleash/fix/revive-archived-feature

Fix/revive archived feature
This commit is contained in:
Youssef Khedher 2021-11-08 15:19:13 +01:00 committed by GitHub
commit df170e6b1f
4 changed files with 42 additions and 17 deletions

View File

@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import classnames from 'classnames'; import classnames from 'classnames';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { Chip, IconButton, ListItem, Tooltip } from '@material-ui/core'; import { Chip, ListItem, Tooltip } from '@material-ui/core';
import { Undo } from '@material-ui/icons'; import { Undo } from '@material-ui/icons';
import TimeAgo from 'react-timeago'; import TimeAgo from 'react-timeago';
@ -17,6 +17,8 @@ import { useStyles } from './styles';
import { getTogglePath } from '../../../../utils/route-path-helpers'; import { getTogglePath } from '../../../../utils/route-path-helpers';
import FeatureStatus from '../../FeatureView2/FeatureStatus/FeatureStatus'; import FeatureStatus from '../../FeatureView2/FeatureStatus/FeatureStatus';
import FeatureType from '../../FeatureView2/FeatureType/FeatureType'; import FeatureType from '../../FeatureView2/FeatureType/FeatureType';
import useProjects from '../../../../hooks/api/getters/useProjects/useProjects';
import PermissionIconButton from '../../../common/PermissionIconButton/PermissionIconButton';
const FeatureToggleListItem = ({ const FeatureToggleListItem = ({
feature, feature,
@ -31,11 +33,25 @@ const FeatureToggleListItem = ({
}) => { }) => {
const styles = useStyles(); const styles = useStyles();
const { projects } = useProjects();
const isArchive = !!revive; const isArchive = !!revive;
const { name, description, type, stale, createdAt, project, lastSeenAt } = const { name, description, type, stale, createdAt, project, lastSeenAt } =
feature; feature;
const projectExists = () => {
let projectExist = projects.find(proj => proj.id === project);
if (projectExist) {
return true;
}
return false;
};
const reviveFeature = () => {
if (projectExists()) {
revive(feature.name);
}
};
return ( return (
<ListItem <ListItem
{...rest} {...rest}
@ -83,7 +99,7 @@ const FeatureToggleListItem = ({
<> <>
<Tooltip title={description}> <Tooltip title={description}>
<span className={commonStyles.toggleName}> <span className={commonStyles.toggleName}>
{name}&nbsp; z{' '} {name}&nbsp;{' '}
</span> </span>
</Tooltip> </Tooltip>
<span className={styles.listItemToggle}></span> <span className={styles.listItemToggle}></span>
@ -109,12 +125,15 @@ const FeatureToggleListItem = ({
<Link <Link
to={`/projects/${project}`} to={`/projects/${project}`}
style={{ textDecoration: 'none' }} style={{ textDecoration: 'none' }}
className={classnames({
[`${styles.disabledLink}`]: !projectExists(),
})}
> >
<Chip <Chip
color="primary" color="primary"
variant="outlined" variant="outlined"
className={styles.typeChip} className={styles.typeChip}
style={{ marginLeft: '8px' }} style={{ marginLeft: '8px', cursor: 'pointer' }}
title={`Project: ${project}`} title={`Project: ${project}`}
label={project} label={project}
/> />
@ -123,15 +142,14 @@ const FeatureToggleListItem = ({
<ConditionallyRender <ConditionallyRender
condition={revive} condition={revive}
show={ show={
<ConditionallyRender <PermissionIconButton
condition={hasAccess(UPDATE_FEATURE, project)} permission={UPDATE_FEATURE}
show={ projectId={project}
<IconButton onClick={() => revive(feature.name)}> disabled={!projectExists()}
<Undo /> onClick={reviveFeature}
</IconButton> >
} <Undo />
elseShow={<span style={{ width: '48px ' }} />} </PermissionIconButton>
/>
} }
/> />
</ListItem> </ListItem>

View File

@ -29,4 +29,7 @@ export const useStyles = makeStyles(theme => ({
listItemStrategies: { listItemStrategies: {
marginLeft: 'auto', marginLeft: 'auto',
}, },
disabledLink:{
pointerEvents: 'none'
},
})); }));

View File

@ -10,7 +10,7 @@ exports[`renders correctly with one feature 1`] = `
> >
<div <div
aria-describedby={null} aria-describedby={null}
className="makeStyles-container-7" className="makeStyles-container-8"
onBlur={[Function]} onBlur={[Function]}
onFocus={[Function]} onFocus={[Function]}
onMouseLeave={[Function]} onMouseLeave={[Function]}
@ -42,7 +42,7 @@ exports[`renders correctly with one feature 1`] = `
<svg <svg
aria-describedby={null} aria-describedby={null}
aria-hidden={true} aria-hidden={true}
className="MuiSvgIcon-root makeStyles-icon-8" className="MuiSvgIcon-root makeStyles-icon-9"
data-loading={true} data-loading={true}
focusable="false" focusable="false"
onBlur={[Function]} onBlur={[Function]}
@ -105,6 +105,7 @@ exports[`renders correctly with one feature 1`] = `
className="makeStyles-listItemStrategies-6 hideLt920" className="makeStyles-listItemStrategies-6 hideLt920"
> >
<a <a
className="makeStyles-disabledLink-7"
href="/projects/default" href="/projects/default"
onClick={[Function]} onClick={[Function]}
style={ style={
@ -119,6 +120,7 @@ exports[`renders correctly with one feature 1`] = `
onKeyUp={[Function]} onKeyUp={[Function]}
style={ style={
Object { Object {
"cursor": "pointer",
"marginLeft": "8px", "marginLeft": "8px",
} }
} }
@ -145,7 +147,7 @@ exports[`renders correctly with one feature without permission 1`] = `
> >
<div <div
aria-describedby={null} aria-describedby={null}
className="makeStyles-container-7" className="makeStyles-container-8"
onBlur={[Function]} onBlur={[Function]}
onFocus={[Function]} onFocus={[Function]}
onMouseLeave={[Function]} onMouseLeave={[Function]}
@ -177,7 +179,7 @@ exports[`renders correctly with one feature without permission 1`] = `
<svg <svg
aria-describedby={null} aria-describedby={null}
aria-hidden={true} aria-hidden={true}
className="MuiSvgIcon-root makeStyles-icon-8" className="MuiSvgIcon-root makeStyles-icon-9"
data-loading={true} data-loading={true}
focusable="false" focusable="false"
onBlur={[Function]} onBlur={[Function]}
@ -240,6 +242,7 @@ exports[`renders correctly with one feature without permission 1`] = `
className="makeStyles-listItemStrategies-6 hideLt920" className="makeStyles-listItemStrategies-6 hideLt920"
> >
<a <a
className="makeStyles-disabledLink-7"
href="/projects/undefined" href="/projects/undefined"
onClick={[Function]} onClick={[Function]}
style={ style={
@ -254,6 +257,7 @@ exports[`renders correctly with one feature without permission 1`] = `
onKeyUp={[Function]} onKeyUp={[Function]}
style={ style={
Object { Object {
"cursor": "pointer",
"marginLeft": "8px", "marginLeft": "8px",
} }
} }

View File

@ -93,7 +93,7 @@ const ProjectFeatureToggles = ({
condition={hasAccess(CREATE_FEATURE, id)} condition={hasAccess(CREATE_FEATURE, id)}
show={ show={
<Link <Link
to={getCreateTogglePath(id)} to={getCreateTogglePath(id, uiConfig.flags.E)}
className={styles.link} className={styles.link}
data-loading data-loading
> >