Skip to content

Commit

Permalink
Toggle all direct children from folder #1188
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagocarod committed Feb 28, 2024
1 parent a057c5b commit 537239d
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/desktop/src/renderer/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ export class AppComponent extends Logger implements OnInit {
if (payload.subject === 'route') {
this.environmentsService.toggleRoute(payload.subjectUUID);
}
if (payload.subject === 'folder') {
this.environmentsService.toggleFolder(payload.subjectUUID);
}
break;
case 'duplicateToEnv':
this.startEntityDuplicationToAnotherEnvironment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ export const FoldersContextMenu = (folderUUID: string): ContextMenuItem[] => [
icon: 'folder',
disabled: false
},
{
payload: {
subject: 'folder',
action: 'toggle',
subjectUUID: folderUUID
},
label: 'Toggle folder',
icon: 'power_settings_new',
disabled: false
},
{
payload: {
subject: 'folder',
Expand Down
15 changes: 15 additions & 0 deletions packages/desktop/src/renderer/app/services/environments.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,21 @@ export class EnvironmentsService extends Logger {
}
}

/**
* Enable and disable routes in a folder
*/
public toggleFolder(folderId: string | 'root') {
const activeEnvironment = this.store.getActiveEnvironment();
const selectedFolder = activeEnvironment.folders.find(
(folder) => folder.uuid === folderId
);
for (const child of selectedFolder.children) {
if (child.type === 'route') {
this.toggleRoute(child.uuid);
}
}
}

/**
* Update a folder and save it in the store
*/
Expand Down
124 changes: 124 additions & 0 deletions packages/desktop/test/data/mock-envs/basic-folder-2-routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"uuid": "c8cdc030-344f-452f-aec4-56ded95b440c",
"lastMigration": 32,
"name": "Basic folder 2 routes",
"endpointPrefix": "",
"latency": 0,
"port": 3003,
"hostname": "",
"folders": [
{
"uuid": "1a84ec8b-0179-437c-954d-1fe0ca5e08fc",
"name": "New folder",
"children": [
{
"type": "route",
"uuid": "8745c4cf-88bd-4960-8353-858ae80623a5"
},
{
"type": "route",
"uuid": "7cad788c-433f-404e-bd0f-ca0bef288492"
}
]
}
],
"routes": [
{
"uuid": "8745c4cf-88bd-4960-8353-858ae80623a5",
"type": "http",
"documentation": "",
"method": "get",
"endpoint": "test1",
"responses": [
{
"uuid": "6e9b4207-1aa4-4103-a051-9f50bb9a5b45",
"body": "{}",
"latency": 0,
"statusCode": 200,
"label": "",
"headers": [],
"bodyType": "INLINE",
"filePath": "",
"databucketID": "",
"sendFileAsBody": false,
"rules": [],
"rulesOperator": "OR",
"disableTemplating": false,
"fallbackTo404": false,
"default": true,
"crudKey": "id",
"callbacks": []
}
],
"responseMode": null
},
{
"uuid": "7cad788c-433f-404e-bd0f-ca0bef288492",
"type": "http",
"documentation": "",
"method": "get",
"endpoint": "test2",
"responses": [
{
"uuid": "637e0e82-682a-4735-8f82-384d340a33a4",
"body": "{}",
"latency": 0,
"statusCode": 200,
"label": "",
"headers": [],
"bodyType": "INLINE",
"filePath": "",
"databucketID": "",
"sendFileAsBody": false,
"rules": [],
"rulesOperator": "OR",
"disableTemplating": false,
"fallbackTo404": false,
"default": true,
"crudKey": "id",
"callbacks": []
}
],
"responseMode": null
}
],
"rootChildren": [
{
"type": "folder",
"uuid": "1a84ec8b-0179-437c-954d-1fe0ca5e08fc"
}
],
"proxyMode": false,
"proxyHost": "",
"proxyRemovePrefix": false,
"tlsOptions": {
"enabled": false,
"type": "CERT",
"pfxPath": "",
"certPath": "",
"keyPath": "",
"caPath": "",
"passphrase": ""
},
"cors": true,
"headers": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"proxyReqHeaders": [
{
"key": "",
"value": ""
}
],
"proxyResHeaders": [
{
"key": "",
"value": ""
}
],
"data": [],
"callbacks": []
}
3 changes: 2 additions & 1 deletion packages/desktop/test/libs/context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export enum ContextMenuFolderActions {
ADD_CRUD = 1,
ADD_HTTP = 2,
ADD_FOLDER = 3,
DELETE = 4
TOGGLE_FOLDER = 4,
DELETE = 5
}

class ContextMenu {
Expand Down
20 changes: 20 additions & 0 deletions packages/desktop/test/specs/folders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,24 @@ describe('Folders', () => {
await routes.assertRoutePaddingLevel(2, 1);
await routes.assertRoutePaddingLevel(3, 1);
});

it('should toggle all the routes inside the folder', async () => {
await environments.open('basic-folder-2-routes');
await contextMenu.open('routes', 1);
await contextMenu.getItem(4).click();
await $(
'.routes-menu .menu-list .nav-item .nav-link.active.route-disabled'
).waitForExist();
await utils.waitForAutosave();
await file.verifyObjectPropertyInFile(
'./tmp/storage/settings.json',
['disabledRoutes.c8cdc030-344f-452f-aec4-56ded95b440c.0'],
['8745c4cf-88bd-4960-8353-858ae80623a5']
);
await file.verifyObjectPropertyInFile(
'./tmp/storage/settings.json',
['disabledRoutes.c8cdc030-344f-452f-aec4-56ded95b440c.1'],
['7cad788c-433f-404e-bd0f-ca0bef288492']
);
});
});

0 comments on commit 537239d

Please sign in to comment.