Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds error alert for Variables tabs #165

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/components/Alert/StyledAlert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import styled, { css } from 'styled-components';
import { color } from "lib/variables";

const sharedStyles = css`
position: relative;
padding: 1rem;
margin-bottom: 2rem;
border-radius: 0.25rem;
display: flex;
justify-content: space-between;
`;

export const StyledAlert = styled.div`
border-radius: 0.25rem;
&.error {
color: ${color.white};
background-color: #d68100;

.anticon-close-circle {
margin-right: 4px;
vertical-align: text-top;
}
}

.closebtn {
margin: 4px 8px 0 0;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
cursor: pointer;

&.closebtn:hover {
color: black;
}
}

`;

export const StyledAlertContent = styled.div`
${sharedStyles}
`;
29 changes: 29 additions & 0 deletions src/components/Alert/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react";
import {StyledAlert, StyledAlertContent} from './StyledAlert';

export const Alert = ({
type, header, message, closeAlert
}) => {
const createClassName = () => {
let className = `${type ? `${type} alert-element` : 'alert-element'}`;
return className;
};

const AlertElement =
<StyledAlert className={createClassName()}>
<span className="closebtn" onClick={() => closeAlert()}>
&times;
</span>
<StyledAlertContent>
<span>
<b>{header}</b> {message}
</span>
</StyledAlertContent>
</StyledAlert>



return <>{AlertElement}</>;
}

export default Alert;
10 changes: 10 additions & 0 deletions src/components/EnvironmentVariables/StyledEnvironmentVariables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ export const StyledEnvironmentVariableDetails = styled.div`
display: inline-block;
width: 36px;
height: 36px;

&.value-btn {
width: 90px;
height: 17px;
}
}
.loader:after {
content: " ";
Expand All @@ -134,6 +139,11 @@ export const StyledEnvironmentVariableDetails = styled.div`
border-color: ${color.blue} transparent ${color.blue} transparent;
animation: loader 1.2s linear infinite;
}
.loader.value-btn:after {
margin: 0 auto;
border: 2px solid ${color.white};
border-color: ${color.white} transparent ${color.white} transparent;
}
@keyframes loader {
0% {
transform: rotate(0deg);
Expand Down
57 changes: 43 additions & 14 deletions src/components/EnvironmentVariables/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Image from "next/image";
import show from "../../static/images/show.svg";
import hide from "../../static/images/hide.svg";
import ProjectVariablesLink from "components/link/ProjectVariables";
import Alert from 'components/Alert'

/**
* Displays the environment variable information.
Expand All @@ -32,7 +33,7 @@ const hashValue = (value) => {
return hashedVal;
};

const EnvironmentVariables = ({ environment, onVariableAdded, closeModal }) => {
const EnvironmentVariables = ({ environment, onVariableAdded }) => {
let displayVars = environment.envVariables;
let displayProjectVars = environment.project.envVariables;
let initValueState = new Array(displayVars.length).fill(false);
Expand All @@ -45,12 +46,26 @@ const EnvironmentVariables = ({ environment, onVariableAdded, closeModal }) => {
const [updateVarValue, setUpdateVarValue ] = useState('');
const [updateVarName, setUpdateVarName ] = useState('');
const [updateVarScope, setUpdateVarScope ] = useState('');
const [environmentErrorAlert, setEnvironmentErrorAlert] = useState(false);
const [projectErrorAlert, setProjectErrorAlert] = useState(false);

const closeEnvironmentError = () => {
setEnvironmentErrorAlert(false);
};

const closeProjectError = () => {
setProjectErrorAlert(false);
};

const [
getEnvVarValues,
{ loading: envLoading, error: envError, data: envValues },
] = useLazyQuery(EnvironmentByProjectNameWithEnvVarsValueQuery, {
variables: { openshiftProjectName: environment.openshiftProjectName },
onError: () => {
setOpenEnvVars(!openEnvVars);
setEnvironmentErrorAlert(true);
}
});

if (envValues) {
Expand All @@ -64,6 +79,10 @@ const EnvironmentVariables = ({ environment, onVariableAdded, closeModal }) => {
{ loading: prjLoading, error: prjError, data: prjEnvValues },
] = useLazyQuery(EnvironmentProjectByProjectNameWithEnvVarsValueQuery, {
variables: { openshiftProjectName: environment.openshiftProjectName },
onError: () => {
setOpenPrjVars(!openPrjVars);
setProjectErrorAlert(true);
}
});

if (prjEnvValues) {
Expand Down Expand Up @@ -132,6 +151,16 @@ const EnvironmentVariables = ({ environment, onVariableAdded, closeModal }) => {
</>
) : (
<>
{
environmentErrorAlert && (
<Alert
type="error"
closeAlert={closeEnvironmentError}
header="Unauthorized:"
message="You don't have permission to view environment variable values. Contact your administrator to obtain the relevant permissions."
/>
)
}
<div className="header">
<label>Environment Variables</label>
<div className="header-buttons">
Expand All @@ -152,7 +181,7 @@ const EnvironmentVariables = ({ environment, onVariableAdded, closeModal }) => {
aria-controls="example-collapse-text"
aria-expanded={openEnvVars}
>
{!openEnvVars ? "Show values" : "Hide values"}
{ !openEnvVars ? "Show values" : "Hide values"}
</Button>
</div>
</div>
Expand Down Expand Up @@ -261,12 +290,7 @@ const EnvironmentVariables = ({ environment, onVariableAdded, closeModal }) => {
</div>
</Collapse>
) : (
<Collapse in={openEnvVars}>
<div className="varValue" id={index}>
Unauthorized: You don't have permission to view
this variable.
</div>
</Collapse>
''
)}
<div className="varActions">
<VariableActions>
Expand Down Expand Up @@ -333,6 +357,16 @@ const EnvironmentVariables = ({ environment, onVariableAdded, closeModal }) => {
) : (
<>
<hr style={{ margin: "30px 0" }} />
{
projectErrorAlert && (
<Alert
type="error"
closeAlert={closeProjectError}
header="Unauthorized:"
message="You don't have permission to view project variable values. Contact your administrator to obtain the relevant permissions."
/>
)
}
<div className="header">
<label>Project Variables</label>
<div className="header-buttons">
Expand Down Expand Up @@ -461,12 +495,7 @@ const EnvironmentVariables = ({ environment, onVariableAdded, closeModal }) => {
</div>
</Collapse>
) : (
<Collapse in={openPrjVars}>
<div className="varValue" id={index}>
Unauthorized: You don't have permission to view
this variable.
</div>
</Collapse>
''
)}
</div>
</Fragment>
Expand Down
10 changes: 10 additions & 0 deletions src/components/ProjectVariables/StyledProjectVariables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ export const StyledProjectVariablesDetails = styled.div`
display: inline-block;
width: 36px;
height: 36px;

&.value-btn {
width: 90px;
height: 17px;
}
}
.loader:after {
content: " ";
Expand All @@ -128,6 +133,11 @@ export const StyledProjectVariablesDetails = styled.div`
border-color: ${color.blue} transparent ${color.blue} transparent;
animation: loader 1.2s linear infinite;
}
.loader.value-btn:after {
margin: 0 auto;
border: 2px solid ${color.white};
border-color: ${color.white} transparent ${color.white} transparent;
}
@keyframes loader {
0% {
transform: rotate(0deg);
Expand Down
28 changes: 22 additions & 6 deletions src/components/ProjectVariables/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
VariableActions,
} from "./StyledProjectVariables";
import DeleteVariable from "components/DeleteVariable";
import Alert from 'components/Alert'

/**
* Displays the projects variable information.
Expand All @@ -38,12 +39,22 @@ const ProjectVariables = ({ project, onVariableAdded, closeModal }) => {
const [updateVarValue, setUpdateVarValue ] = useState('');
const [updateVarName, setUpdateVarName ] = useState('');
const [updateVarScope, setUpdateVarScope ] = useState('');
const [projectErrorAlert, setProjectErrorAlert] = useState(false);

const closeProjectError = () => {
setProjectErrorAlert(false);
};


const [
getPrjEnvVarValues,
{ loading: prjLoading, error: prjError, data: prjEnvValues },
] = useLazyQuery(ProjectByNameWithEnvVarsValueQuery, {
variables: { name: project.name },
onError: () => {
setOpenPrjVars(!openPrjVars);
setProjectErrorAlert(true);
}
});

if (prjEnvValues) {
Expand Down Expand Up @@ -96,6 +107,16 @@ const ProjectVariables = ({ project, onVariableAdded, closeModal }) => {
</>
) : (
<>
{
projectErrorAlert && (
<Alert
type="error"
closeAlert={closeProjectError}
header="Unauthorized:"
message="You don't have permission to view project variable values. Contact your administrator to obtain the relevant permissions."
/>
)
}
<div className="header">
<label>Project Variables</label>
<div className="header-buttons">
Expand Down Expand Up @@ -227,12 +248,7 @@ const ProjectVariables = ({ project, onVariableAdded, closeModal }) => {
</div>
</Collapse>
) : (
<Collapse in={openPrjVars}>
<div className="varValue" id={index}>
Unauthorized: You don't have permission to view
this variable.
</div>
</Collapse>
''
)}
<div className="varActions">
<VariableActions>
Expand Down