UI: Use the new JSON schema in the Configure page

This commit is contained in:
Ilija Lazoroski 2022-06-29 18:33:38 +02:00
parent 22bb423d0d
commit afbd3789e8
1 changed files with 9 additions and 11 deletions

View File

@ -18,6 +18,7 @@ import ConfigImportModal from '../configuration-components/ImportConfigModal';
import applyUiSchemaManipulators from '../configuration-components/UISchemaManipulators.tsx'; import applyUiSchemaManipulators from '../configuration-components/UISchemaManipulators.tsx';
import HtmlFieldDescription from '../configuration-components/HtmlFieldDescription.js'; import HtmlFieldDescription from '../configuration-components/HtmlFieldDescription.js';
import CONFIGURATION_TABS_PER_MODE from '../configuration-components/ConfigurationTabs.js'; import CONFIGURATION_TABS_PER_MODE from '../configuration-components/ConfigurationTabs.js';
import {SCHEMA} from '../../services/configuration/config_schema.js';
const CONFIG_URL = '/api/configuration/island'; const CONFIG_URL = '/api/configuration/island';
export const API_PBA_LINUX = '/api/file-upload/PBAlinux'; export const API_PBA_LINUX = '/api/file-upload/PBAlinux';
@ -68,24 +69,25 @@ class ConfigurePageComponent extends AuthComponent {
} }
componentDidMount = () => { componentDidMount = () => {
let urls = [CONFIG_URL]; let urls = ['/api/agent-configuration'];
// ??? Why fetch config here and not in `render()`? // ??? Why fetch config here and not in `render()`?
Promise.all(urls.map(url => this.authFetch(url).then(res => res.json()))) Promise.all(urls.map(url => this.authFetch(url).then(res => res.json())))
.then(data => { .then(data => {
let sections = []; let sections = [];
let monkeyConfig = data[0]; let monkeyConfig = data[0];
this.setInitialConfig(monkeyConfig.configuration); this.setInitialConfig(monkeyConfig);
for (let sectionKey of this.getSectionsOrder()) { for (let sectionKey of this.getSectionsOrder()) {
sections.push({ sections.push({
key: sectionKey, key: sectionKey,
title: monkeyConfig.schema.properties[sectionKey].title title: SCHEMA.properties[sectionKey].title
}); });
} }
this.setState({ this.setState({
schema: monkeyConfig.schema, schema: SCHEMA,
configuration: monkeyConfig.configuration, configuration: monkeyConfig,
sections: sections, sections: sections,
currentFormData: monkeyConfig.configuration[this.state.selectedSection] currentFormData: monkeyConfig[this.state.selectedSection]
}) })
}); });
}; };
@ -337,10 +339,6 @@ class ConfigurePageComponent extends AuthComponent {
let formProperties = {}; let formProperties = {};
formProperties['schema'] = displayedSchema formProperties['schema'] = displayedSchema
formProperties['uiSchema'] = UiSchema({ formProperties['uiSchema'] = UiSchema({
PBA_linux_filename: this.state.configuration.monkey.post_breach.PBA_linux_filename,
PBA_windows_filename: this.state.configuration.monkey.post_breach.PBA_windows_filename,
setPbaFilenameWindows: this.setPbaFilenameWindows,
setPbaFilenameLinux: this.setPbaFilenameLinux,
selectedSection: this.state.selectedSection selectedSection: this.state.selectedSection
}) })
formProperties['fields'] = {DescriptionField: HtmlFieldDescription}; formProperties['fields'] = {DescriptionField: HtmlFieldDescription};
@ -391,7 +389,7 @@ class ConfigurePageComponent extends AuthComponent {
style={{'marginBottom': '2em'}} style={{'marginBottom': '2em'}}
className={'config-nav'}> className={'config-nav'}>
{this.state.sections.map(section => { {this.state.sections.map(section => {
let classProp = section.key.startsWith('basic') ? 'tab-primary' : ''; let classProp = section.key.startsWith('propagation') ? 'tab-primary' : '';
return ( return (
<Nav.Item key={section.key}> <Nav.Item key={section.key}>
<Nav.Link className={classProp} eventKey={section.key}>{section.title}</Nav.Link> <Nav.Link className={classProp} eventKey={section.key}>{section.title}</Nav.Link>