Skip to content

Commit bdadaad

Browse files
Feature/1424 import export rules and settings (#30)
* add import/export rules and settings feature * update load samples
1 parent fc807bd commit bdadaad

File tree

9 files changed

+570
-374
lines changed

9 files changed

+570
-374
lines changed

audit-resolve.json

Lines changed: 328 additions & 328 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ml-testing-toolkit-ui",
3-
"version": "10.3.5",
3+
"version": "10.4.1",
44
"description": "Frontend UI for Mojaloop Testing Toolkit",
55
"main": "index.js",
66
"repository": {

src/views/outbound/OutboundRequest.jsx

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Header from "../../components/Headers/Header.jsx";
3434

3535
import { getServerConfig } from '../../utils/getConfig'
3636

37-
import { Input, Row, Col, Affix, Descriptions, Modal, Icon, message, Popover, Progress, Menu, Dropdown, Radio, Tabs, Table } from 'antd';
37+
import { Input, Row, Col, Affix, Descriptions, Modal, Icon, message, Popover, Progress, Menu, Dropdown, Radio, Tabs, Table, Collapse } from 'antd';
3838

3939
import axios from 'axios';
4040
import TestCaseEditor from './TestCaseEditor'
@@ -204,7 +204,7 @@ class OutboundRequest extends React.Component {
204204
loadSampleDialogVisible: false,
205205
loadSampleFiles: {},
206206
loadSampleChecked: {},
207-
loadSampleTypes: ['hub', 'dfsp', 'provisioning']
207+
loadSampleCollectionTypes: ['hub','dfsp','provisioning']
208208
};
209209
}
210210

@@ -223,14 +223,20 @@ class OutboundRequest extends React.Component {
223223
this.collectionFileSelector = buildFileSelector(true);
224224
this.environmentFileSelector = buildFileSelector();
225225
this.collectionFileSelector.addEventListener ('input', (e) => {
226-
if (e.target.files.length == 1) {
227-
this.handleImportCollectionFile(e.target.files[0])
228-
} else if (e.target.files.length > 1) {
229-
this.handleImportCollectionFileMulti(e.target.files)
226+
if (e.target.files) {
227+
if (e.target.files.length == 1) {
228+
this.handleImportCollectionFile(e.target.files[0])
229+
} else if (e.target.files.length > 1) {
230+
this.handleImportCollectionFileMulti(e.target.files)
231+
}
232+
this.collectionFileSelector.value = null
230233
}
231234
})
232235
this.environmentFileSelector.addEventListener ('input', (e) => {
233-
this.handleImportEnvironmentFile(e.target.files[0])
236+
if (e.target.files) {
237+
this.handleImportEnvironmentFile(e.target.files[0])
238+
this.environmentFileSelector.value = null
239+
}
234240
})
235241

236242
// const sampleTemplate = require('./sample1.json')
@@ -653,7 +659,7 @@ class OutboundRequest extends React.Component {
653659
this.state.loadSampleChecked.environment = null
654660
}
655661
const { apiBaseUrl } = getConfig()
656-
const resp = await axios.get(apiBaseUrl + '/api/outbound/samples/data', {
662+
const resp = await axios.get(apiBaseUrl + '/api/samples/load', {
657663
params: this.state.loadSampleChecked
658664
})
659665
if (resp.data.body.name) {
@@ -676,36 +682,57 @@ class OutboundRequest extends React.Component {
676682

677683
loadSampleContent = async () => {
678684
const { apiBaseUrl } = getConfig()
679-
for (const index in this.state.loadSampleTypes) {
680-
const type = this.state.loadSampleTypes[index]
681-
if (!this.state.loadSampleFiles[type]) {
682-
const resp = await axios.get(apiBaseUrl + `/api/outbound/samples?type=${type}`)
683-
this.state.loadSampleFiles[type] = resp.data.body
684-
this.state.loadSampleFiles[type].environments.push('none')
685+
if (!this.state.loadSampleCollections) {
686+
this.state.loadSampleCollections = {}
687+
for (const index in this.state.loadSampleCollectionTypes) {
688+
const resp = await axios.get(apiBaseUrl + `/api/samples/load/collections?type=${this.state.loadSampleCollectionTypes[index]}`)
689+
this.state.loadSampleCollections[this.state.loadSampleCollectionTypes[index]] = resp.data.body
685690
}
686691
}
692+
if (!this.state.loadSampleEnvironments) {
693+
const resp = await axios.get(apiBaseUrl + `/api/samples/load/environments`)
694+
resp.data.body.push('none')
695+
this.state.loadSampleEnvironments = resp.data.body
696+
}
687697
}
688698

689699
loadSampleCollections = (type) => {
690700
const collections = []
691-
if (this.state.loadSampleFiles[type]) {
692-
for (const i in this.state.loadSampleFiles[type].collections) {
693-
collections.push({key: i, collection: this.state.loadSampleFiles[type].collections[i]})
701+
if (this.state.loadSampleCollections && this.state.loadSampleCollections[type]) {
702+
for (const i in this.state.loadSampleCollections[type]) {
703+
collections.push({key: i, collection: this.state.loadSampleCollections[type][i]})
694704
}
695705
}
696706
return collections
697707
}
698708

699-
loadSampleEnvironments = (type) => {
709+
loadSampleEnvironments = () => {
700710
const environments = []
701-
if (this.state.loadSampleFiles[type]) {
702-
for (const i in this.state.loadSampleFiles[type].environments) {
703-
environments.push({key: i, environment: this.state.loadSampleFiles[type].environments[i]})
711+
if (this.state.loadSampleEnvironments) {
712+
for (const i in this.state.loadSampleEnvironments) {
713+
environments.push({key: i, environment: this.state.loadSampleEnvironments[i]})
704714
}
705715
}
706716
return environments
707717
}
708718

719+
loadSampleCollectionsTabContent = () => {
720+
return this.state.loadSampleCollectionTypes.map(type => {
721+
return (
722+
<Tabs.TabPane tab={type} key={type}>
723+
<Table
724+
rowSelection={{type: 'checkbox', selectedRowKeys: this.state.selectedCollections, onChange: (selectedRowKeys, selectedRows) => {
725+
this.setState({selectedCollections: selectedRowKeys})
726+
this.state.loadSampleChecked.collections = selectedRows.map(selectedRow => {return selectedRow.collection})
727+
}}}
728+
columns={[{title: 'Select all', dataIndex: 'collection', render: text => <a>{text}</a>}]}
729+
dataSource={this.loadSampleCollections(type)}
730+
/>
731+
</Tabs.TabPane>
732+
)
733+
})
734+
}
735+
709736
clearSampleSelectionState = () => {
710737
this.setState({selectedCollections: []})
711738
this.setState({selectedEnvironments: []})
@@ -910,6 +937,7 @@ class OutboundRequest extends React.Component {
910937
<Row>
911938
<Col span={8}>
912939
<Button color="primary" size="sm" onClick={async (e) => {
940+
913941
await this.loadSampleContent()
914942
this.setState({loadSampleDialogVisible: true})
915943
}}>
@@ -918,7 +946,7 @@ class OutboundRequest extends React.Component {
918946
<Modal
919947
title="Loaded Samples"
920948
visible={this.state.loadSampleDialogVisible}
921-
width='90%'
949+
width='50%'
922950
onOk={async () => {
923951
await this.handleLoadSample()
924952
this.clearSampleSelectionState()
@@ -929,11 +957,25 @@ class OutboundRequest extends React.Component {
929957
this.setState({loadSampleDialogVisible: false})
930958
}}
931959
>
932-
<Tabs defaultActiveKey={this.state.loadSampleTypes[0]} onChange={() => {
933-
this.clearSampleSelectionState()
934-
}}>
935-
{this.loadSampleTabContent()}
936-
</Tabs>
960+
<Collapse defaultActiveKey={['1']}>
961+
<Collapse.Panel header="Collections" key="1">
962+
<Tabs defaultActiveKey={this.state.loadSampleCollectionTypes[0]} onChange={() => {
963+
this.setState({selectedCollections: []})
964+
}}>
965+
{this.loadSampleCollectionsTabContent()}
966+
</Tabs>
967+
</Collapse.Panel>
968+
<Collapse.Panel header="Environments" key="2">
969+
<Table
970+
rowSelection={{type: 'radio', disabled: true, selectedRowKeys: this.state.selectedEnvironments, onChange: (selectedRowKeys, selectedRows) => {
971+
this.setState({selectedEnvironments: selectedRowKeys})
972+
this.state.loadSampleChecked.environment = selectedRows[0].environment
973+
}}}
974+
columns={[{dataIndex: 'environment', render: text => <a>{text}</a>}]}
975+
dataSource={this.loadSampleEnvironments()}
976+
/>
977+
</Collapse.Panel>
978+
</Collapse>
937979
</Modal>
938980
<Button
939981
color="success"

src/views/rules/RuleEditor.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
// core components
3434
import { Dropdown, DropdownButton } from 'react-bootstrap';
3535

36-
import { Select } from 'antd';
36+
import { Select, message } from 'antd';
3737

3838
import { JsonEditor as Editor } from 'jsoneditor-react';
3939
import 'jsoneditor-react/es/editor.min.css';
@@ -329,7 +329,12 @@ class RulesEditor extends React.Component {
329329
handleSave = () => {
330330
// const newJson = this.refs.editor.jsonEditor.get()
331331
// // this.setState( { curJson: [ ...newJson ]} )
332-
this.props.onSave(JSON.parse(this.getRule()))
332+
const rule = JSON.parse(this.getRule())
333+
if (!rule.event.type) {
334+
message.error(({ content: 'rule event type is required', key: 'ruleSaveProgress', duration: 4 }));
335+
return;
336+
}
337+
this.props.onSave(rule)
333338
}
334339

335340
apiVersionSelectHandler = (apiVersion) => {

src/views/rules/RulesCallback.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const { Option } = Select;
4141
const { SubMenu } = Menu;
4242
const { Panel } = Collapse;
4343

44-
4544
class RulesCallback extends React.Component {
4645

4746
constructor() {
@@ -236,7 +235,6 @@ class RulesCallback extends React.Component {
236235
message.success({ content: 'Activated', key: 'activateFileProgress', duration: 2 });
237236
}
238237

239-
240238
render() {
241239
var newFileName = ''
242240
var newFileNameErrorMessage = ''

src/views/rules/RulesResponse.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ const { Option } = Select;
4343
const { SubMenu } = Menu;
4444
const { Panel } = Collapse;
4545

46-
4746
class RulesResponse extends React.Component {
4847

4948
constructor() {
@@ -232,7 +231,6 @@ class RulesResponse extends React.Component {
232231
message.success({ content: 'Activated', key: 'activateFileProgress', duration: 2 });
233232
}
234233

235-
236234
render() {
237235
var newFileName = ''
238236
var newFileNameErrorMessage = ''

src/views/rules/RulesValidation.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const { Option } = Select;
4141
const { SubMenu } = Menu;
4242
const { Panel } = Collapse;
4343

44-
4544
class RulesValidation extends React.Component {
4645

4746
constructor() {
@@ -237,7 +236,6 @@ class RulesValidation extends React.Component {
237236
message.success({ content: 'Activated', key: 'activateFileProgress', duration: 2 });
238237
}
239238

240-
241239
render() {
242240
var newFileName = ''
243241
var newFileNameErrorMessage = ''

0 commit comments

Comments
 (0)