Skip to content

Commit 909dc02

Browse files
authored
feat: refactor (#226)
* feat: refactor * fix: lint * chore: deps * chore: added code owner
1 parent ef93e17 commit 909dc02

14 files changed

+1930
-1377
lines changed

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## @global-owner1 and @global-owner2 will be requested for
55
## review when someone opens a pull request.
66
#* @global-owner1 @global-owner2
7-
* @vijayg10 @bushjames @elnyry-sam-k @kleyow @shashi165 @gibaros
7+
* @vijayg10 @bushjames @elnyry-sam-k @kleyow @shashi165 @gibaros @kalinkrustev
88
## Order is important; the last matching pattern takes the most
99
## precedence. When someone opens a pull request that only
1010
## modifies JS files, only @js-owner and not the global

audit-ci.jsonc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"GHSA-p3vf-v8qc-cwcr", // https://github.com/advisories/GHSA-p3vf-v8qc-cwcr
4040
"GHSA-3xgq-45jj-v275",
4141
"GHSA-76p7-773f-r4q5",
42-
"GHSA-vhxf-7vqr-mrjg"
42+
"GHSA-vhxf-7vqr-mrjg",
43+
"GHSA-hw8r-x6gr-5gjp"
4344
]
4445
}

package-lock.json

Lines changed: 110 additions & 103 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,29 @@
5959
]
6060
},
6161
"dependencies": {
62-
"@ant-design/colors": "^7.2.0",
63-
"@ant-design/icons": "^5.6.1",
62+
"@ant-design/colors": "^8.0.0",
63+
"@ant-design/icons": "^6.0.0",
6464
"@mojaloop/ml-testing-toolkit-shared-lib": "14.0.1",
6565
"@testing-library/jest-dom": "^5.11.5",
6666
"@testing-library/react": "^11.1.0",
6767
"@testing-library/user-event": "^12.1.10",
68-
"ace-builds": "^1.38.0",
68+
"ace-builds": "^1.39.1",
6969
"ajv": "^8.17.1",
7070
"antd": "^4.24.7",
7171
"array-move": "^4.0.0",
72-
"axios": "^1.7.9",
72+
"axios": "^1.8.4",
7373
"bootstrap": "^4.5.3",
7474
"brace": "^0.11.1",
75-
"core-js": "^3.40.0",
76-
"electron": "^34.2.0",
75+
"core-js": "^3.41.0",
76+
"electron": "^35.0.3",
7777
"idb-keyval": "^6.2.1",
7878
"js-file-download": "^0.4.12",
7979
"jsoneditor": "9.10.3",
8080
"jsoneditor-react": "^3.1.2",
8181
"jszip": "^3.10.1",
8282
"lodash": "^4.17.21",
8383
"mermaid": "9.1.7",
84-
"mobx": "^6.13.6",
84+
"mobx": "^6.13.7",
8585
"mock-json-schema": "^1.1.1",
8686
"moment": "^2.30.1",
8787
"react": "^17.0.1",
@@ -93,15 +93,15 @@
9393
"react-sortable-hoc": "^2.0.0",
9494
"redoc": "^2.1.3",
9595
"socket.io-client": "^4.8.1",
96-
"styled-components": "^6.1.15",
96+
"styled-components": "^6.1.16",
9797
"web-vitals": "^0.2.4"
9898
},
9999
"devDependencies": {
100100
"@types/markerclustererplus": "2.1.33",
101101
"@types/react": "16.8.7",
102102
"audit-ci": "^7.1.0",
103103
"eslint-config-airbnb-typescript": "^17.1.0",
104-
"npm-check-updates": "^17.1.14",
104+
"npm-check-updates": "^17.1.16",
105105
"replace": "^1.2.2",
106106
"standard-version": "^9.5.0"
107107
},

src/utils/nameConversions.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*****
2+
License
3+
--------------
4+
Copyright © 2020-2025 Mojaloop Foundation
5+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
10+
11+
Contributors
12+
--------------
13+
This is the official list of the Mojaloop project contributors for this file.
14+
Names of the original copyright holders (individuals or organizations)
15+
should be listed with a '*' in the first column. People who have
16+
contributed from an organization can be listed under the organization
17+
that actually holds the copyright for their contributions (see the
18+
Mojaloop Foundation for an example). Those individuals should have
19+
their names indented and be marked with a '-'. Email address can be added
20+
optionally within square brackets <email>.
21+
22+
* Mojaloop Foundation
23+
- Name Surname <[email protected]>
24+
25+
* Vijaya Kumar Guthi <[email protected]> (Original Author)
26+
--------------
27+
******/
28+
29+
export const generateShortName = name => {
30+
const MAX_LENGTH = 20;
31+
32+
// Remove special characters and replace spaces with dashes
33+
let sanitized = name.replace(/[^a-zA-Z0-9 ]/g, '').replace(/ +/g, '-');
34+
35+
// Trim to the maximum allowed length without splitting words unnecessarily
36+
if(sanitized.length <= MAX_LENGTH) {
37+
return sanitized;
38+
}
39+
40+
// Try to preserve whole words within the length limit
41+
let words = sanitized.split('-');
42+
let shortName = '';
43+
44+
for(let word of words) {
45+
if((shortName + (shortName ? '-' : '') + word).length > MAX_LENGTH) {
46+
break;
47+
}
48+
shortName += (shortName ? '-' : '') + word;
49+
}
50+
51+
// If shortName is empty, fallback to direct truncation
52+
if(!shortName) {
53+
shortName = sanitized.substring(0, MAX_LENGTH);
54+
}
55+
56+
return shortName;
57+
};

src/views/outbound/OutboundRequest.jsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import IterationRunner from './IterationRunner';
4343
import FileDownload from 'js-file-download';
4444
import FileManager from './FileManager.jsx';
4545
import EnvironmentManager from './EnvironmentManager';
46+
import { generateShortName } from '../../utils/nameConversions';
4647

4748
import { FolderParser, TraceHeaderUtils } from '@mojaloop/ml-testing-toolkit-shared-lib';
4849

@@ -396,7 +397,16 @@ class OutboundRequest extends React.Component {
396397
const { test_cases, ...remainingTestCaseProps } = template;
397398
let newTestCases = test_cases;
398399
if(test_cases) {
400+
const testCaseIds = new Set();
401+
let i = 0;
399402
newTestCases = test_cases.map(testCase => {
403+
// Check if testCase.id is unique, append a suffix if not
404+
let testCaseId = testCase.id;
405+
if(testCaseIds.has(testCase.id)) {
406+
testCaseId = testCase.id + '-' + i;
407+
i = i + 1;
408+
}
409+
testCaseIds.add(testCaseId);
400410
if(testCase.requests) {
401411
const { requests, ...remainingProps } = testCase;
402412
const newRequests = requests.map(item => {
@@ -408,9 +418,9 @@ class OutboundRequest extends React.Component {
408418
return newRequest;
409419
}
410420
});
411-
return { ...remainingProps, requests: newRequests };
421+
return { ...remainingProps, requests: newRequests, id: testCaseId };
412422
} else {
413-
return testCase;
423+
return { ...testCase, id: testCaseId };
414424
}
415425
});
416426
}
@@ -424,9 +434,8 @@ class OutboundRequest extends React.Component {
424434
if(!fileTemplate.test_cases) {
425435
fileTemplate.test_cases = [];
426436
}
427-
// Find highest request id to determine the new ID
428-
const maxId = +fileTemplate.test_cases.reduce(function (m, k) { return k.id > m ? k.id : m; }, 0);
429-
fileTemplate.test_cases.push({ id: maxId + 1, name: testCaseName, requests: [] });
437+
const shortName = generateShortName(testCaseName);
438+
fileTemplate.test_cases.push({ id: shortName, name: testCaseName, requests: [] });
430439
this.regenerateTemplate(this.state.additionalData);
431440
this.forceUpdate();
432441
this.autoSave = true;
@@ -522,8 +531,7 @@ class OutboundRequest extends React.Component {
522531
if(testCases[i].requests === undefined) {
523532
testCases[i].requests = [];
524533
}
525-
const testCaseRef = testCases[i];
526-
this.state.template.test_cases.push({ ...testCaseRef, id: i + 1 });
534+
this.state.template.test_cases.push(testCases[i]);
527535
}
528536
// this.state.template.test_cases = testCases.map((item, index) => { return { ...item, id: index + 1} })
529537
const folders = additionalData.selectedFiles.filter(x => x.slice((x.lastIndexOf('.') - 1 >>> 0) + 2) == '');
@@ -626,15 +634,12 @@ class OutboundRequest extends React.Component {
626634
if(fileSelected) {
627635
const fileTemplate = fileSelected.content;
628636

629-
// Find highest request id to determine the new ID
630-
const maxId = +fileTemplate.test_cases.reduce(function (m, k) { return k.id > m ? k.id : m; }, 0);
631-
632637
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
633638
const { id, name, ...otherProps } = fileTemplate.test_cases[testCaseIndex];
634639
// Deep copy other properties
635640
const clonedProps = JSON.parse(JSON.stringify(otherProps));
636641

637-
fileTemplate.test_cases.push({ id: maxId + 1, name: name + ' Copy', ...clonedProps });
642+
fileTemplate.test_cases.push({ id: id + '-copy', name: name + ' Copy', ...clonedProps });
638643

639644
this.regenerateTemplate(this.state.additionalData);
640645
this.forceUpdate();

0 commit comments

Comments
 (0)