diff --git a/Composer/packages/client/src/pages/setting/dialog-settings/index.js b/Composer/packages/client/src/pages/setting/dialog-settings/index.js index addc9142b5..fafa38e6ea 100644 --- a/Composer/packages/client/src/pages/setting/dialog-settings/index.js +++ b/Composer/packages/client/src/pages/setting/dialog-settings/index.js @@ -1,4 +1,4 @@ -import React, { useState, useContext } from 'react'; +import React, { useState, useContext, useEffect } from 'react'; import { Controlled as CodeMirror } from 'react-codemirror2'; import jsonlint from 'jsonlint-webpack'; import 'codemirror/lib/codemirror.css'; @@ -32,6 +32,11 @@ export const DialogSettings = () => { const { state, actions } = useContext(StoreContext); const { botName, settings } = state; const [value, setValue] = useState(JSON.stringify(settings, null, 2)); + + useEffect(() => { + setValue(JSON.stringify(settings, null, 2)); + }, [settings]); + const updateFormData = (editor, data, newValue) => { try { setValue(newValue); diff --git a/Composer/packages/client/src/store/action/setting.ts b/Composer/packages/client/src/store/action/setting.ts index a267ba49ae..34764498f5 100644 --- a/Composer/packages/client/src/store/action/setting.ts +++ b/Composer/packages/client/src/store/action/setting.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { get, debounce } from 'lodash'; +import { get } from 'lodash'; import { ActionCreator, DialogSetting } from '../types'; import settingsStorage from '../../utils/dialogSettingStorage'; @@ -7,7 +7,6 @@ import { SensitiveProperties } from '../../constants'; import { BASEURL, ActionTypes } from './../../constants/index'; -const post = debounce(axios.post.bind(axios), 1000); export const setSettings: ActionCreator = async ({ dispatch }, botName: string, settings: DialogSetting) => { try { // set value to store @@ -23,7 +22,7 @@ export const setSettings: ActionCreator = async ({ dispatch }, botName: string, settingsStorage.setField(botName, property, propertyValue ? propertyValue : ''); } // set value to server - await post(`${BASEURL}/projects/opened/settings`, { settings }); + await axios.post(`${BASEURL}/projects/opened/settings`, { settings }); } catch (err) { dispatch({ type: ActionTypes.SET_ERROR, diff --git a/Composer/packages/server/src/models/bot/luPublisher.ts b/Composer/packages/server/src/models/bot/luPublisher.ts index 84fbbc6e7e..2668209990 100644 --- a/Composer/packages/server/src/models/bot/luPublisher.ts +++ b/Composer/packages/server/src/models/bot/luPublisher.ts @@ -7,7 +7,10 @@ import { LUFile, ILuisConfig, LuisStatus, FileUpdateType } from './interface'; const GENERATEDFOLDER = 'generated'; const LU_STATUS_FILE = 'luis.status.json'; - +const DEFAULT_STATUS = { + lastUpdateTime: 1, + lastPublishTime: 0, // means unpublished +}; export class LuPublisher { public botDir: string; public generatedFolderPath: string; @@ -18,7 +21,6 @@ export class LuPublisher { // key: filePath relative to bot dir // value: lastUpdateTime && lastPublishTime public status: { [key: string]: LuisStatus } = {}; - constructor(path: string, storage: IFileStorage) { this.botDir = path; this.generatedFolderPath = Path.join(this.botDir, GENERATEDFOLDER); @@ -36,15 +38,19 @@ export class LuPublisher { // make sure all LU file have an initial value files.forEach(f => { if (!this.status[f]) { - this.status[f] = { - lastUpdateTime: 1, - lastPublishTime: 0, // means unpublished - }; + this.status[f] = { ...DEFAULT_STATUS }; // use ... ensure don't referred to the same object } }); return this.status; }; + // reset status when config changed, because status don't represent the current config + public resetStatus = () => { + for (const key in this.status) { + this.status[key] = { ...DEFAULT_STATUS }; + } + }; + public saveStatus = async () => { if (!(await this.storage.exists(this.generatedFolderPath))) { await this.storage.mkDir(this.generatedFolderPath); @@ -114,9 +120,8 @@ export class LuPublisher { public setLuisConfig = async (config: ILuisConfig) => { if (!isEqual(config, this.config)) { this.config = config; - if (!(await this.storage.exists(this._getSettingPath(config)))) { - await this._deleteGenerated(this.generatedFolderPath); - } + await this._deleteGenerated(this.generatedFolderPath); + this.resetStatus(); } }; @@ -156,11 +161,6 @@ export class LuPublisher { }); }; - private _getSettingPath = (config: ILuisConfig | null) => { - if (config === null) return ''; - return Path.join(this.generatedFolderPath, `luis.settings.${config.environment}.${config.authoringRegion}.json`); - }; - private _getConfig = (luFiles: LUFile[]) => { const luConfig: any = { ...this.config }; luConfig.models = [];