Make sure (1) config is updated before exporting; (2) plaintext config is exported correctly

This commit is contained in:
Shreya 2021-06-01 12:52:37 +05:30 committed by VakarisZ
parent f4b5d341cf
commit d67e84a6a7
2 changed files with 8 additions and 4 deletions

View File

@ -38,7 +38,8 @@ const ConfigExportModal = (props: Props) => {
.then(res => { .then(res => {
let configToExport = res['to_export']; let configToExport = res['to_export'];
if (res['is_plaintext'] === true) { if (res['is_plaintext'] === true) {
const configAsBinary = new Blob([configToExport], {type: 'text/plain;charset=utf-8'}); const configAsBinary = new Blob([JSON.stringify(configToExport, null, 2)],
{type: 'text/plain;charset=utf-8'});
FileSaver.saveAs(configAsBinary, 'monkey.conf'); FileSaver.saveAs(configAsBinary, 'monkey.conf');
} }
else { else {

View File

@ -369,6 +369,11 @@ class ConfigurePageComponent extends AuthComponent {
this.authFetch(apiEndpoint, request_options); this.authFetch(apiEndpoint, request_options);
} }
exportConfig = () => {
this.updateConfigSection();
this.setState({showConfigExportModal: true});
};
sendConfig() { sendConfig() {
return ( return (
this.authFetch('/api/configuration/island', this.authFetch('/api/configuration/island',
@ -500,9 +505,7 @@ class ConfigurePageComponent extends AuthComponent {
Import config Import config
</button> </button>
<button type='button' <button type='button'
onClick={() => { onClick={this.exportConfig}
this.setState({showConfigExportModal: true})
}}
className='btn btn-info btn-lg' style={{margin: '5px'}}> className='btn btn-info btn-lg' style={{margin: '5px'}}>
Export config Export config
</button> </button>