mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-01 01:18:10 +02:00
fix: show side bar and disable drag and add strategy based on permissions (#426)
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
This commit is contained in:
parent
95221e7b6b
commit
a9d46d4ce6
@ -3,23 +3,13 @@ import FeatureStrategiesList from './FeatureStrategiesList/FeatureStrategiesList
|
|||||||
import { useStyles } from './FeatureStrategies.styles';
|
import { useStyles } from './FeatureStrategies.styles';
|
||||||
import FeatureStrategiesUIProvider from './FeatureStrategiesUIProvider';
|
import FeatureStrategiesUIProvider from './FeatureStrategiesUIProvider';
|
||||||
import FeatureStrategiesEnvironments from './FeatureStrategiesEnvironments/FeatureStrategiesEnvironments';
|
import FeatureStrategiesEnvironments from './FeatureStrategiesEnvironments/FeatureStrategiesEnvironments';
|
||||||
import ConditionallyRender from '../../../common/ConditionallyRender';
|
|
||||||
import { UPDATE_FEATURE } from '../../../AccessProvider/permissions';
|
|
||||||
import { useContext } from 'react';
|
|
||||||
import AccessContext from '../../../../contexts/AccessContext';
|
|
||||||
|
|
||||||
const FeatureStrategies = () => {
|
const FeatureStrategies = () => {
|
||||||
const { hasAccess } = useContext(AccessContext);
|
|
||||||
|
|
||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
return (
|
return (
|
||||||
<Paper className={styles.container}>
|
<Paper className={styles.container}>
|
||||||
<FeatureStrategiesUIProvider>
|
<FeatureStrategiesUIProvider>
|
||||||
<ConditionallyRender
|
<FeatureStrategiesList />
|
||||||
condition={hasAccess(UPDATE_FEATURE)}
|
|
||||||
show={<FeatureStrategiesList />}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FeatureStrategiesEnvironments />
|
<FeatureStrategiesEnvironments />
|
||||||
</FeatureStrategiesUIProvider>
|
</FeatureStrategiesUIProvider>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
@ -25,11 +25,13 @@ export const useStyles = makeStyles(theme => ({
|
|||||||
width: '15%',
|
width: '15%',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
iconButton: {
|
iconButtonWrapper: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: '300px',
|
top: '300px',
|
||||||
right: '-25px',
|
right: '-25px',
|
||||||
backgroundColor: theme.palette.grey[300],
|
},
|
||||||
|
iconButton: {
|
||||||
|
backgroundColor: `${theme.palette.grey[300]}!important`,
|
||||||
[theme.breakpoints.down(700)]: {
|
[theme.breakpoints.down(700)]: {
|
||||||
right: '-10px',
|
right: '-10px',
|
||||||
},
|
},
|
||||||
|
@ -5,15 +5,20 @@ import { useStyles } from './FeatureStrategiesList.styles';
|
|||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import FeatureStrategiesUIContext from '../../../../../contexts/FeatureStrategiesUIContext';
|
import FeatureStrategiesUIContext from '../../../../../contexts/FeatureStrategiesUIContext';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import { Button, IconButton, useMediaQuery } from '@material-ui/core';
|
import { Button, IconButton, Tooltip, useMediaQuery } from '@material-ui/core';
|
||||||
import { DoubleArrow } from '@material-ui/icons';
|
import { DoubleArrow } from '@material-ui/icons';
|
||||||
import ConditionallyRender from '../../../../common/ConditionallyRender';
|
import ConditionallyRender from '../../../../common/ConditionallyRender';
|
||||||
|
import { UPDATE_FEATURE } from '../../../../AccessProvider/permissions';
|
||||||
|
import AccessContext from '../../../../../contexts/AccessContext';
|
||||||
|
|
||||||
|
|
||||||
const FeatureStrategiesList = () => {
|
const FeatureStrategiesList = () => {
|
||||||
const smallScreen = useMediaQuery('(max-width:700px)');
|
const smallScreen = useMediaQuery('(max-width:700px)');
|
||||||
const { expandedSidebar, setExpandedSidebar } = useContext(
|
const { expandedSidebar, setExpandedSidebar } = useContext(
|
||||||
FeatureStrategiesUIContext
|
FeatureStrategiesUIContext
|
||||||
);
|
);
|
||||||
|
const { hasAccess } = useContext(AccessContext);
|
||||||
|
|
||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
|
|
||||||
const { strategies } = useStrategies();
|
const { strategies } = useStrategies();
|
||||||
@ -60,9 +65,17 @@ const FeatureStrategiesList = () => {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<IconButton className={styles.iconButton} onClick={toggleSidebar}>
|
<Tooltip title={hasAccess(UPDATE_FEATURE) ? 'Click to open.' : 'You don\'t have access to perform this operation'} arrow>
|
||||||
|
<span className={styles.iconButtonWrapper}>
|
||||||
|
<IconButton
|
||||||
|
className={styles.iconButton}
|
||||||
|
onClick={toggleSidebar}
|
||||||
|
disabled={!hasAccess(UPDATE_FEATURE)}
|
||||||
|
>
|
||||||
<DoubleArrow className={iconClasses} />
|
<DoubleArrow className={iconClasses} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
</span>
|
||||||
|
</Tooltip>
|
||||||
{renderStrategies()}
|
{renderStrategies()}
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
@ -4,6 +4,7 @@ import classNames from 'classnames';
|
|||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import { useDrag } from 'react-dnd';
|
import { useDrag } from 'react-dnd';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
|
import AccessContext from '../../../../../../contexts/AccessContext';
|
||||||
import FeatureStrategiesUIContext from '../../../../../../contexts/FeatureStrategiesUIContext';
|
import FeatureStrategiesUIContext from '../../../../../../contexts/FeatureStrategiesUIContext';
|
||||||
import useStrategies from '../../../../../../hooks/api/getters/useStrategies/useStrategies';
|
import useStrategies from '../../../../../../hooks/api/getters/useStrategies/useStrategies';
|
||||||
import { IFeatureViewParams } from '../../../../../../interfaces/params';
|
import { IFeatureViewParams } from '../../../../../../interfaces/params';
|
||||||
@ -13,6 +14,7 @@ import {
|
|||||||
getFeatureStrategyIcon,
|
getFeatureStrategyIcon,
|
||||||
getHumanReadbleStrategyName,
|
getHumanReadbleStrategyName,
|
||||||
} from '../../../../../../utils/strategy-names';
|
} from '../../../../../../utils/strategy-names';
|
||||||
|
import { UPDATE_FEATURE } from '../../../../../AccessProvider/permissions';
|
||||||
import ConditionallyRender from '../../../../../common/ConditionallyRender';
|
import ConditionallyRender from '../../../../../common/ConditionallyRender';
|
||||||
import { useStyles } from './FeatureStrategyCard.styles';
|
import { useStyles } from './FeatureStrategyCard.styles';
|
||||||
|
|
||||||
@ -37,6 +39,8 @@ const FeatureStrategyCard = ({
|
|||||||
const { setConfigureNewStrategy, setExpandedSidebar } = useContext(
|
const { setConfigureNewStrategy, setExpandedSidebar } = useContext(
|
||||||
FeatureStrategiesUIContext
|
FeatureStrategiesUIContext
|
||||||
);
|
);
|
||||||
|
const { hasAccess } = useContext(AccessContext);
|
||||||
|
const canUpdateFeature = hasAccess(UPDATE_FEATURE)
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
const strategy = getStrategyObject(strategies, name, featureId);
|
const strategy = getStrategyObject(strategies, name, featureId);
|
||||||
@ -50,6 +54,7 @@ const FeatureStrategyCard = ({
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const [_, drag] = useDrag({
|
const [_, drag] = useDrag({
|
||||||
type: FEATURE_STRATEGIES_DRAG_TYPE,
|
type: FEATURE_STRATEGIES_DRAG_TYPE,
|
||||||
|
canDrag: canUpdateFeature,
|
||||||
item: () => {
|
item: () => {
|
||||||
return { name };
|
return { name };
|
||||||
},
|
},
|
||||||
@ -78,9 +83,8 @@ const FeatureStrategyCard = ({
|
|||||||
<IconButton
|
<IconButton
|
||||||
className={styles.addButton}
|
className={styles.addButton}
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
data-test={`${ADD_NEW_STRATEGY_CARD_BUTTON_ID}-${
|
data-test={`${ADD_NEW_STRATEGY_CARD_BUTTON_ID}-${index + 1}`}
|
||||||
index + 1
|
disabled={!canUpdateFeature}
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<Add />
|
<Add />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
Loading…
Reference in New Issue
Block a user