import React from "react"; import {Button, Card, Col, Input, Row, Select} from 'antd'; import {LinkOutlined} from "@ant-design/icons"; import * as ApplicationBackend from "./backend/ApplicationBackend"; import * as Setting from "./Setting"; import * as ProviderBackend from "./backend/ProviderBackend"; const { Option } = Select; class ApplicationEditPage extends React.Component { constructor(props) { super(props); this.state = { classes: props, applicationName: props.match.params.applicationName, application: null, providers: [], }; } componentWillMount() { this.getApplication(); this.getProviders(); } getApplication() { ApplicationBackend.getApplication("admin", this.state.applicationName) .then((application) => { this.setState({ application: application, }); }); } getProviders() { ProviderBackend.getProviders("admin") .then((res) => { this.setState({ providers: res, }); }); } parseApplicationField(key, value) { // if ([].includes(key)) { // value = Setting.myParseInt(value); // } return value; } updateApplicationField(key, value) { value = this.parseApplicationField(key, value); let application = this.state.application; application[key] = value; this.setState({ application: application, }); } renderApplication() { return ( Edit Application     } style={{marginLeft: '5px'}} type="inner"> Name: { this.updateApplicationField('name', e.target.value); }} /> Display Name: { this.updateApplicationField('displayName', e.target.value); }} /> Providers: ) } submitApplicationEdit() { let application = Setting.deepCopy(this.state.application); ApplicationBackend.updateApplication(this.state.application.owner, this.state.applicationName, application) .then((res) => { if (res) { Setting.showMessage("success", `Successfully saved`); this.setState({ applicationName: this.state.application.name, }); this.props.history.push(`/applications/${this.state.application.name}`); } else { Setting.showMessage("error", `failed to save: server side failure`); this.updateApplicationField('name', this.state.applicationName); } }) .catch(error => { Setting.showMessage("error", `failed to save: ${error}`); }); } render() { return (
{ this.state.application !== null ? this.renderApplication() : null }
); } } export default ApplicationEditPage;