Commit c032399e by Shavonn Brown Committed by GitHub

remove editor keys and null coalescing (#20115)

* remove editor keys and null coalescing

* remove commented, update snap
parent 64752f38
...@@ -24,7 +24,7 @@ export class ConfigEditor extends PureComponent<Props, State> { ...@@ -24,7 +24,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
const { options } = this.props; const { options } = this.props;
this.state = { this.state = {
config: ConfigEditor.keyFill(options), config: ConfigEditor.defaults(options),
subscriptions: [], subscriptions: [],
logAnalyticsSubscriptions: [], logAnalyticsSubscriptions: [],
logAnalyticsWorkspaces: [], logAnalyticsWorkspaces: [],
...@@ -44,36 +44,19 @@ export class ConfigEditor extends PureComponent<Props, State> { ...@@ -44,36 +44,19 @@ export class ConfigEditor extends PureComponent<Props, State> {
static getDerivedStateFromProps(props: Props, state: State) { static getDerivedStateFromProps(props: Props, state: State) {
return { return {
...state, ...state,
config: ConfigEditor.keyFill(props.options), config: ConfigEditor.defaults(props.options),
}; };
} }
static keyFill = (options: any) => { static defaults = (options: any) => {
options.jsonData.cloudName = options.jsonData.cloudName || 'azuremonitor'; options.jsonData.cloudName = options.jsonData.cloudName || 'azuremonitor';
if (!options.jsonData.hasOwnProperty('azureLogAnalyticsSameAs')) { if (!options.jsonData.hasOwnProperty('azureLogAnalyticsSameAs')) {
options.jsonData.azureLogAnalyticsSameAs = true; options.jsonData.azureLogAnalyticsSameAs = true;
} }
if (!options.hasOwnProperty('editorSecureJsonData')) { if (!options.hasOwnProperty('secureJsonData')) {
options.editorSecureJsonData = { options.secureJsonData = {};
clientSecret: '',
logAnalyticsClientSecret: '',
appInsightsApiKey: '',
};
}
if (!options.hasOwnProperty('editorJsonData')) {
options.editorJsonData = {
clientId: options.jsonData.clientId || '',
tenantId: options.jsonData.tenantId || '',
subscriptionId: options.jsonData.subscriptionId || '',
logAnalyticsClientId: options.jsonData.logAnalyticsClientId || '',
logAnalyticsDefaultWorkspace: options.jsonData.logAnalyticsDefaultWorkspace || '',
logAnalyticsTenantId: options.jsonData.logAnalyticsTenantId || '',
logAnalyticsSubscriptionId: options.jsonData.logAnalyticsSubscriptionId || '',
appInsightsAppId: options.jsonData.appInsightsAppId || '',
};
} }
if (!options.hasOwnProperty('secureJsonFields')) { if (!options.hasOwnProperty('secureJsonFields')) {
...@@ -111,39 +94,13 @@ export class ConfigEditor extends PureComponent<Props, State> { ...@@ -111,39 +94,13 @@ export class ConfigEditor extends PureComponent<Props, State> {
} }
} }
for (const m in config.editorJsonData) {
if (!config.hasOwnProperty('jsonData')) {
config.jsonData = {};
}
if (config.editorJsonData[m].length === 0) {
if (config.hasOwnProperty('jsonData') && config.jsonData.hasOwnProperty(m)) {
delete config.jsonData[m];
}
} else {
config.jsonData[m] = config.editorJsonData[m];
}
}
for (const l in config.editorSecureJsonData) {
if (!config.hasOwnProperty('secureJsonData')) {
config.secureJsonData = {};
}
if (config.editorSecureJsonData[l].length === 0) {
if (config.hasOwnProperty('secureJsonData') && config.secureJsonData.hasOwnProperty(l)) {
delete config.secureJsonData[l];
}
} else {
config.secureJsonData[l] = config.editorSecureJsonData[l];
}
}
this.props.onOptionsChange({ this.props.onOptionsChange({
...config, ...config,
}); });
}; };
hasNecessaryCredentials = () => { hasNecessaryCredentials = () => {
if (!this.state.config.secureJsonFields.clientSecret && !this.state.config.editorSecureJsonData.clientSecret) { if (!this.state.config.secureJsonFields.clientSecret && !this.state.config.secureJsonData.clientSecret) {
return false; return false;
} }
...@@ -157,7 +114,7 @@ export class ConfigEditor extends PureComponent<Props, State> { ...@@ -157,7 +114,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
logAnalyticsHasNecessaryCredentials = () => { logAnalyticsHasNecessaryCredentials = () => {
if ( if (
!this.state.config.secureJsonFields.logAnalyticsClientSecret && !this.state.config.secureJsonFields.logAnalyticsClientSecret &&
!this.state.config.editorSecureJsonData.logAnalyticsClientSecret !this.state.config.secureJsonData.logAnalyticsClientSecret
) { ) {
return false; return false;
} }
...@@ -206,11 +163,10 @@ export class ConfigEditor extends PureComponent<Props, State> { ...@@ -206,11 +163,10 @@ export class ConfigEditor extends PureComponent<Props, State> {
if (subscriptions && subscriptions.length > 0) { if (subscriptions && subscriptions.length > 0) {
this.setState({ subscriptions }); this.setState({ subscriptions });
this.state.config.editorJsonData.subscriptionId = this.state.config.jsonData.subscriptionId = this.state.config.jsonData.subscriptionId || subscriptions[0].value;
this.state.config.editorJsonData.subscriptionId || subscriptions[0].value;
} }
if (this.state.config.editorJsonData.subscriptionId && this.state.config.jsonData.azureLogAnalyticsSameAs) { if (this.state.config.jsonData.subscriptionId && this.state.config.jsonData.azureLogAnalyticsSameAs) {
await this.getWorkspaces(); await this.getWorkspaces();
} }
}; };
...@@ -233,19 +189,18 @@ export class ConfigEditor extends PureComponent<Props, State> { ...@@ -233,19 +189,18 @@ export class ConfigEditor extends PureComponent<Props, State> {
if (logAnalyticsSubscriptions && logAnalyticsSubscriptions.length > 0) { if (logAnalyticsSubscriptions && logAnalyticsSubscriptions.length > 0) {
this.setState({ logAnalyticsSubscriptions }); this.setState({ logAnalyticsSubscriptions });
this.state.config.editorJsonData.logAnalyticsSubscriptionId = this.state.config.jsonData.logAnalyticsSubscriptionId =
this.state.config.editorJsonData.logAnalyticsSubscriptionId || logAnalyticsSubscriptions[0].value; this.state.config.jsonData.logAnalyticsSubscriptionId || logAnalyticsSubscriptions[0].value;
} }
if (this.state.config.editorJsonData.logAnalyticsSubscriptionId) { if (this.state.config.jsonData.logAnalyticsSubscriptionId) {
await this.getWorkspaces(); await this.getWorkspaces();
} }
}; };
getWorkspaces = async () => { getWorkspaces = async () => {
const sameAs = const sameAs = this.state.config.jsonData.azureLogAnalyticsSameAs && this.state.config.jsonData.subscriptionId;
this.state.config.jsonData.azureLogAnalyticsSameAs && this.state.config.editorJsonData.subscriptionId; if (!sameAs && !this.state.config.jsonData.logAnalyticsSubscriptionId) {
if (!sameAs && !this.state.config.editorJsonData.logAnalyticsSubscriptionId) {
return; return;
} }
...@@ -256,9 +211,7 @@ export class ConfigEditor extends PureComponent<Props, State> { ...@@ -256,9 +211,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
); );
let logAnalyticsWorkspaces = await azureLogAnalyticsDatasource.getWorkspaces( let logAnalyticsWorkspaces = await azureLogAnalyticsDatasource.getWorkspaces(
sameAs sameAs ? this.state.config.jsonData.subscriptionId : this.state.config.jsonData.logAnalyticsSubscriptionId
? this.state.config.editorJsonData.subscriptionId
: this.state.config.editorJsonData.logAnalyticsSubscriptionId
); );
logAnalyticsWorkspaces = logAnalyticsWorkspaces.map((workspace: any) => { logAnalyticsWorkspaces = logAnalyticsWorkspaces.map((workspace: any) => {
return { return {
...@@ -270,8 +223,8 @@ export class ConfigEditor extends PureComponent<Props, State> { ...@@ -270,8 +223,8 @@ export class ConfigEditor extends PureComponent<Props, State> {
if (logAnalyticsWorkspaces.length > 0) { if (logAnalyticsWorkspaces.length > 0) {
this.setState({ logAnalyticsWorkspaces }); this.setState({ logAnalyticsWorkspaces });
this.state.config.editorJsonData.logAnalyticsDefaultWorkspace = this.state.config.jsonData.logAnalyticsDefaultWorkspace =
this.state.config.editorJsonData.logAnalyticsDefaultWorkspace || logAnalyticsWorkspaces[0].value; this.state.config.jsonData.logAnalyticsDefaultWorkspace || logAnalyticsWorkspaces[0].value;
} }
}; };
......
...@@ -10,21 +10,6 @@ exports[`Render should render component 1`] = ` ...@@ -10,21 +10,6 @@ exports[`Render should render component 1`] = `
"basicAuthPassword": "", "basicAuthPassword": "",
"basicAuthUser": "", "basicAuthUser": "",
"database": "", "database": "",
"editorJsonData": Object {
"appInsightsAppId": "",
"clientId": "",
"logAnalyticsClientId": "",
"logAnalyticsDefaultWorkspace": "",
"logAnalyticsSubscriptionId": "",
"logAnalyticsTenantId": "",
"subscriptionId": "",
"tenantId": "",
},
"editorSecureJsonData": Object {
"appInsightsApiKey": "",
"clientSecret": "",
"logAnalyticsClientSecret": "",
},
"id": 21, "id": 21,
"isDefault": false, "isDefault": false,
"jsonData": Object { "jsonData": Object {
...@@ -57,21 +42,6 @@ exports[`Render should render component 1`] = ` ...@@ -57,21 +42,6 @@ exports[`Render should render component 1`] = `
"basicAuthPassword": "", "basicAuthPassword": "",
"basicAuthUser": "", "basicAuthUser": "",
"database": "", "database": "",
"editorJsonData": Object {
"appInsightsAppId": "",
"clientId": "",
"logAnalyticsClientId": "",
"logAnalyticsDefaultWorkspace": "",
"logAnalyticsSubscriptionId": "",
"logAnalyticsTenantId": "",
"subscriptionId": "",
"tenantId": "",
},
"editorSecureJsonData": Object {
"appInsightsApiKey": "",
"clientSecret": "",
"logAnalyticsClientSecret": "",
},
"id": 21, "id": 21,
"isDefault": false, "isDefault": false,
"jsonData": Object { "jsonData": Object {
...@@ -106,21 +76,6 @@ exports[`Render should render component 1`] = ` ...@@ -106,21 +76,6 @@ exports[`Render should render component 1`] = `
"basicAuthPassword": "", "basicAuthPassword": "",
"basicAuthUser": "", "basicAuthUser": "",
"database": "", "database": "",
"editorJsonData": Object {
"appInsightsAppId": "",
"clientId": "",
"logAnalyticsClientId": "",
"logAnalyticsDefaultWorkspace": "",
"logAnalyticsSubscriptionId": "",
"logAnalyticsTenantId": "",
"subscriptionId": "",
"tenantId": "",
},
"editorSecureJsonData": Object {
"appInsightsApiKey": "",
"clientSecret": "",
"logAnalyticsClientSecret": "",
},
"id": 21, "id": 21,
"isDefault": false, "isDefault": false,
"jsonData": Object { "jsonData": Object {
......
...@@ -20,18 +20,16 @@ const setup = (propOverrides?: object) => { ...@@ -20,18 +20,16 @@ const setup = (propOverrides?: object) => {
basicAuthPassword: '', basicAuthPassword: '',
withCredentials: false, withCredentials: false,
isDefault: false, isDefault: false,
jsonData: {
azureLogAnalyticsSameAs: false,
},
secureJsonFields: { secureJsonFields: {
logAnalyticsClientSecret: false, logAnalyticsClientSecret: false,
}, },
editorJsonData: { jsonData: {
azureLogAnalyticsSameAs: false,
logAnalyticsDefaultWorkspace: '', logAnalyticsDefaultWorkspace: '',
logAnalyticsClientSecret: '', logAnalyticsClientSecret: '',
logAnalyticsTenantId: '', logAnalyticsTenantId: '',
}, },
editorSecureJsonData: { secureJsonData: {
logAnalyticsClientSecret: '', logAnalyticsClientSecret: '',
}, },
version: 1, version: 1,
...@@ -67,7 +65,7 @@ describe('Render', () => { ...@@ -67,7 +65,7 @@ describe('Render', () => {
it('should enable azure log analytics load workspaces button', () => { it('should enable azure log analytics load workspaces button', () => {
const wrapper = setup({ const wrapper = setup({
editorJsonData: { jsonData: {
logAnalyticsDefaultWorkspace: '', logAnalyticsDefaultWorkspace: '',
logAnalyticsTenantId: 'e7f3f661-a933-4b3f-8176-51c4f982ec48', logAnalyticsTenantId: 'e7f3f661-a933-4b3f-8176-51c4f982ec48',
logAnalyticsClientId: '44693801-6ee6-49de-9b2d-9106972f9572', logAnalyticsClientId: '44693801-6ee6-49de-9b2d-9106972f9572',
......
...@@ -43,8 +43,8 @@ export class AnalyticsConfig extends PureComponent<Props, State> { ...@@ -43,8 +43,8 @@ export class AnalyticsConfig extends PureComponent<Props, State> {
onLogAnalyticsTenantIdChange = (logAnalyticsTenantId: string) => { onLogAnalyticsTenantIdChange = (logAnalyticsTenantId: string) => {
this.props.onDatasourceUpdate({ this.props.onDatasourceUpdate({
...this.state.config, ...this.state.config,
editorJsonData: { jsonData: {
...this.state.config.editorJsonData, ...this.state.config.jsonData,
logAnalyticsTenantId, logAnalyticsTenantId,
}, },
}); });
...@@ -53,8 +53,8 @@ export class AnalyticsConfig extends PureComponent<Props, State> { ...@@ -53,8 +53,8 @@ export class AnalyticsConfig extends PureComponent<Props, State> {
onLogAnalyticsClientIdChange = (logAnalyticsClientId: string) => { onLogAnalyticsClientIdChange = (logAnalyticsClientId: string) => {
this.props.onDatasourceUpdate({ this.props.onDatasourceUpdate({
...this.state.config, ...this.state.config,
editorJsonData: { jsonData: {
...this.state.config.editorJsonData, ...this.state.config.jsonData,
logAnalyticsClientId, logAnalyticsClientId,
}, },
}); });
...@@ -63,8 +63,8 @@ export class AnalyticsConfig extends PureComponent<Props, State> { ...@@ -63,8 +63,8 @@ export class AnalyticsConfig extends PureComponent<Props, State> {
onLogAnalyticsClientSecretChange = (logAnalyticsClientSecret: string) => { onLogAnalyticsClientSecretChange = (logAnalyticsClientSecret: string) => {
this.props.onDatasourceUpdate({ this.props.onDatasourceUpdate({
...this.state.config, ...this.state.config,
editorSecureJsonData: { secureJsonData: {
...this.state.config.editorSecureJsonData, ...this.state.config.secureJsonData,
logAnalyticsClientSecret, logAnalyticsClientSecret,
}, },
}); });
...@@ -81,8 +81,8 @@ export class AnalyticsConfig extends PureComponent<Props, State> { ...@@ -81,8 +81,8 @@ export class AnalyticsConfig extends PureComponent<Props, State> {
onLogAnalyticsSubscriptionSelect = (logAnalyticsSubscription: SelectableValue<string>) => { onLogAnalyticsSubscriptionSelect = (logAnalyticsSubscription: SelectableValue<string>) => {
this.props.onDatasourceUpdate({ this.props.onDatasourceUpdate({
...this.state.config, ...this.state.config,
editorJsonData: { jsonData: {
...this.state.config.editorJsonData, ...this.state.config.jsonData,
logAnalyticsSubscriptionId: logAnalyticsSubscription.value, logAnalyticsSubscriptionId: logAnalyticsSubscription.value,
}, },
}); });
...@@ -91,8 +91,8 @@ export class AnalyticsConfig extends PureComponent<Props, State> { ...@@ -91,8 +91,8 @@ export class AnalyticsConfig extends PureComponent<Props, State> {
onWorkspaceSelectChange = (logAnalyticsDefaultWorkspace: SelectableValue<string>) => { onWorkspaceSelectChange = (logAnalyticsDefaultWorkspace: SelectableValue<string>) => {
this.props.onDatasourceUpdate({ this.props.onDatasourceUpdate({
...this.state.config, ...this.state.config,
editorJsonData: { jsonData: {
...this.state.config.editorJsonData, ...this.state.config.jsonData,
logAnalyticsDefaultWorkspace: logAnalyticsDefaultWorkspace.value, logAnalyticsDefaultWorkspace: logAnalyticsDefaultWorkspace.value,
}, },
}); });
...@@ -110,29 +110,30 @@ export class AnalyticsConfig extends PureComponent<Props, State> { ...@@ -110,29 +110,30 @@ export class AnalyticsConfig extends PureComponent<Props, State> {
hasWorkspaceRequiredFields = () => { hasWorkspaceRequiredFields = () => {
const { const {
config: { editorJsonData, editorSecureJsonData, jsonData, secureJsonFields }, config: { jsonData, secureJsonData, secureJsonFields },
} = this.state; } = this.state;
if (jsonData.azureLogAnalyticsSameAs) { if (jsonData.azureLogAnalyticsSameAs) {
return ( return (
editorJsonData.tenantId && jsonData.tenantId &&
editorJsonData.clientId && jsonData.clientId &&
editorJsonData.subscriptionId && jsonData.subscriptionId &&
(editorSecureJsonData.clientSecret || secureJsonFields.clientSecret) (secureJsonData.clientSecret || secureJsonFields.clientSecret)
); );
} }
return ( return (
editorJsonData.logAnalyticsTenantId.length && jsonData.logAnalyticsTenantId &&
editorJsonData.logAnalyticsClientId.length && jsonData.logAnalyticsTenantId.length &&
editorJsonData.logAnalyticsSubscriptionId && (jsonData.logAnalyticsClientId && jsonData.logAnalyticsClientId.length) &&
(secureJsonFields.logAnalyticsClientSecret || editorSecureJsonData.logAnalyticsClientSecret) jsonData.logAnalyticsSubscriptionId &&
(secureJsonFields.logAnalyticsClientSecret || secureJsonData.logAnalyticsClientSecret)
); );
}; };
render() { render() {
const { const {
config: { editorJsonData, editorSecureJsonData, jsonData, secureJsonFields }, config: { jsonData, secureJsonData, secureJsonFields },
logAnalyticsSubscriptions, logAnalyticsSubscriptions,
logAnalyticsWorkspaces, logAnalyticsWorkspaces,
} = this.state; } = this.state;
...@@ -154,10 +155,10 @@ export class AnalyticsConfig extends PureComponent<Props, State> { ...@@ -154,10 +155,10 @@ export class AnalyticsConfig extends PureComponent<Props, State> {
{!jsonData.azureLogAnalyticsSameAs && ( {!jsonData.azureLogAnalyticsSameAs && (
<AzureCredentialsForm <AzureCredentialsForm
subscriptionOptions={logAnalyticsSubscriptions} subscriptionOptions={logAnalyticsSubscriptions}
selectedSubscription={editorJsonData.logAnalyticsSubscriptionId} selectedSubscription={jsonData.logAnalyticsSubscriptionId}
tenantId={editorJsonData.logAnalyticsTenantId} tenantId={jsonData.logAnalyticsTenantId}
clientId={editorJsonData.logAnalyticsClientId} clientId={jsonData.logAnalyticsClientId}
clientSecret={editorSecureJsonData.logAnalyticsClientSecret} clientSecret={secureJsonData.logAnalyticsClientSecret}
clientSecretConfigured={secureJsonFields.logAnalyticsClientSecret} clientSecretConfigured={secureJsonFields.logAnalyticsClientSecret}
onSubscriptionSelectChange={this.onLogAnalyticsSubscriptionSelect} onSubscriptionSelectChange={this.onLogAnalyticsSubscriptionSelect}
onTenantIdChange={this.onLogAnalyticsTenantIdChange} onTenantIdChange={this.onLogAnalyticsTenantIdChange}
...@@ -179,10 +180,10 @@ export class AnalyticsConfig extends PureComponent<Props, State> { ...@@ -179,10 +180,10 @@ export class AnalyticsConfig extends PureComponent<Props, State> {
<div className="width-25"> <div className="width-25">
<Select <Select
value={logAnalyticsWorkspaces.find( value={logAnalyticsWorkspaces.find(
workspace => workspace.value === editorJsonData.logAnalyticsDefaultWorkspace workspace => workspace.value === jsonData.logAnalyticsDefaultWorkspace
)} )}
options={logAnalyticsWorkspaces} options={logAnalyticsWorkspaces}
defaultValue={editorJsonData.logAnalyticsDefaultWorkspace} defaultValue={jsonData.logAnalyticsDefaultWorkspace}
onChange={this.onWorkspaceSelectChange} onChange={this.onWorkspaceSelectChange}
/> />
</div> </div>
......
...@@ -111,7 +111,7 @@ export class AzureCredentialsForm extends PureComponent<Props, State> { ...@@ -111,7 +111,7 @@ export class AzureCredentialsForm extends PureComponent<Props, State> {
<Input <Input
className="width-30" className="width-30"
placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
value={tenantId} value={tenantId || ''}
onChange={(event: ChangeEvent<HTMLInputElement>) => onTenantIdChange(event.target.value)} onChange={(event: ChangeEvent<HTMLInputElement>) => onTenantIdChange(event.target.value)}
/> />
</div> </div>
...@@ -124,7 +124,7 @@ export class AzureCredentialsForm extends PureComponent<Props, State> { ...@@ -124,7 +124,7 @@ export class AzureCredentialsForm extends PureComponent<Props, State> {
<Input <Input
className="width-30" className="width-30"
placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
value={clientId} value={clientId || ''}
onChange={(event: ChangeEvent<HTMLInputElement>) => onClientIdChange(event.target.value)} onChange={(event: ChangeEvent<HTMLInputElement>) => onClientIdChange(event.target.value)}
/> />
</div> </div>
...@@ -152,7 +152,7 @@ export class AzureCredentialsForm extends PureComponent<Props, State> { ...@@ -152,7 +152,7 @@ export class AzureCredentialsForm extends PureComponent<Props, State> {
<Input <Input
className="width-30" className="width-30"
placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
value={clientSecret} value={clientSecret || ''}
onChange={(event: ChangeEvent<HTMLInputElement>) => onClientSecretChange(event.target.value)} onChange={(event: ChangeEvent<HTMLInputElement>) => onClientSecretChange(event.target.value)}
/> />
</div> </div>
......
...@@ -20,14 +20,13 @@ const setup = (propOverrides?: object) => { ...@@ -20,14 +20,13 @@ const setup = (propOverrides?: object) => {
basicAuthPassword: '', basicAuthPassword: '',
withCredentials: false, withCredentials: false,
isDefault: false, isDefault: false,
jsonData: {},
secureJsonFields: { secureJsonFields: {
appInsightsApiKey: false, appInsightsApiKey: false,
}, },
editorJsonData: { jsonData: {
appInsightsAppId: 'cddcc020-2c94-460a-a3d0-df3147ffa792', appInsightsAppId: 'cddcc020-2c94-460a-a3d0-df3147ffa792',
}, },
editorSecureJsonData: { secureJsonData: {
appInsightsApiKey: 'e7f3f661-a933-4b3f-8176-51c4f982ec48', appInsightsApiKey: 'e7f3f661-a933-4b3f-8176-51c4f982ec48',
}, },
version: 1, version: 1,
...@@ -54,10 +53,10 @@ describe('Render', () => { ...@@ -54,10 +53,10 @@ describe('Render', () => {
secureJsonFields: { secureJsonFields: {
appInsightsApiKey: true, appInsightsApiKey: true,
}, },
editorJsonData: { jsonData: {
appInsightsAppId: 'cddcc020-2c94-460a-a3d0-df3147ffa792', appInsightsAppId: 'cddcc020-2c94-460a-a3d0-df3147ffa792',
}, },
editorSecureJsonData: { secureJsonData: {
appInsightsApiKey: 'e7f3f661-a933-4b3f-8176-51c4f982ec48', appInsightsApiKey: 'e7f3f661-a933-4b3f-8176-51c4f982ec48',
}, },
}, },
...@@ -71,10 +70,10 @@ describe('Render', () => { ...@@ -71,10 +70,10 @@ describe('Render', () => {
secureJsonFields: { secureJsonFields: {
appInsightsApiKey: false, appInsightsApiKey: false,
}, },
editorJsonData: { jsonData: {
appInsightsAppId: 'cddcc020-2c94-460a-a3d0-df3147ffa792', appInsightsAppId: 'cddcc020-2c94-460a-a3d0-df3147ffa792',
}, },
editorSecureJsonData: { secureJsonData: {
appInsightsApiKey: 'e7f3f661-a933-4b3f-8176-51c4f982ec48', appInsightsApiKey: 'e7f3f661-a933-4b3f-8176-51c4f982ec48',
}, },
}, },
......
...@@ -31,8 +31,8 @@ export class InsightsConfig extends PureComponent<Props, State> { ...@@ -31,8 +31,8 @@ export class InsightsConfig extends PureComponent<Props, State> {
onAppInsightsAppIdChange = (appInsightsAppId: string) => { onAppInsightsAppIdChange = (appInsightsAppId: string) => {
this.props.onDatasourceUpdate({ this.props.onDatasourceUpdate({
...this.state.config, ...this.state.config,
editorJsonData: { jsonData: {
...this.state.config.editorJsonData, ...this.state.config.jsonData,
appInsightsAppId, appInsightsAppId,
}, },
}); });
...@@ -41,8 +41,8 @@ export class InsightsConfig extends PureComponent<Props, State> { ...@@ -41,8 +41,8 @@ export class InsightsConfig extends PureComponent<Props, State> {
onAppInsightsApiKeyChange = (appInsightsApiKey: string) => { onAppInsightsApiKeyChange = (appInsightsApiKey: string) => {
this.props.onDatasourceUpdate({ this.props.onDatasourceUpdate({
...this.state.config, ...this.state.config,
editorSecureJsonData: { secureJsonData: {
...this.state.config.editorSecureJsonData, ...this.state.config.secureJsonData,
appInsightsApiKey, appInsightsApiKey,
}, },
}); });
...@@ -87,7 +87,7 @@ export class InsightsConfig extends PureComponent<Props, State> { ...@@ -87,7 +87,7 @@ export class InsightsConfig extends PureComponent<Props, State> {
<Input <Input
className="width-30" className="width-30"
placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
value={config.editorSecureJsonData.appInsightsApiKey} value={config.secureJsonData.appInsightsApiKey || ''}
onChange={event => this.onAppInsightsApiKeyChange(event.target.value)} onChange={event => this.onAppInsightsApiKeyChange(event.target.value)}
/> />
</div> </div>
...@@ -100,7 +100,7 @@ export class InsightsConfig extends PureComponent<Props, State> { ...@@ -100,7 +100,7 @@ export class InsightsConfig extends PureComponent<Props, State> {
<div className="width-15"> <div className="width-15">
<Input <Input
className="width-30" className="width-30"
value={config.editorJsonData.appInsightsAppId} value={config.jsonData.appInsightsAppId || ''}
onChange={event => this.onAppInsightsAppIdChange(event.target.value)} onChange={event => this.onAppInsightsAppIdChange(event.target.value)}
/> />
</div> </div>
......
...@@ -54,8 +54,8 @@ export class MonitorConfig extends PureComponent<Props, State> { ...@@ -54,8 +54,8 @@ export class MonitorConfig extends PureComponent<Props, State> {
onTenantIdChange = (tenantId: string) => { onTenantIdChange = (tenantId: string) => {
this.props.onDatasourceUpdate({ this.props.onDatasourceUpdate({
...this.state.config, ...this.state.config,
editorJsonData: { jsonData: {
...this.state.config.editorJsonData, ...this.state.config.jsonData,
tenantId, tenantId,
}, },
}); });
...@@ -64,8 +64,8 @@ export class MonitorConfig extends PureComponent<Props, State> { ...@@ -64,8 +64,8 @@ export class MonitorConfig extends PureComponent<Props, State> {
onClientIdChange = (clientId: string) => { onClientIdChange = (clientId: string) => {
this.props.onDatasourceUpdate({ this.props.onDatasourceUpdate({
...this.state.config, ...this.state.config,
editorJsonData: { jsonData: {
...this.state.config.editorJsonData, ...this.state.config.jsonData,
clientId, clientId,
}, },
}); });
...@@ -74,8 +74,8 @@ export class MonitorConfig extends PureComponent<Props, State> { ...@@ -74,8 +74,8 @@ export class MonitorConfig extends PureComponent<Props, State> {
onClientSecretChange = (clientSecret: string) => { onClientSecretChange = (clientSecret: string) => {
this.props.onDatasourceUpdate({ this.props.onDatasourceUpdate({
...this.state.config, ...this.state.config,
editorSecureJsonData: { secureJsonData: {
...this.state.config.editorSecureJsonData, ...this.state.config.secureJsonData,
clientSecret, clientSecret,
}, },
}); });
...@@ -95,8 +95,8 @@ export class MonitorConfig extends PureComponent<Props, State> { ...@@ -95,8 +95,8 @@ export class MonitorConfig extends PureComponent<Props, State> {
onSubscriptionSelect = (subscription: SelectableValue<string>) => { onSubscriptionSelect = (subscription: SelectableValue<string>) => {
this.props.onDatasourceUpdate({ this.props.onDatasourceUpdate({
...this.state.config, ...this.state.config,
editorJsonData: { jsonData: {
...this.state.config.editorJsonData, ...this.state.config.jsonData,
subscriptionId: subscription.value, subscriptionId: subscription.value,
}, },
}); });
...@@ -111,10 +111,10 @@ export class MonitorConfig extends PureComponent<Props, State> { ...@@ -111,10 +111,10 @@ export class MonitorConfig extends PureComponent<Props, State> {
selectedAzureCloud={config.jsonData.cloudName} selectedAzureCloud={config.jsonData.cloudName}
azureCloudOptions={azureClouds} azureCloudOptions={azureClouds}
subscriptionOptions={subscriptions} subscriptionOptions={subscriptions}
selectedSubscription={config.editorJsonData.subscriptionId} selectedSubscription={config.jsonData.subscriptionId}
tenantId={config.editorJsonData.tenantId} tenantId={config.jsonData.tenantId}
clientId={config.editorJsonData.clientId} clientId={config.jsonData.clientId}
clientSecret={config.editorSecureJsonData.clientSecret} clientSecret={config.secureJsonData.clientSecret}
clientSecretConfigured={config.secureJsonFields.clientSecret} clientSecretConfigured={config.secureJsonFields.clientSecret}
onAzureCloudChange={this.onAzureCloudSelect} onAzureCloudChange={this.onAzureCloudSelect}
onSubscriptionSelectChange={this.onSubscriptionSelect} onSubscriptionSelectChange={this.onSubscriptionSelect}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment