Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Composer/packages/client/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export enum ActionTypes {
RELOAD_BOT_FAILURE = 'RELOAD_BOT_FAILURE',
UPDATE_SKILL_SUCCESS = 'UPDATE_SKILL_SUCCESS',
SYNC_ENV_SETTING = 'SYNC_ENV_SETTING',
GET_ENV_SETTING = 'GET_ENV_SETTING',
SET_ERROR = 'SET_ERROR',
REMOVE_RECENT_PROJECT = 'REMOVE_RECENT_PROJECT',
EDITOR_RESET_VISUAL = 'EDITOR_RESET_VISUAL',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@

/** @jsx jsx */
import { jsx } from '@emotion/core';
import { useState, useContext } from 'react';
import { useContext } from 'react';
import { JsonEditor } from '@bfc/code-editor';
import formatMessage from 'format-message';
import { ChoiceGroup } from 'office-ui-fabric-react/lib/ChoiceGroup';
import { Link } from 'office-ui-fabric-react/lib/Link';
import { RouteComponentProps } from '@reach/router';

import { StoreContext } from '../../../store';
import { isAbsHosted } from '../../../utils/envUtil';

import { hostedSettings, hostedControls, slotChoice, settingsEditor } from './style';
import { hostedSettings, hostedControls, settingsEditor } from './style';

const hostControlLabels = {
showKeys: formatMessage('Show keys'),
Expand All @@ -28,27 +26,12 @@ const hostControlLabels = {

export const DialogSettings: React.FC<RouteComponentProps> = () => {
const { state, actions } = useContext(StoreContext);
const { botName, settings: origSettings, botEnvironment, projectId } = state;
const absHosted = isAbsHosted();
const { luis, MicrosoftAppPassword, MicrosoftAppId, ...settings } = origSettings;
const managedSettings = { luis, MicrosoftAppPassword, MicrosoftAppId };
const visibleSettings = absHosted ? settings : origSettings;
const [slot, setSlot] = useState(botEnvironment === 'editing' ? 'integration' : botEnvironment);

const slots = [
{ key: 'production', text: hostControlLabels.productionSlot, checked: slot === 'production' },
{ key: 'integration', text: hostControlLabels.integrationSlot, checked: slot === 'integration' },
];

const changeSlot = (_, option) => {
setSlot(option.key);
actions.setDialogSettingsSlot(projectId, option.key);
};
const { botName, settings, projectId } = state;

const saveChangeResult = (result) => {
try {
const mergedResult = absHosted ? { ...managedSettings, ...result } : result;
actions.setSettings(projectId, botName, mergedResult, absHosted ? slot : undefined);
const mergedResult = result;
actions.setSettings(projectId, botName, mergedResult);
} catch (err) {
// eslint-disable-next-line no-console
console.error(err.message);
Expand All @@ -68,25 +51,20 @@ export const DialogSettings: React.FC<RouteComponentProps> = () => {
{hostControlLabels.botSettingDescription}
&nbsp;
<Link
href={
absHosted
? 'https://aka.ms/absh/docs/settings'
: 'https://github.com/microsoft/BotFramework-Composer/blob/stable/docs/deploy-bot.md'
}
href={'https://github.com/microsoft/BotFramework-Composer/blob/stable/docs/deploy-bot.md'}
target="_blank"
>
{hostControlLabels.learnMore}
</Link>
</p>
{absHosted ? <ChoiceGroup css={slotChoice} options={slots} selectedKey={slot} onChange={changeSlot} /> : null}
</div>
);

return botName ? (
<div css={hostedSettings}>
{hostedControl()}
<div css={settingsEditor}>
<JsonEditor value={visibleSettings} onChange={handleChange} />
<JsonEditor value={settings} onChange={handleChange} />
</div>
</div>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export const hostedControls = css`
}
`;

export const slotChoice = css`
max-width: 40ch;
`;

export const settingsEditor = css`
flex: 1;
max-height: 70%;
Expand Down
27 changes: 1 addition & 26 deletions Composer/packages/client/src/store/action/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import { ActionCreator, DialogSetting } from '../types';

import { ActionTypes } from './../../constants/index';
import { BotEnvironments } from './../../utils/envUtil';
import httpClient from './../../utils/httpUtil';

export const setSettings: ActionCreator = async (
{ dispatch },
Expand All @@ -17,31 +15,8 @@ export const setSettings: ActionCreator = async (
type: ActionTypes.SYNC_ENV_SETTING,
payload: {
projectId,
botName,
settings,
},
});
};

export const setDialogSettingsSlot = async ({ dispatch }, projectId: string, slot?: BotEnvironments) => {
const suffix = slot ? `/${slot}` : '';
const url = `/projects/${projectId}/settings${suffix}`;

try {
const response = await httpClient.get(url);
const settings = response.data;
dispatch({
type: ActionTypes.GET_ENV_SETTING,
payload: {
settings,
},
});
} catch (err) {
dispatch({
type: ActionTypes.SET_ERROR,
payload: {
message: err.response && err.response.data.message ? err.reponse.data.message : err,
summary: 'DLG SETTINGS ERROR',
},
});
}
};
11 changes: 1 addition & 10 deletions Composer/packages/client/src/store/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ const dismissSkillManifestModal: ReducerFunc = (state) => {
return state;
};

const syncEnvSetting: ReducerFunc = (state, { settings }) => {
const { botName } = state;
const syncEnvSetting: ReducerFunc = (state, { settings, botName }) => {
// set value in local storage
for (const property of SensitiveProperties) {
if (has(settings, property)) {
Expand All @@ -441,13 +440,6 @@ const syncEnvSetting: ReducerFunc = (state, { settings }) => {
return state;
};

const getEnvSetting: ReducerFunc = (state, { settings }) => {
state.settings = settings;
refreshLocalStorage(state.botName, state.settings);
mergeLocalStorage(state.botName, state.settings);
return state;
};

const setTemplateProjects: ReducerFunc = (state, { response } = {}) => {
const data = response && response.data;

Expand Down Expand Up @@ -677,7 +669,6 @@ export const reducer = createReducer({
[ActionTypes.REMOVE_SKILL_MANIFEST]: removeSkillManifest,
[ActionTypes.UPDATE_SKILL_MANIFEST]: updateSkillManifest,
[ActionTypes.SYNC_ENV_SETTING]: syncEnvSetting,
[ActionTypes.GET_ENV_SETTING]: getEnvSetting,
[ActionTypes.USER_LOGIN_SUCCESS]: setUserToken,
[ActionTypes.USER_LOGIN_FAILURE]: setUserToken, // will be invoked with token = undefined
[ActionTypes.USER_SESSION_EXPIRED]: setUserSessionExpired,
Expand Down
45 changes: 0 additions & 45 deletions Composer/packages/server/__tests__/controllers/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,48 +272,3 @@ describe('lu operation', () => {
expect(mockRes.status).toHaveBeenCalledWith(200);
});
});

describe('setting operation', () => {
const defaultSetting = {
MicrosoftAppId: '',
luis: {
name: 'test',
authoringRegion: 'westus',
defaultLanguage: 'en-us',
environment: 'composer',
},
qna: {
knowledgebaseid: '',
endpointkey: '',
hostname: '',
},
downsampling: {
maxImbalanceRatio: 10,
maxUtteranceAllowed: 15000,
},
};
let projectId = '';
beforeEach(async () => {
projectId = await BotProjectService.openProject(location2);
});
it('should update default setting', async () => {
const mockReq = {
params: { projectId },
query: {},
body: { settings: defaultSetting },
} as Request;

await ProjectController.updateDefaultSlotEnvSettings(mockReq, mockRes);
expect(mockRes.send).toHaveBeenCalledWith('ok');
});

it('should update default setting', async () => {
const mockReq = {
params: { projectId },
query: { obfuscate: false },
} as Request;

await ProjectController.getDefaultSlotEnvSettings(mockReq, mockRes);
expect(mockRes.send).toHaveBeenCalledWith(defaultSetting);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const defaultDir = Path.join(__dirname, dir);
describe('get', () => {
it('return values', async () => {
const sm = new FileSettingManager(defaultDir);
const result = await sm.get('', false);
const result = await sm.get(false);
expect(result.label).toBe('default');
});

it('return obfuscated alues', async () => {
const sm = new FileSettingManager(defaultDir);
const result = await sm.get('', true);
const result = await sm.get(true);
expect(result.label).toBe('*****');
expect(result.mock1).toBe('*****');
expect(result.mock2).toBe('*****');
Expand All @@ -25,14 +25,4 @@ describe('get', () => {
expect(result.mock3.mock5[0]).toBe('*****');
expect(result.mock3.mock5[1]).toBe('*****');
});

it('return slot values', async () => {
const sm = new FileSettingManager(defaultDir);
const result = await sm.get('integration', false);
expect(result.label).toBe('integration');
const result2 = await sm.get('production', false);
expect(result2.label).toBe('production');
const result3 = await sm.get('bonus', false);
expect(result3.label).toBe('bonus');
});
});

This file was deleted.

88 changes: 0 additions & 88 deletions Composer/packages/server/src/controllers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,48 +252,6 @@ async function removeFile(req: Request, res: Response) {
}
}

async function getDefaultSlotEnvSettings(req: Request, res: Response) {
const projectId = req.params.projectId;
const user = await PluginLoader.getUserFromRequest(req);

const currentProject = await BotProjectService.getProjectById(projectId, user);
if (currentProject !== undefined) {
try {
const settings = await currentProject.getDefaultSlotEnvSettings(req.query.obfuscate);
res.send(settings);
} catch (err) {
res.status(404).json({
message: err.message,
});
}
} else {
res.status(404).json({
message: 'No such bot project opened',
});
}
}

async function getEnvSettings(req: Request, res: Response) {
const projectId = req.params.projectId;
const user = await PluginLoader.getUserFromRequest(req);

const currentProject = await BotProjectService.getProjectById(projectId, user);
if (currentProject !== undefined) {
try {
const settings = await currentProject.getEnvSettings(req.params.slot, req.query.obfuscate);
res.send(settings);
} catch (err) {
res.status(404).json({
message: err.message,
});
}
} else {
res.status(404).json({
message: 'No such bot project opened',
});
}
}

async function updateSkill(req: Request, res: Response) {
const projectId = req.params.projectId;
const user = await PluginLoader.getUserFromRequest(req);
Expand Down Expand Up @@ -349,48 +307,6 @@ async function exportProject(req: Request, res: Response) {
});
}

async function updateEnvSettings(req: Request, res: Response) {
const projectId = req.params.projectId;
const user = await PluginLoader.getUserFromRequest(req);

const currentProject = await BotProjectService.getProjectById(projectId, user);
if (currentProject !== undefined) {
try {
await currentProject.updateEnvSettings(req.params.slot, req.body.settings);
res.send('ok');
} catch (err) {
res.status(404).json({
message: err.message,
});
}
} else {
res.status(404).json({
message: 'No such bot project opened',
});
}
}

async function updateDefaultSlotEnvSettings(req: Request, res: Response) {
const projectId = req.params.projectId;
const user = await PluginLoader.getUserFromRequest(req);

const currentProject = await BotProjectService.getProjectById(projectId, user);
if (currentProject !== undefined) {
try {
await currentProject.updateDefaultSlotEnvSettings(req.body.settings);
res.send('ok');
} catch (err) {
res.status(404).json({
message: err.message,
});
}
} else {
res.status(404).json({
message: 'No such bot project opened',
});
}
}

async function publishLuis(req: Request, res: Response) {
const projectId = req.params.projectId;
const user = await PluginLoader.getUserFromRequest(req);
Expand Down Expand Up @@ -437,10 +353,6 @@ export const ProjectController = {
updateFile,
createFile,
removeFile,
getEnvSettings,
getDefaultSlotEnvSettings,
updateEnvSettings,
updateDefaultSlotEnvSettings,
updateSkill,
getSkill,
publishLuis,
Expand Down
Loading