Skip to content

Commit

Permalink
Create update
Browse files Browse the repository at this point in the history
  • Loading branch information
jgruica committed May 22, 2020
1 parent 790990d commit 635bcc7
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions kotsadm/web/src/components/redactors/EditRedactor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import "brace/mode/text";
import "brace/mode/yaml";
import "brace/theme/chrome";

import { Utilities } from "../../utilities/utilities";

const redactor = {
id: "1",
name: "my-demo-redactor",
Expand Down Expand Up @@ -35,10 +37,18 @@ class EditRedactor extends Component {
createErrMsg: ""
};

createRedactor = () => {
createRedactor = (name, slug, enabled, newRedactor, yaml) => {
this.setState({ creatingRedactor: true, createErrMsg: "" });

fetch(`${window.env.API_ENDPOINT}/redact/metadata/${name}`, {
const payload = {
name: name,
slug: slug,
enabled: enabled,
new: newRedactor,
redactor: yaml
}

fetch(`${window.env.API_ENDPOINT}/redact/spec/${name}`, {
method: "POST",
headers: {
"Authorization": Utilities.getToken(),
Expand All @@ -47,7 +57,6 @@ class EditRedactor extends Component {
body: JSON.stringify(payload)
})
.then(async (res) => {

const createResponse = await res.json();
if (!res.ok) {
this.setState({
Expand All @@ -59,7 +68,7 @@ class EditRedactor extends Component {

if (createResponse.success) {
this.setState({
snapshotSettings: settingsResponse,
newRedactor: createResponse,
creatingRedactor: false,
createConfirm: true,
createErrMsg: ""
Expand All @@ -70,7 +79,7 @@ class EditRedactor extends Component {
} else {
this.setState({
creatingRedactor: false,
createErrMsg: settingsResponse.error
createErrMsg: createResponse.error
})
}
})
Expand Down Expand Up @@ -102,7 +111,11 @@ class EditRedactor extends Component {
}

onSaveRedactor = () => {
console.log("save redactor")
if (this.props.match.params.id) {
console.log("a")
} else {
this.createRedactor("", "", this.state.redactorEnabled, true, this.state.redactorYaml)
}
}

toggleEditRedactorName = () => {
Expand Down Expand Up @@ -157,7 +170,8 @@ class EditRedactor extends Component {
</div> :
<div className="flex flex1 alignItems--center">
<p className="u-fontWeight--bold u-color--tuna u-fontSize--jumbo u-lineHeight--normal u-marginRight--10"> {this.state.redactorName} </p>
<span className="replicated-link u-fontSize--normal" onClick={this.toggleEditRedactorName}> Edit </span>
{this.props.match.params.id &&
<span className="replicated-link u-fontSize--normal" onClick={this.toggleEditRedactorName}> Edit </span>}
</div>

}
Expand Down

0 comments on commit 635bcc7

Please sign in to comment.