Save app name on onBlur event

This commit is contained in:
navaneeth 2021-04-25 14:37:00 +05:30
parent 82c04369e6
commit d7528fffb6
4 changed files with 10 additions and 14 deletions

View file

@ -18,7 +18,7 @@ class AppsController < ApplicationController
def update
@app = App.find params[:id]
@app.update(definition: params[:definition], name: params[:name], current_version_id: params['currentVersion'])
@app.update(params["app"].permit("name", "current_version_id"))
end
def users

View file

@ -145,10 +145,11 @@ class Editor extends React.Component {
})
}
saveApp = () => {
const { app, appDefinition } = this.state;
appService.saveApp(app.id, app.name, appDefinition).then((data) => {
toast.success('App saved & deployed sucessfully', { hideProgressBar: true, position: "top-center" })
saveApp = (id, attributes, notify = false) => {
appService.saveApp(id, attributes).then((data) => {
if(notify){
toast.success('App saved sucessfully', { hideProgressBar: true, position: "top-center" })
}
});
}
@ -282,6 +283,7 @@ class Editor extends React.Component {
type="text"
style={{width: '200px', left: '80px', position: 'absolute'}}
onChange={(e) => this.onNameChanged(e.target.value)}
onBlur={(e) => this.saveApp(this.state.app.id, { name: e.target.value })}
className="form-control-plaintext form-control-plaintext-sm"
value={this.state.app.name}
/>

View file

@ -63,7 +63,7 @@ class SaveAndPreview extends React.Component {
deployVersion = (versionId) => {
this.setState({ isDeploying: true });
appService.saveApp(this.props.appId, this.props.appName ,undefined, versionId).then(data => {
appService.saveApp(this.props.appId, { name: this.props.appName, current_version_id: versionId }).then(data => {
this.setState({ isDeploying: false });
toast.success('Version Deployed', { hideProgressBar: true, position: "top-center", });
});

View file

@ -31,19 +31,13 @@ function getApp(id) {
}
function saveApp(id, name, definition, currentVersion) {
function saveApp(id, attributes) {
const headers = {
...authHeader(),
'Content-Type': 'application/json'
}
const body = {
definition,
name,
currentVersion
};
const requestOptions = { method: 'PUT', headers: headers, body: JSON.stringify(body) };
const requestOptions = { method: 'PUT', headers: headers, body: JSON.stringify({app: attributes}) };
return fetch(`${config.apiUrl}/apps/${id}`, requestOptions).then(handleResponse);
}