-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add env variables in start session form
- Loading branch information
1 parent
3e57242
commit d98c125
Showing
7 changed files
with
234 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
client/src/notebooks/components/EnviromentVariables.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/*! | ||
* Copyright 2022 - Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import React, { ChangeEvent } from "react"; | ||
import { Button, Col, FormGroup, Input, Label, Row } from "../../utils/ts-wrappers"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faTrash } from "@fortawesome/free-solid-svg-icons"; | ||
import { InputLabel } from "../../utils/components/formlabels/FormLabels"; | ||
|
||
interface EnvironmentVariablesProps { | ||
environmentVariables: EnvVariablesField[]; | ||
setEnvironmentVariables: Function; | ||
} | ||
|
||
export interface EnvVariablesField { | ||
key: string; | ||
value: string; | ||
} | ||
|
||
function EnvironmentVariables({ environmentVariables, setEnvironmentVariables }: EnvironmentVariablesProps) { | ||
const handleFormChange = (index: number, name: "key" | "value", value: string) => { | ||
let data: EnvVariablesField[] = [...environmentVariables]; | ||
data[index][name] = value; | ||
setEnvironmentVariables(data); | ||
}; | ||
|
||
const addFields = () => { | ||
let object = { key: "", value: "" }; | ||
setEnvironmentVariables([...environmentVariables, object]); | ||
}; | ||
|
||
const removeFields = (index: number) => { | ||
let data = [...environmentVariables]; | ||
data.splice(index, 1); | ||
setEnvironmentVariables(data); | ||
}; | ||
|
||
const content = environmentVariables?.map((input, index) => { | ||
return ( | ||
<Row key={index}> | ||
<Col xs={5}> | ||
<FormGroup className="field-group"> | ||
<Label for="variable" size="sm" className="text-muted d-md-none">Variable</Label> | ||
<Input | ||
name="variable" | ||
value={input.key} | ||
onChange={(event: ChangeEvent<HTMLInputElement>) => handleFormChange(index, "key", event.target.value)} | ||
/> | ||
</FormGroup> | ||
</Col> | ||
<Col xs={5}> | ||
<FormGroup className="field-group"> | ||
<Label for="variable" size="sm" className="text-muted d-md-none">Value</Label> | ||
<Input | ||
name="value" | ||
value={input.value} | ||
onChange={(event: ChangeEvent<HTMLInputElement>) => handleFormChange(index, "value", event.target.value)} | ||
/> | ||
</FormGroup> | ||
</Col> | ||
<Col xs={2} className="d-flex align-items-center justify-content-start"> | ||
<Button | ||
size="sm" | ||
className="border-0 text-danger bg-transparent mb-3" | ||
onClick={() => removeFields(index)}> | ||
<FontAwesomeIcon icon={faTrash} /> | ||
</Button> | ||
</Col> | ||
</Row> | ||
); | ||
}); | ||
|
||
const header = !environmentVariables?.length ? null : | ||
<Row className="my-2 d-none d-sm-none d-md-flex d-xl-flex"> | ||
<Col sm={5}> | ||
<Label className="small">Variable</Label> | ||
</Col> | ||
<Col sm={5}> | ||
<Label className="small">Value</Label> | ||
</Col> | ||
</Row>; | ||
|
||
return <div className="mt-3"> | ||
<InputLabel text="Environment Variables" isRequired={false} /> | ||
{header} | ||
{content} | ||
<div><Button className="btn-outline-rk-green my-1" onClick={addFields}>Add Variable</Button></div> | ||
</div>; | ||
} | ||
|
||
export default EnvironmentVariables; |
Oops, something went wrong.