Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix toggle not work in settings page #2476

Merged
merged 12 commits into from
Apr 8, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const DialogSettings = () => {
const { luis, MicrosoftAppPassword, MicrosoftAppId, ...settings } = origSettings;
const managedSettings = { luis, MicrosoftAppPassword, MicrosoftAppId };
const visibleSettings = absHosted ? settings : origSettings;
const editing = true;
const [slot, setSlot] = useState(botEnvironment === 'editing' ? 'integration' : botEnvironment);

const slots = [
Expand All @@ -43,7 +42,7 @@ export const DialogSettings = () => {

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

const saveChangeResult = result => {
Expand All @@ -57,9 +56,7 @@ export const DialogSettings = () => {
};

const handleChange = debounce(result => {
if (editing) {
saveChangeResult(result);
}
saveChangeResult(result);
}, 200);

const hostedControl = () => (
Expand Down Expand Up @@ -87,12 +84,7 @@ export const DialogSettings = () => {
<div css={hostedSettings}>
{hostedControl()}
<div css={settingsEditor}>
<JsonEditor
onChange={x => handleChange(x)}
options={{ readOnly: !editing }}
value={visibleSettings}
obfuscate={!editing}
/>
<JsonEditor onChange={x => handleChange(x)} value={visibleSettings} />
</div>
</div>
) : (
Expand Down
22 changes: 2 additions & 20 deletions Composer/packages/client/src/store/action/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ export const setSettings: ActionCreator = async (
}
};

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

try {
const response = await httpClient.get(url);
Expand All @@ -77,15 +71,3 @@ export const setDialogSettingsSlot = async (
});
}
};

export const setEditDialogSettings: ActionCreator = async (
store,
projectId: string,
editing: boolean,
slot?: BotEnvironments
) => {
if (editing) {
// fetch the real settings for editing
await setDialogSettingsSlot(store, projectId, editing, slot);
}
};
23 changes: 3 additions & 20 deletions Composer/packages/lib/code-editor/src/JsonEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,25 @@
// Licensed under the MIT License.
import React, { useState } from 'react';

import * as utils from './utils';
import { BaseEditor, BaseEditorProps, OnInit } from './BaseEditor';

interface JsonEditorProps extends Omit<BaseEditorProps, 'language' | 'value' | 'errorMessage' | 'onChange'> {
onChange: (jsonData: any) => void;
value?: object;
obfuscate?: boolean;
schema?: any;
}

const JsonEditor: React.FC<JsonEditorProps> = props => {
const {
options: additionalOptions,
value: initialValue,
onChange,
obfuscate,
onInit: onInitProp,
schema,
id,
...rest
} = props;
const { options: additionalOptions, value: initialValue, onChange, onInit: onInitProp, schema, id, ...rest } = props;

const [parseError, setParseError] = useState<string>('');
const options = {
quickSuggestions: true,
folding: false,
readOnly: obfuscate,
readOnly: false,
...additionalOptions,
};

const value = (() => {
const result = obfuscate ? utils.obfuscate(initialValue) : initialValue;
return JSON.stringify(result, null, 2);
})();

const onInit: OnInit = monaco => {
const disposable = monaco.editor.onDidCreateModel(model => {
const diagnosticOptions: any = {
Expand Down Expand Up @@ -94,12 +78,11 @@ const JsonEditor: React.FC<JsonEditorProps> = props => {

return (
<BaseEditor
key={obfuscate ? 'notedit' : 'edit'}
id={id}
helpURL="https://www.json.org"
language="json"
options={options}
value={value}
value={JSON.stringify(initialValue, null, 2)}
onChange={handleChange}
errorMessage={parseError}
onInit={onInit}
Expand Down
1 change: 0 additions & 1 deletion Composer/packages/lib/code-editor/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export * from './obfuscate';
export * from './common';
18 changes: 0 additions & 18 deletions Composer/packages/lib/code-editor/src/utils/obfuscate.ts

This file was deleted.