@crowdin/app-project-module 0.40.0 → 0.41.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -318,6 +318,8 @@
318
318
  const JOB_TYPE = {
319
319
  updateCrowdin: 'updateCrowdin',
320
320
  updateIntegration: 'updateIntegration',
321
+ integrationSyncSettingsSave: 'integrationSyncSettingsSave',
322
+ crowdinSyncSettingsSave: 'crowdinSyncSettingsSave',
321
323
  };
322
324
 
323
325
  const JOB_STATUS = {
@@ -328,6 +330,11 @@
328
330
  finished: 'finished',
329
331
  };
330
332
 
333
+ const silentJobs = [
334
+ JOB_TYPE.integrationSyncSettingsSave,
335
+ JOB_TYPE.crowdinSyncSettingsSave,
336
+ ];
337
+
331
338
  const asyncJobs = {};
332
339
 
333
340
  let project = {};
@@ -410,16 +417,31 @@
410
417
  }
411
418
  return item;
412
419
  });
420
+
421
+ const appIntegrationFiles = appComponent.querySelector('#integration-files');
413
422
  if (hardReload) {
414
423
  appComponent.setIntegrationFilesData(tree);
415
- } else {
416
- appComponent.pushIntegrationFilesData(tree);
424
+ } else if (tree.length) {
425
+ appComponent.pushIntegrationFilesData(tree).then(() => {
426
+ appIntegrationFiles.getSelected().then(selection => {
427
+ selection = selection?.filter((node) => node);
428
+ if (!selection?.length) {
429
+ return;
430
+ }
431
+
432
+ const selectedIds = selection.map(({id}) => id);
433
+ tree.forEach((node) => {
434
+ selectedIds.includes(node.parent_id) && selectedIds.push(node.id);
435
+ });
436
+ appIntegrationFiles.setSelected(selectedIds);
437
+ });
438
+ });
417
439
  }
418
440
  {{#if integrationPagination}}
419
441
  if (stopPagination) {
420
- appComponent.querySelector('#integration-files').setAttribute('load-more-disabled', true);
442
+ appIntegrationFiles.setAttribute('load-more-disabled', true);
421
443
  } else {
422
- appComponent.querySelector('#integration-files').setAttribute('load-more-disabled', false);
444
+ appIntegrationFiles.setAttribute('load-more-disabled', false);
423
445
  }
424
446
  {{/if}}
425
447
  if (search) {
@@ -530,6 +552,12 @@
530
552
  case JOB_TYPE.updateIntegration:
531
553
  appComponent.setAttribute('is-to-integration-process', true);
532
554
  break;
555
+ case JOB_TYPE.crowdinSyncSettingsSave:
556
+ appComponent.setAttribute(`is-crowdin-sync-settings-in-progress`, true)
557
+ break;
558
+ case JOB_TYPE.integrationSyncSettingsSave:
559
+ appComponent.setAttribute(`is-integration-sync-settings-in-progress`, true)
560
+ break;
533
561
  default:
534
562
  }
535
563
 
@@ -575,6 +603,16 @@
575
603
  onFinally = (() => appComponent.setAttribute('is-to-integration-process', false));
576
604
  }
577
605
  break;
606
+ case JOB_TYPE.crowdinSyncSettingsSave:
607
+ if (!onFinally) {
608
+ onFinally = (() => appComponent.setAttribute(`is-crowdin-sync-settings-in-progress`, false));
609
+ }
610
+ break;
611
+ case JOB_TYPE.integrationSyncSettingsSave:
612
+ if (!onFinally) {
613
+ onFinally = (() => appComponent.setAttribute(`is-integration-sync-settings-in-progress`, false));
614
+ }
615
+ break;
578
616
  default:
579
617
  }
580
618
 
@@ -586,7 +624,7 @@
586
624
  const progress = isFailed || JOB_STATUS.finished === job.status ? 100 : job.progress;
587
625
  const info = JOB_STATUS.canceled === job.status ? `Cancelled\n${job.info || ''}` : job.info;
588
626
 
589
- pushJobs([ {
627
+ !silentJobs.find((type) => type === jobType) && pushJobs([ {
590
628
  id: job.id,
591
629
  title: job.title,
592
630
  progress,
@@ -610,7 +648,7 @@
610
648
  .catch((e) => {
611
649
  onFinally && onFinally();
612
650
 
613
- pushJobs([ {
651
+ !silentJobs.find((type) => type === jobType) && pushJobs([ {
614
652
  id: jobId,
615
653
  isFailed: true,
616
654
  } ]);
@@ -783,6 +821,18 @@
783
821
  document.body.addEventListener('crowdinDisableSync', disableCrowdinSync);
784
822
  document.body.addEventListener('integrationDisableSync', disableIntegrationSync);
785
823
 
824
+ function getIntegrationFoldersToExpand(allData, syncedFiles) {
825
+ return Array.isArray(allData)
826
+ ? allData.filter(
827
+ node => (node.node_type === folderType && !syncedFiles.find((syncedFile) => syncedFile.parent_id === node.id))
828
+ ).map(node => ({
829
+ ...node,
830
+ nodeType: node.node_type,
831
+ parentId: node.parent_id,
832
+ }))
833
+ : [];
834
+ }
835
+
786
836
  async function saveScheduleSync() {
787
837
  const newFile = scheduleModal.querySelector('#new-files').checked || false;
788
838
  const selectedFiles = scheduleModal.querySelector('#selected-files').checked || false;
@@ -792,13 +842,22 @@
792
842
  if (type === 'crowdin') {
793
843
  appComponent.setCrowdinScheduleSync(syncData, newFile, selectedFiles);
794
844
  const syncedFiles = await appComponent.getCrowdinScheduleSync(true);
795
- appComponent.setAttribute('is-crowdin-loading', true);
845
+ appComponent.setAttribute('is-crowdin-sync-settings-in-progress', true);
796
846
  updateSyncSettings(syncedFiles, 'schedule', 'crowdin');
797
847
  } else if (type === 'integration') {
798
848
  appComponent.setIntegrationScheduleSync(syncData, newFile, selectedFiles);
799
849
  const syncedFiles = await appComponent.getIntegrationScheduleSync(true);
800
- appComponent.setAttribute('is-integration-loading', true);
801
- updateSyncSettings(syncedFiles, 'schedule', 'integration');
850
+ appComponent.setAttribute('is-integration-sync-settings-in-progress', true);
851
+ {{#if integrationOneLevelFetching}}
852
+ updateSyncSettings(
853
+ syncedFiles,
854
+ 'schedule',
855
+ 'integration',
856
+ selectedFiles ? getIntegrationFoldersToExpand(syncData, syncedFiles) : [],
857
+ );
858
+ {{else}}
859
+ updateSyncSettings(syncedFiles, 'schedule', 'integration');
860
+ {{/if}}
802
861
  }
803
862
 
804
863
  scheduleModal.close();
@@ -861,8 +920,13 @@
861
920
  {{else}}
862
921
  const syncedFiles = await appComponent.getIntegrationScheduleSync();
863
922
  {{/if}}
864
- appComponent.setAttribute('is-integration-loading', true);
865
- updateSyncSettings(syncedFiles, 'schedule', 'integration');
923
+
924
+ appComponent.setAttribute('is-integration-sync-settings-in-progress', true);
925
+ {{#if integrationOneLevelFetching}}
926
+ updateSyncSettings(syncedFiles, 'schedule', 'integration', getIntegrationFoldersToExpand(e.detail, syncedFiles));
927
+ {{else}}
928
+ updateSyncSettings(syncedFiles, 'schedule', 'integration');
929
+ {{/if}}
866
930
  }
867
931
 
868
932
  async function setCrowdinScheduleSync(e) {
@@ -884,7 +948,7 @@
884
948
  {{else}}
885
949
  const syncedFiles = await appComponent.getCrowdinScheduleSync();
886
950
  {{/if}}
887
- appComponent.setAttribute('is-crowdin-loading', true);
951
+ appComponent.setAttribute('is-crowdin-sync-settings-in-progress', true);
888
952
  updateSyncSettings(syncedFiles, 'schedule', 'crowdin');
889
953
  }
890
954
 
@@ -893,7 +957,7 @@
893
957
  showToast('Select templates which will be pushed to Crowdin');
894
958
  return;
895
959
  }
896
- appComponent.setAttribute('is-integration-loading', true);
960
+ appComponent.setAttribute('is-integration-sync-settings-in-progress', true);
897
961
  {{#if syncNewElements.integration}}
898
962
  const syncedFiles = await appComponent.getIntegrationScheduleSync(true);
899
963
  {{else}}
@@ -908,7 +972,7 @@
908
972
  showToast('Select templates which will be pushed to Crowdin');
909
973
  return;
910
974
  }
911
- appComponent.setAttribute('is-crowdin-loading', true);
975
+ appComponent.setAttribute('is-crowdin-sync-settings-in-progress', true);
912
976
  {{#if syncNewElements.crowdin}}
913
977
  const syncedFiles = await appComponent.getCrowdinScheduleSync(true);
914
978
  {{else}}
@@ -918,16 +982,21 @@
918
982
  updateSyncSettings(syncedFiles, 'schedule', 'crowdin');
919
983
  }
920
984
 
921
- function updateSyncSettings(files, type, provider) {
985
+ function updateSyncSettings(files, type, provider, expandIntegrationFolders = []) {
922
986
  checkOrigin()
923
987
  .then(restParams => fetch('api/sync-settings' + restParams, {
924
988
  method: 'POST',
925
989
  headers: { 'Content-Type': 'application/json' },
926
- body: JSON.stringify({ files, type, provider })
990
+ body: JSON.stringify({ files, type, provider, expandIntegrationFolders })
927
991
  }))
928
992
  .then(checkResponse)
929
- .catch(e => catchRejection(e, 'Can\'t save schedule sync settings'))
930
- .finally(() => (appComponent.setAttribute(`is-${provider}-loading`, false)));
993
+ .then((res) => {
994
+ checkJob({
995
+ jobId: res?.jobId,
996
+ jobType: JOB_TYPE[`${provider}SyncSettingsSave`],
997
+ })
998
+ })
999
+ .catch(e => catchRejection(e, 'Can\'t save schedule sync settings'));
931
1000
  }
932
1001
  {{/or}}
933
1002
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.40.0",
3
+ "version": "0.41.1",
4
4
  "description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",
@@ -17,12 +17,13 @@
17
17
  "@aws-sdk/client-s3": "^3.423.0",
18
18
  "@aws-sdk/s3-request-presigner": "^3.484.0",
19
19
  "@crowdin/crowdin-apps-functions": "0.6.0",
20
- "@crowdin/logs-formatter": "^2.1.1",
20
+ "@crowdin/logs-formatter": "^2.1.3",
21
21
  "@godaddy/terminus": "^4.12.1",
22
22
  "amqplib": "^0.10.3",
23
23
  "crypto-js": "^4.2.0",
24
24
  "express": "4.18.2",
25
25
  "express-handlebars": "^5.3.5",
26
+ "lodash.uniqby": "^4.7.0",
26
27
  "mysql2": "^2.3.3",
27
28
  "node-cron": "^3.0.2",
28
29
  "pg": "^8.11.3",
@@ -35,27 +36,28 @@
35
36
  "@babel/preset-react": "^7.23.3",
36
37
  "@emotion/react": "^11.11.1",
37
38
  "@emotion/styled": "^11.11.0",
38
- "@mui/icons-material": "^5.15.2",
39
- "@mui/material": "^5.15.2",
40
- "@rjsf/core": "^5.15.1",
41
- "@rjsf/mui": "^5.15.1",
39
+ "@mui/icons-material": "^5.15.7",
40
+ "@mui/material": "^5.15.7",
41
+ "@rjsf/core": "^5.16.1",
42
+ "@rjsf/mui": "^5.16.1",
42
43
  "@rjsf/utils": "^5.15.1",
43
- "@rjsf/validator-ajv8": "^5.15.1",
44
+ "@rjsf/validator-ajv8": "^5.16.1",
44
45
  "@rollup/plugin-babel": "^6.0.4",
45
46
  "@rollup/plugin-commonjs": "^24.1.0",
46
47
  "@rollup/plugin-json": "^6.0.0",
47
- "@rollup/plugin-node-resolve": "^15.2.1",
48
+ "@rollup/plugin-node-resolve": "^15.2.3",
48
49
  "@rollup/plugin-replace": "^5.0.5",
49
50
  "@rollup/plugin-terser": "^0.4.3",
50
51
  "@types/amqplib": "^0.10.4",
51
52
  "@types/crypto-js": "^4.1.3",
52
- "@types/express": "4.17.18",
53
+ "@types/express": "4.17.21",
53
54
  "@types/express-handlebars": "^5.3.1",
54
55
  "@types/jest": "^29.5.5",
56
+ "@types/lodash.uniqby": "^4.7.9",
55
57
  "@types/node": "^16.18.69",
56
58
  "@types/node-cron": "^3.0.9",
57
59
  "@types/pg": "^8.10.3",
58
- "@types/swagger-jsdoc": "^6.0.1",
60
+ "@types/swagger-jsdoc": "^6.0.4",
59
61
  "@types/uuid": "^9.0.7",
60
62
  "@typescript-eslint/eslint-plugin": "^2.3.1",
61
63
  "@typescript-eslint/parser": "^2.3.1",