mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-01 01:18:10 +02:00
feat: update dialog to accept permissions (#627)
* feat: update dialog to accept permissions * refactor: make dialog component accept permission button * fix: remove unused dependencies * fix: update button permissions Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
This commit is contained in:
parent
bbde9f00ec
commit
be3a26529a
@ -23,6 +23,7 @@ interface IDialogue {
|
||||
maxWidth?: 'lg' | 'sm' | 'xs' | 'md' | 'xl';
|
||||
disabledPrimaryButton?: boolean;
|
||||
formId?: string;
|
||||
permissionButton?: React.ReactNode;
|
||||
}
|
||||
|
||||
const Dialogue: React.FC<IDialogue> = ({
|
||||
@ -37,6 +38,7 @@ const Dialogue: React.FC<IDialogue> = ({
|
||||
maxWidth = 'sm',
|
||||
fullWidth = false,
|
||||
formId,
|
||||
permissionButton,
|
||||
}) => {
|
||||
const styles = useStyles();
|
||||
const handleClick = formId
|
||||
@ -66,20 +68,26 @@ const Dialogue: React.FC<IDialogue> = ({
|
||||
|
||||
<DialogActions>
|
||||
<ConditionallyRender
|
||||
condition={Boolean(onClick)}
|
||||
show={
|
||||
<Button
|
||||
form={formId}
|
||||
color="primary"
|
||||
variant="contained"
|
||||
onClick={handleClick}
|
||||
autoFocus={!formId}
|
||||
disabled={disabledPrimaryButton}
|
||||
data-test={DIALOGUE_CONFIRM_ID}
|
||||
type={formId ? 'submit' : 'button'}
|
||||
>
|
||||
{primaryButtonText || "Yes, I'm sure"}
|
||||
</Button>
|
||||
condition={Boolean(permissionButton)}
|
||||
show={permissionButton}
|
||||
elseShow={
|
||||
<ConditionallyRender
|
||||
condition={Boolean(onClick)}
|
||||
show={
|
||||
<Button
|
||||
form={formId}
|
||||
color="primary"
|
||||
variant="contained"
|
||||
onClick={handleClick}
|
||||
autoFocus={!formId}
|
||||
disabled={disabledPrimaryButton}
|
||||
data-test={DIALOGUE_CONFIRM_ID}
|
||||
type={formId ? 'submit' : 'button'}
|
||||
>
|
||||
{primaryButtonText || "Yes, I'm sure"}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { CREATE_FEATURE_STRATEGY } from '../../providers/AccessProvider/permissions';
|
||||
import Dialogue from '../Dialogue';
|
||||
import PermissionButton from '../PermissionButton/PermissionButton';
|
||||
import { useStyles } from './EnvironmentStrategyDialog.styles';
|
||||
|
||||
interface IEnvironmentStrategyDialogProps {
|
||||
@ -25,10 +26,19 @@ const EnvironmentStrategyDialog = ({
|
||||
<Dialogue
|
||||
open={open}
|
||||
maxWidth="sm"
|
||||
onClick={() => history.push(strategiesLink)}
|
||||
onClose={() => onClose()}
|
||||
title="You need to add a strategy to your toggle"
|
||||
primaryButtonText="Take me directly to add strategy"
|
||||
permissionButton={
|
||||
<PermissionButton
|
||||
permission={CREATE_FEATURE_STRATEGY}
|
||||
projectId={projectId}
|
||||
environmentId={environmentName}
|
||||
onClick={() => history.push(strategiesLink)}
|
||||
>
|
||||
Take me directly to add strategy
|
||||
</PermissionButton>
|
||||
}
|
||||
secondaryButtonText="Cancel"
|
||||
>
|
||||
<p className={styles.infoText}>
|
||||
@ -36,8 +46,8 @@ const EnvironmentStrategyDialog = ({
|
||||
add an activation strategy.
|
||||
</p>
|
||||
<p className={styles.infoText}>
|
||||
You can add the activation strategy by selecting the toggle, open
|
||||
the environment accordion and add the activation strategy.
|
||||
You can add the activation strategy by selecting the toggle,
|
||||
open the environment accordion and add the activation strategy.
|
||||
</p>
|
||||
</Dialogue>
|
||||
);
|
||||
|
@ -4,7 +4,7 @@ import { useContext } from 'react';
|
||||
import AccessContext from '../../../contexts/AccessContext';
|
||||
import ConditionallyRender from '../ConditionallyRender';
|
||||
|
||||
interface IPermissionIconButtonProps
|
||||
export interface IPermissionIconButtonProps
|
||||
extends React.HTMLProps<HTMLButtonElement> {
|
||||
permission: string | string[];
|
||||
tooltip?: string;
|
||||
|
@ -8,7 +8,7 @@ import {
|
||||
getHumanReadableStrategyName,
|
||||
} from '../../../../../../../../utils/strategy-names';
|
||||
import PermissionIconButton from '../../../../../../../common/PermissionIconButton/PermissionIconButton';
|
||||
import { UPDATE_FEATURE } from '../../../../../../../providers/AccessProvider/permissions';
|
||||
import { UPDATE_FEATURE_STRATEGY } from '../../../../../../../providers/AccessProvider/permissions';
|
||||
import FeatureStrategyExecution from '../../../../../FeatureStrategies/FeatureStrategyExecution/FeatureStrategyExecution';
|
||||
import { useStyles } from './FeatureOverviewEnvironmentStrategy.styles';
|
||||
|
||||
@ -36,7 +36,8 @@ const FeatureOverviewEnvironmentStrategy = ({
|
||||
{getHumanReadableStrategyName(strategy.name)}
|
||||
<div className={styles.editStrategy}>
|
||||
<PermissionIconButton
|
||||
permission={UPDATE_FEATURE}
|
||||
permission={UPDATE_FEATURE_STRATEGY}
|
||||
environmentId={environmentName}
|
||||
projectId={projectId}
|
||||
component={Link}
|
||||
to={`/projects/${projectId}/features2/${featureId}/strategies?environment=${environmentName}`}
|
||||
|
Loading…
Reference in New Issue
Block a user