Skip to content

Commit

Permalink
Extends error alert
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 committed Nov 2, 2023
1 parent 7bb73dd commit c439e72
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 34 deletions.
14 changes: 6 additions & 8 deletions src/components/AddVariable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,15 @@ export const AddVariable = ({
}, [varValue]);

return (
<NewVariable>
<NewVariable>
{
icon ?
<Button variant='white' icon={icon} action={openModal}>
Update
</Button>
:
<Button variant='white' icon={icon} action={openModal}>
Update
</Button>
:
<ButtonBootstrap onClick={openModal}>
{
noVars || !updateName ? "Add" : "Update"
}
Add
</ButtonBootstrap>
}
<Modal
Expand Down
5 changes: 4 additions & 1 deletion src/components/DeleteVariable/StyledDeleteVariable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ export const DeleteVariableModal = styled.div`
`;

export const DeleteVariableButton = styled.div`
button.btn-red:not(.icon) {
padding: 8px 26px;
}
button.icon {
padding: 0 10px;
display: flex !important;
}
`;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export const StyledEnvironmentVariableDetails = styled.div`
.header-buttons {
display: flex;
margin: 0 4px;
.add-variable {
width: 54px;
height: 38px;
}
button {
margin-right: 4px;
Expand Down Expand Up @@ -572,4 +577,4 @@ export const StyledProjectVariableTable = styled.div`
display: none;
transition: unset;
}
`;
`;
72 changes: 48 additions & 24 deletions src/components/EnvironmentVariables/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ 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'
import ButtonComp from 'components/Button'
import {DeleteVariableButton} from "../DeleteVariable/StyledDeleteVariable";
import {LoadingOutlined} from "@ant-design/icons";

/**
* Displays the environment variable information.
Expand Down Expand Up @@ -48,6 +51,7 @@ const EnvironmentVariables = ({ environment, onVariableAdded }) => {
const [updateVarScope, setUpdateVarScope ] = useState('');
const [environmentErrorAlert, setEnvironmentErrorAlert] = useState(false);
const [projectErrorAlert, setProjectErrorAlert] = useState(false);
const [action, setAction] = useState('');

const closeEnvironmentError = () => {
setEnvironmentErrorAlert(false);
Expand All @@ -63,7 +67,8 @@ const EnvironmentVariables = ({ environment, onVariableAdded }) => {
] = useLazyQuery(EnvironmentByProjectNameWithEnvVarsValueQuery, {
variables: { openshiftProjectName: environment.openshiftProjectName },
onError: () => {
setOpenEnvVars(!openEnvVars);
setOpenEnvVars(false);
setValueState(initValueState);
setEnvironmentErrorAlert(true);
}
});
Expand Down Expand Up @@ -116,6 +121,7 @@ const EnvironmentVariables = ({ environment, onVariableAdded }) => {
getEnvVarValues();
setOpenEnvVars(!openEnvVars);
setValueState(initValueState);
setAction("view")
};

const showPrjVarValue = () => {
Expand All @@ -126,8 +132,15 @@ const EnvironmentVariables = ({ environment, onVariableAdded }) => {

const setUpdateValue = (rowValue, rowName, rowScope) => {
setUpdateVarValue(rowValue);
setUpdateVarName(rowName)
setUpdateVarScope(rowScope)
setUpdateVarName(rowName);
setUpdateVarScope(rowScope);
}

const permissionCheck = (action, index) => {
setOpenEnvVars(false);
setAction(action);
valuesShow(index);
getEnvVarValues();
}

return (
Expand All @@ -153,28 +166,30 @@ const EnvironmentVariables = ({ environment, onVariableAdded }) => {
<>
{
environmentErrorAlert && (
<Alert
<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."
message={`You don't have permission to ${action} environment ${action === "view" ? " variable values" : "variables"}. Contact your administrator to obtain the relevant permissions.`}
/>
)
}
}
<div className="header">
<label>Environment Variables</label>
<div className="header-buttons">
<Button
onClick={() => setOpenEnvVars(false)}
style={{ all: "unset" }}
onClick={() => permissionCheck("add")}
style={{ all: "unset" }}
>
<AddVariable
varProject={environment.project.name}
varEnvironment={environment.name}
varValues={displayVars}
varTarget="Environment"
refresh={onVariableAdded}
/>
{envLoading && action === "add" ? <Button className="add-variable"><LoadingOutlined/></Button> :
<AddVariable
varProject={environment.project.name}
varEnvironment={environment.name}
varValues={displayVars}
varTarget="Environment"
refresh={onVariableAdded}
/>
}
</Button>
<Button
onClick={() => showVarValue()}
Expand Down Expand Up @@ -315,14 +330,23 @@ const EnvironmentVariables = ({ environment, onVariableAdded }) => {
</div>
</Collapse>
<div className="varDelete">
<DeleteVariable
deleteType="Environment variable"
deleteName={envVar.name}
varProject={environment.project.name}
varEnvironment={environment.name}
icon="bin"
refresh={onVariableAdded}
/>
<Button
onClick={() => permissionCheck("delete", index)}
style={{ all: "unset" }}
>
{envLoading ? <DeleteVariableButton><ButtonComp index={index} variant='red' icon={!valueState[index] ? 'bin': ''} className="delete-btn">
{valueState[index] ? <LoadingOutlined/> : "Delete"}</ButtonComp>
</DeleteVariableButton>:
<DeleteVariable
deleteType="Environment variable"
deleteName={envVar.name}
varProject={environment.project.name}
varEnvironment={environment.name}
icon="bin"
refresh={onVariableAdded}
/>
}
</Button>
</div>
</VariableActions>
</div>
Expand Down Expand Up @@ -359,7 +383,7 @@ const EnvironmentVariables = ({ environment, onVariableAdded }) => {
<hr style={{ margin: "30px 0" }} />
{
projectErrorAlert && (
<Alert
<Alert
type="error"
closeAlert={closeProjectError}
header="Unauthorized:"
Expand Down

0 comments on commit c439e72

Please sign in to comment.