1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00

fix: envrionments should give understandable error if not possible to… (#433)

This commit is contained in:
Ivar Conradi Østhus 2021-10-14 19:58:57 +02:00 committed by GitHub
parent bbf06725a3
commit 1058b4049c
9 changed files with 67 additions and 57 deletions

View File

@ -21,7 +21,7 @@ export const useStyles = makeStyles(theme => ({
paddingLeft: '10px', paddingLeft: '10px',
}, },
tableCellEnv: { tableCellEnv: {
width: '20px', width: '90px',
[theme.breakpoints.down('sm')]: { [theme.breakpoints.down('sm')]: {
display: 'none', display: 'none',
}, },
@ -33,4 +33,11 @@ export const useStyles = makeStyles(theme => ({
display: 'none', display: 'none',
}, },
}, },
envName: {
display: 'inline-block',
width: '90px',
textOverflow: 'ellipsis',
overflow: 'hidden',
whiteSpace: 'nowrap',
}
})); }));

View File

@ -120,10 +120,8 @@ const FeatureToggleListNew = ({
)} )}
align="center" align="center"
> >
<span data-loading> <span data-loading className={styles.envName} >
{env.name === ':global:' {env.name}
? 'Status'
: env.name}
</span> </span>
</TableCell> </TableCell>
); );

View File

@ -63,7 +63,7 @@ const FeatureToggleListNewItem = ({
setToastData({ setToastData({
show: true, show: true,
type: 'error', type: 'error',
text: e.toString(), text: e.message,
}); });
}); });
}; };

View File

@ -2,7 +2,6 @@ import { useHistory, useParams } from 'react-router';
import { useCommonStyles } from '../../../common.styles'; import { useCommonStyles } from '../../../common.styles';
import useProject from '../../../hooks/api/getters/useProject/useProject'; import useProject from '../../../hooks/api/getters/useProject/useProject';
import useLoading from '../../../hooks/useLoading'; import useLoading from '../../../hooks/useLoading';
import useUiConfig from '../../../hooks/api/getters/useUiConfig/useUiConfig';
import ApiError from '../../common/ApiError/ApiError'; import ApiError from '../../common/ApiError/ApiError';
import ConditionallyRender from '../../common/ConditionallyRender'; import ConditionallyRender from '../../common/ConditionallyRender';
import { useStyles } from './Project.styles'; import { useStyles } from './Project.styles';
@ -23,7 +22,6 @@ const Project = () => {
const { id, activeTab } = useParams<{ id: string, activeTab: string }>(); const { id, activeTab } = useParams<{ id: string, activeTab: string }>();
const params = useQueryParams(); const params = useQueryParams();
const { project, error, loading, refetch } = useProject(id); const { project, error, loading, refetch } = useProject(id);
const { uiConfig } = useUiConfig();
const ref = useLoading(loading); const ref = useLoading(loading);
const { toast, setToastData } = useToast(); const { toast, setToastData } = useToast();
const commonStyles = useCommonStyles(); const commonStyles = useCommonStyles();
@ -57,7 +55,6 @@ const Project = () => {
component: <ProjectEnvironment projectId={id} />, component: <ProjectEnvironment projectId={id} />,
path: `${basePath}/environments`, path: `${basePath}/environments`,
name: 'environments', name: 'environments',
disabled: !uiConfig.flags.E
}, },
{ {
title: 'Settings', title: 'Settings',

View File

@ -138,10 +138,6 @@ const ProjectEnvironmentList = ({ projectId }: ProjectEnvironmentListProps) => {
); );
const renderEnvironments = () => { const renderEnvironments = () => {
if (!uiConfig.flags.E) {
return <p>Feature not enabled.</p>;
}
return ( return (
<FormGroup> <FormGroup>
{envs.map(env => ( {envs.map(env => (
@ -167,45 +163,53 @@ const ProjectEnvironmentList = ({ projectId }: ProjectEnvironmentListProps) => {
<PageContent <PageContent
headerContent={ headerContent={
<HeaderTitle <HeaderTitle
title={`Configure environments for "${project?.name}"`} title={`Configure environments for "${project?.name}" project`}
/>} />}
> >
<Alert severity="info"> <ConditionallyRender condition={uiConfig.flags.E} show={
<b>Important!</b> In order for your application to retrieve feature toggle activation strategies for a specific environment, the application<br/> must use an environment-specific API key. You can look up the environment-specific API keys {' '} <div className={styles.container}>
<Link <ConditionallyRender condition={error} show={renderError()} />
to='/admin/api' <Alert severity="info" style={{marginBottom: '20px'}}>
> <b>Important!</b> In order for your application to retrieve configured activation strategies for a specific environment,
here. the application<br/> must use an environment specific API key. You can look up the environment-specific API keys {' '}
</Link>{' '} <Link
<br/> to='/admin/api'
<br/> >
Your administrator can configure an environment-specific API key and add it to your SDK if you can't find it on the list. here.
If you are an administrator you can create a new API key {' '} </Link>
<Link <br/>
to='/admin/api' <br/>
> Your administrator can configure an environment-specific API key to be used in the SDK.
here. If you are an administrator you can {' '}
</Link>{' '} <Link
to='/admin/api'
>
create a new API key.
</Link>
</Alert>
<ConditionallyRender
condition={environments.length < 1 && !loading}
show={<div>No environments available.</div>}
elseShow={renderEnvironments()}
/>
<EnvironmentDisableConfirm
env={selectedEnv}
open={!!selectedEnv}
handleDisableEnvironment={handleDisableEnvironment}
handleCancelDisableEnvironment={
handleCancelDisableEnvironment
}
confirmName={confirmName}
setConfirmName={setConfirmName}
/>
</div>
} elseShow={
<Alert security="success">
This feature has not been Unleashed for you yet.
</Alert> </Alert>
<br/> } />
<ConditionallyRender condition={error} show={renderError()} />
<div className={styles.container}>
<ConditionallyRender
condition={environments.length < 1 && !loading}
show={<div>No environments available.</div>}
elseShow={renderEnvironments()}
/>
</div>
<EnvironmentDisableConfirm
env={selectedEnv}
open={!!selectedEnv}
handleDisableEnvironment={handleDisableEnvironment}
handleCancelDisableEnvironment={
handleCancelDisableEnvironment
}
confirmName={confirmName}
setConfirmName={setConfirmName}
/>
{toast} {toast}
</PageContent> </PageContent>
</div> </div>

View File

@ -107,16 +107,16 @@ const ProjectFormComponent = (props: ProjectFormComponentProps) => {
<PageContent <PageContent
headerContent={ headerContent={
<HeaderTitle <HeaderTitle
title={`${submitText} Project`} title={`${submitText} ${project?.name} project`}
/> />
} }
> >
<ConditionallyRender condition={isOss()} show={ <ConditionallyRender condition={isOss()} show={
<Alert data-loading severity="error"> <Alert data-loading severity="error">
Creating and updating projects requires a paid version of Unleash. {submitText} project requires a paid version of Unleash.
Check out <a href="https://www.getunleash.io" target="_blank" rel="noreferrer">getunleash.io</a> Check out <a href="https://www.getunleash.io" target="_blank" rel="noreferrer">getunleash.io</a>{' '}
to find out more. to learn more.
</Alert> </Alert>
} elseShow={ } elseShow={
<> <>

View File

@ -66,9 +66,11 @@ export const handleForbidden = async (
if (res) { if (res) {
const data = await res.json(); const data = await res.json();
const message = data.isJoi ? data.details[0].message : data[0].msg;
setErrors(prev => ({ setErrors(prev => ({
...prev, ...prev,
[requestId]: data[0].msg, [requestId]: message,
})); }));
} }

View File

@ -153,12 +153,14 @@ const useAPI = ({
} }
if (propagateErrors) { if (propagateErrors) {
throw new ForbiddenError(res.status); const response = await res.json();
throw new ForbiddenError(res.status, response);
} }
} }
if (res.status > 399) { if (res.status > 399) {
const response = await res.json(); const response = await res.json();
if (response?.details?.length > 0) { if (response?.details?.length > 0) {
const error = response.details[0]; const error = response.details[0];
if (propagateErrors) { if (propagateErrors) {

View File

@ -27,8 +27,8 @@ export class AuthenticationError extends Error {
} }
export class ForbiddenError extends Error { export class ForbiddenError extends Error {
constructor(statusCode, body) { constructor(statusCode, body = {}) {
super('You cannot perform this action'); super(body.details?.length > 0 ? body.details[0].message : 'You cannot perform this action');
this.name = 'ForbiddenError'; this.name = 'ForbiddenError';
this.statusCode = statusCode; this.statusCode = statusCode;
this.body = body; this.body = body;