gt-sanity 1.0.10 → 1.1.0
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.
- package/dist/index.js +125 -112
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +125 -112
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/adapter/getTranslation.ts +1 -1
- package/src/adapter/types.ts +12 -0
- package/src/components/TranslationsProvider.tsx +83 -58
- package/src/components/page/TranslationsTable.tsx +4 -2
- package/src/components/shared/SingleDocumentView.tsx +4 -2
- package/src/components/tab/TranslationView.tsx +26 -36
- package/src/translation/checkTranslationStatus.ts +7 -4
- package/src/translation/downloadTranslations.ts +13 -38
- package/src/translation/initProject.ts +8 -5
- package/src/utils/importUtils.ts +17 -37
package/dist/index.mjs
CHANGED
|
@@ -652,13 +652,17 @@ async function initProject(uploadResult, options, secrets) {
|
|
|
652
652
|
const { setupJobId } = setupResult, start = Date.now(), pollInterval = 2e3;
|
|
653
653
|
let setupCompleted = !1, setupFailedMessage = null;
|
|
654
654
|
for (; ; ) {
|
|
655
|
-
const status = await gt.
|
|
656
|
-
if (status
|
|
655
|
+
const status = await gt.checkJobStatus([setupJobId]);
|
|
656
|
+
if (!status[0]) {
|
|
657
|
+
setupFailedMessage = "Unknown error";
|
|
658
|
+
break;
|
|
659
|
+
}
|
|
660
|
+
if (status[0].status === "completed") {
|
|
657
661
|
setupCompleted = !0;
|
|
658
662
|
break;
|
|
659
663
|
}
|
|
660
|
-
if (status.status === "failed") {
|
|
661
|
-
setupFailedMessage = status.error?.message || "Unknown error";
|
|
664
|
+
if (status[0].status === "failed") {
|
|
665
|
+
setupFailedMessage = status[0].error?.message || "Unknown error";
|
|
662
666
|
break;
|
|
663
667
|
}
|
|
664
668
|
if (Date.now() - start > setupTimeoutMs) {
|
|
@@ -680,22 +684,20 @@ async function createJobs(uploadResult, localeIds, secrets) {
|
|
|
680
684
|
async function downloadTranslations(files, secrets, maxRetries = 3, retryDelay = 1e3) {
|
|
681
685
|
overrideConfig(secrets);
|
|
682
686
|
let retries = 0;
|
|
683
|
-
const fileIds = files.map((file) => file.translationId), map = new Map(files.map((file) => [file.translationId, file])), result = [];
|
|
684
687
|
for (; retries <= maxRetries; )
|
|
685
688
|
try {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
})
|
|
693
|
-
|
|
694
|
-
return result;
|
|
689
|
+
return (await gt.downloadFileBatch(
|
|
690
|
+
files.map((file) => ({
|
|
691
|
+
fileId: file.fileId,
|
|
692
|
+
branchId: file.branchId,
|
|
693
|
+
versionId: file.versionId,
|
|
694
|
+
locale: file.locale
|
|
695
|
+
}))
|
|
696
|
+
)).files || [];
|
|
695
697
|
} catch {
|
|
696
698
|
retries++, await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
697
699
|
}
|
|
698
|
-
return
|
|
700
|
+
return [];
|
|
699
701
|
}
|
|
700
702
|
async function checkTranslationStatus(fileQueryData, downloadStatus, secrets) {
|
|
701
703
|
overrideConfig(secrets);
|
|
@@ -703,8 +705,10 @@ async function checkTranslationStatus(fileQueryData, downloadStatus, secrets) {
|
|
|
703
705
|
const currentQueryData = fileQueryData.filter(
|
|
704
706
|
(item) => !downloadStatus.downloaded.has(`${item.fileId}:${item.locale}`) && !downloadStatus.failed.has(`${item.fileId}:${item.locale}`) && !downloadStatus.skipped.has(`${item.fileId}:${item.locale}`)
|
|
705
707
|
);
|
|
706
|
-
return currentQueryData.length === 0 ? !0 : ((await gt.
|
|
707
|
-
|
|
708
|
+
return currentQueryData.length === 0 ? !0 : ((await gt.queryFileData({
|
|
709
|
+
translatedFiles: currentQueryData
|
|
710
|
+
})).translatedFiles || []).filter(
|
|
711
|
+
(translation) => translation.completedAt
|
|
708
712
|
);
|
|
709
713
|
} catch (error) {
|
|
710
714
|
return console.error("Error checking translation status", error), [];
|
|
@@ -1022,20 +1026,15 @@ async function processImportBatch(items, options = {}) {
|
|
|
1022
1026
|
successfulImports
|
|
1023
1027
|
};
|
|
1024
1028
|
}
|
|
1025
|
-
async function getReadyFilesForImport(
|
|
1029
|
+
async function getReadyFilesForImport(translationStatuses, options = {}) {
|
|
1026
1030
|
const { filterReadyFiles = () => !0 } = options, readyFiles = [];
|
|
1027
1031
|
for (const [key, status] of translationStatuses.entries())
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
versionId: document2._rev,
|
|
1035
|
-
translationId: status.translationId,
|
|
1036
|
-
locale
|
|
1037
|
-
});
|
|
1038
|
-
}
|
|
1032
|
+
status.isReady && filterReadyFiles(key, status) && readyFiles.push({
|
|
1033
|
+
fileId: status.fileData.fileId,
|
|
1034
|
+
versionId: status.fileData.versionId,
|
|
1035
|
+
branchId: status.fileData.branchId,
|
|
1036
|
+
locale: status.fileData.locale
|
|
1037
|
+
});
|
|
1039
1038
|
return readyFiles;
|
|
1040
1039
|
}
|
|
1041
1040
|
async function importTranslations(readyFiles, secrets, translationContext, options = {}) {
|
|
@@ -1043,13 +1042,13 @@ async function importTranslations(readyFiles, secrets, translationContext, optio
|
|
|
1043
1042
|
return { successCount: 0, failureCount: 0, successfulImports: [] };
|
|
1044
1043
|
const importItems = (await downloadTranslations(readyFiles, secrets)).map((file) => ({
|
|
1045
1044
|
docInfo: {
|
|
1046
|
-
documentId: file.
|
|
1047
|
-
versionId: file.
|
|
1045
|
+
documentId: file.fileId,
|
|
1046
|
+
versionId: file.versionId
|
|
1048
1047
|
},
|
|
1049
|
-
locale: file.
|
|
1048
|
+
locale: file.locale,
|
|
1050
1049
|
data: file.data,
|
|
1051
1050
|
translationContext,
|
|
1052
|
-
key: `${file.
|
|
1051
|
+
key: `${file.branchId}:${file.fileId}:${file.versionId}:${file.locale}`
|
|
1053
1052
|
})), result = await processImportBatch(importItems, {
|
|
1054
1053
|
onProgress: options.onProgress,
|
|
1055
1054
|
onItemSuccess: (item, key) => {
|
|
@@ -1104,7 +1103,7 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1104
1103
|
children,
|
|
1105
1104
|
singleDocument
|
|
1106
1105
|
}) => {
|
|
1107
|
-
const [isBusy, setIsBusy] = useState(!1), [documents, setDocuments] = useState([]), [locales, setLocales] = useState([]), [autoRefresh, setAutoRefresh] = useState(!1), [loadingDocuments, setLoadingDocuments] = useState(!1), [importProgress, setImportProgress] = useState({
|
|
1106
|
+
const [isBusy, setIsBusy] = useState(!1), [documents, setDocuments] = useState([]), [locales, setLocales] = useState([]), [autoRefresh, setAutoRefresh] = useState(!1), [autoImport, setAutoImport] = useState(!1), [autoPatchReferences, setAutoPatchReferences] = useState(!1), [autoPublish, setAutoPublish] = useState(!1), [loadingDocuments, setLoadingDocuments] = useState(!1), [importProgress, setImportProgress] = useState({
|
|
1108
1107
|
current: 0,
|
|
1109
1108
|
total: 0,
|
|
1110
1109
|
isImporting: !1
|
|
@@ -1118,7 +1117,7 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1118
1117
|
skipped: /* @__PURE__ */ new Set()
|
|
1119
1118
|
}), [translationStatuses, setTranslationStatuses] = useState(/* @__PURE__ */ new Map()), [isRefreshing, setIsRefreshing] = useState(!1), client = useClient(), schema = useSchema(), translationContext = { client, schema }, toast = useToast(), { loading: loadingSecrets, secrets } = useSecrets(
|
|
1120
1119
|
pluginConfig.getSecretsNamespace()
|
|
1121
|
-
), fetchDocuments = useCallback(async () => {
|
|
1120
|
+
), [branchId, setBranchId] = useState(void 0), fetchDocuments = useCallback(async () => {
|
|
1122
1121
|
setLoadingDocuments(!0);
|
|
1123
1122
|
try {
|
|
1124
1123
|
if (singleDocument) {
|
|
@@ -1216,13 +1215,10 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1216
1215
|
}
|
|
1217
1216
|
}
|
|
1218
1217
|
}, [secrets, documents, locales, schema]), handleImportAll = useCallback(async () => {
|
|
1219
|
-
if (!(!secrets || documents.length === 0)) {
|
|
1218
|
+
if (!(!secrets || documents.length === 0 || !branchId)) {
|
|
1220
1219
|
setIsBusy(!0);
|
|
1221
1220
|
try {
|
|
1222
|
-
const readyFiles = await getReadyFilesForImport(
|
|
1223
|
-
documents,
|
|
1224
|
-
translationStatuses
|
|
1225
|
-
);
|
|
1221
|
+
const readyFiles = await getReadyFilesForImport(translationStatuses);
|
|
1226
1222
|
if (readyFiles.length === 0) {
|
|
1227
1223
|
toast.push({
|
|
1228
1224
|
title: "No ready translations to import",
|
|
@@ -1279,13 +1275,15 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1279
1275
|
documents,
|
|
1280
1276
|
translationStatuses,
|
|
1281
1277
|
downloadStatus,
|
|
1282
|
-
translationContext
|
|
1283
|
-
|
|
1284
|
-
|
|
1278
|
+
translationContext,
|
|
1279
|
+
branchId
|
|
1280
|
+
]), getExistingTranslations = useCallback(
|
|
1281
|
+
async (documentIds, localeIds, branchId2) => {
|
|
1285
1282
|
const sourceLocale = pluginConfig.getSourceLocale(), existingMetadata = await client.fetch(`*[
|
|
1286
1283
|
_type == 'translation.metadata' &&
|
|
1287
1284
|
translations[_key == $sourceLocale][0].value._ref in $documentIds
|
|
1288
1285
|
] {
|
|
1286
|
+
_rev,
|
|
1289
1287
|
'sourceDocId': translations[_key == $sourceLocale][0].value._ref,
|
|
1290
1288
|
'existingTranslations': translations[_key in $localeIds]._key
|
|
1291
1289
|
}`, {
|
|
@@ -1293,40 +1291,28 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1293
1291
|
documentIds,
|
|
1294
1292
|
localeIds
|
|
1295
1293
|
}), existing = /* @__PURE__ */ new Set();
|
|
1296
|
-
existingMetadata.forEach((metadata) => {
|
|
1294
|
+
return existingMetadata.forEach((metadata) => {
|
|
1297
1295
|
metadata.existingTranslations?.forEach((localeId) => {
|
|
1298
|
-
localeId !== sourceLocale && existing.add(
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
const missing = /* @__PURE__ */ new Set();
|
|
1302
|
-
return documentIds.forEach((docId) => {
|
|
1303
|
-
localeIds.forEach((localeId) => {
|
|
1304
|
-
if (localeId !== sourceLocale) {
|
|
1305
|
-
const key = `${docId}:${localeId}`;
|
|
1306
|
-
existing.has(key) || missing.add(key);
|
|
1307
|
-
}
|
|
1296
|
+
localeId !== sourceLocale && existing.add(
|
|
1297
|
+
`${branchId2}:${metadata.sourceDocId}:${metadata._rev}:${localeId}`
|
|
1298
|
+
);
|
|
1308
1299
|
});
|
|
1309
|
-
}),
|
|
1300
|
+
}), existing;
|
|
1310
1301
|
},
|
|
1311
1302
|
[client]
|
|
1312
1303
|
), handleImportMissing = useCallback(async () => {
|
|
1313
|
-
if (!(!secrets || documents.length === 0)) {
|
|
1304
|
+
if (!(!secrets || documents.length === 0 || !branchId)) {
|
|
1314
1305
|
setIsBusy(!0);
|
|
1315
1306
|
try {
|
|
1316
1307
|
const availableLocaleIds = locales.filter((locale) => locale.enabled !== !1).map((locale) => locale.localeId), documentIds = documents.map(
|
|
1317
1308
|
(doc) => doc._id?.replace("drafts.", "") || doc._id
|
|
1318
|
-
),
|
|
1309
|
+
), existingTranslations2 = await getExistingTranslations(
|
|
1319
1310
|
documentIds,
|
|
1320
|
-
availableLocaleIds
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
translationStatuses,
|
|
1326
|
-
{
|
|
1327
|
-
filterReadyFiles: (key) => missingTranslations.has(key)
|
|
1328
|
-
}
|
|
1329
|
-
);
|
|
1311
|
+
availableLocaleIds,
|
|
1312
|
+
branchId
|
|
1313
|
+
), readyFiles = await getReadyFilesForImport(translationStatuses, {
|
|
1314
|
+
filterReadyFiles: (key) => !existingTranslations2.has(key)
|
|
1315
|
+
});
|
|
1330
1316
|
if (readyFiles.length === 0) {
|
|
1331
1317
|
toast.push({
|
|
1332
1318
|
title: "No missing translations to import",
|
|
@@ -1385,9 +1371,20 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1385
1371
|
translationStatuses,
|
|
1386
1372
|
downloadStatus,
|
|
1387
1373
|
translationContext,
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1374
|
+
getExistingTranslations,
|
|
1375
|
+
branchId
|
|
1376
|
+
]), handleGetBranchId = useCallback(
|
|
1377
|
+
async (secrets2) => {
|
|
1378
|
+
overrideConfig(secrets2);
|
|
1379
|
+
const defaultBranch = await gt.createBranch({
|
|
1380
|
+
branchName: "main",
|
|
1381
|
+
defaultBranch: !0
|
|
1382
|
+
});
|
|
1383
|
+
setBranchId(defaultBranch.branch.id);
|
|
1384
|
+
},
|
|
1385
|
+
[secrets]
|
|
1386
|
+
), handleRefreshAll = useCallback(async () => {
|
|
1387
|
+
if (!(!secrets || documents.length === 0 || !branchId)) {
|
|
1391
1388
|
setIsRefreshing(!0);
|
|
1392
1389
|
try {
|
|
1393
1390
|
const availableLocaleIds = locales.filter((locale) => locale.enabled !== !1).map((locale) => locale.localeId), fileQueryData = [];
|
|
@@ -1397,6 +1394,7 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1397
1394
|
fileQueryData.push({
|
|
1398
1395
|
versionId: doc._rev,
|
|
1399
1396
|
fileId: documentId,
|
|
1397
|
+
branchId,
|
|
1400
1398
|
locale: localeId
|
|
1401
1399
|
});
|
|
1402
1400
|
}
|
|
@@ -1409,16 +1407,21 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1409
1407
|
const newStatuses = /* @__PURE__ */ new Map();
|
|
1410
1408
|
for (const doc of documents)
|
|
1411
1409
|
for (const localeId of availableLocaleIds) {
|
|
1412
|
-
const
|
|
1410
|
+
const documentId = doc._id?.replace("drafts.", "") || doc._id, versionId = doc._rev, key = `${branchId}:${documentId}:${versionId}:${localeId}`;
|
|
1413
1411
|
newStatuses.set(key, { progress: 0, isReady: !1 });
|
|
1414
1412
|
}
|
|
1415
1413
|
if (Array.isArray(readyTranslations))
|
|
1416
1414
|
for (const translation of readyTranslations) {
|
|
1417
|
-
const key = `${translation.fileId}:${translation.locale}`;
|
|
1415
|
+
const key = `${branchId}:${translation.fileId}:${translation.versionId}:${translation.locale}`;
|
|
1418
1416
|
newStatuses.set(key, {
|
|
1419
1417
|
progress: 100,
|
|
1420
1418
|
isReady: !0,
|
|
1421
|
-
|
|
1419
|
+
fileData: {
|
|
1420
|
+
versionId: translation.versionId,
|
|
1421
|
+
fileId: translation.fileId,
|
|
1422
|
+
branchId: translation.branchId,
|
|
1423
|
+
locale: translation.locale
|
|
1424
|
+
}
|
|
1422
1425
|
});
|
|
1423
1426
|
}
|
|
1424
1427
|
return newStatuses;
|
|
@@ -1437,11 +1440,11 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1437
1440
|
setIsRefreshing(!1);
|
|
1438
1441
|
}
|
|
1439
1442
|
}
|
|
1440
|
-
}, [secrets, documents, locales]), handleImportDocument = useCallback(
|
|
1441
|
-
async (documentId, localeId) => {
|
|
1443
|
+
}, [secrets, documents, locales, branchId]), handleImportDocument = useCallback(
|
|
1444
|
+
async (documentId, versionId, localeId) => {
|
|
1442
1445
|
if (!secrets) return;
|
|
1443
|
-
const key = `${documentId}:${localeId}`, status = translationStatuses.get(key);
|
|
1444
|
-
if (!status?.isReady || !status.
|
|
1446
|
+
const key = `${branchId}:${documentId}:${versionId}:${localeId}`, status = translationStatuses.get(key);
|
|
1447
|
+
if (!status?.isReady || !status.fileData) {
|
|
1445
1448
|
toast.push({
|
|
1446
1449
|
title: `Translation not ready for ${documentId} (${localeId})`,
|
|
1447
1450
|
status: "warning",
|
|
@@ -1464,10 +1467,10 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1464
1467
|
const downloadedFiles = await downloadTranslations(
|
|
1465
1468
|
[
|
|
1466
1469
|
{
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
locale:
|
|
1470
|
+
fileId: status.fileData.fileId,
|
|
1471
|
+
branchId: status.fileData.branchId,
|
|
1472
|
+
versionId: status.fileData.versionId,
|
|
1473
|
+
locale: status.fileData.locale
|
|
1471
1474
|
}
|
|
1472
1475
|
],
|
|
1473
1476
|
secrets
|
|
@@ -1513,7 +1516,7 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1513
1516
|
});
|
|
1514
1517
|
}
|
|
1515
1518
|
},
|
|
1516
|
-
[secrets, documents, translationContext, translationStatuses]
|
|
1519
|
+
[secrets, documents, translationContext, translationStatuses, branchId]
|
|
1517
1520
|
), handlePatchDocumentReferences = useCallback(async () => {
|
|
1518
1521
|
if (!secrets || documents.length === 0) return 0;
|
|
1519
1522
|
setIsBusy(!0);
|
|
@@ -1588,7 +1591,7 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1588
1591
|
} finally {
|
|
1589
1592
|
setIsBusy(!1), setImportProgress({ current: 0, total: 0, isImporting: !1 });
|
|
1590
1593
|
}
|
|
1591
|
-
}, [secrets, documents, locales, client]), handlePublishAllTranslations = useCallback(async () => {
|
|
1594
|
+
}, [secrets, documents, locales, client, branchId]), handlePublishAllTranslations = useCallback(async () => {
|
|
1592
1595
|
if (!secrets || documents.length === 0) return 0;
|
|
1593
1596
|
setIsBusy(!0);
|
|
1594
1597
|
try {
|
|
@@ -1640,7 +1643,7 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1640
1643
|
} finally {
|
|
1641
1644
|
setIsBusy(!1);
|
|
1642
1645
|
}
|
|
1643
|
-
}, [secrets, documents, client]);
|
|
1646
|
+
}, [secrets, documents, client, branchId]);
|
|
1644
1647
|
useEffect(() => {
|
|
1645
1648
|
fetchDocuments();
|
|
1646
1649
|
}, [fetchDocuments]), useEffect(() => {
|
|
@@ -1657,13 +1660,16 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1657
1660
|
return () => clearInterval(interval);
|
|
1658
1661
|
}, [autoRefresh, documents.length, secrets, handleRefreshAll]), useEffect(() => {
|
|
1659
1662
|
setImportedTranslations(new Set(downloadStatus.downloaded));
|
|
1660
|
-
}, [downloadStatus.downloaded]);
|
|
1663
|
+
}, [downloadStatus.downloaded]), secrets && handleGetBranchId(secrets);
|
|
1661
1664
|
const contextValue = {
|
|
1662
1665
|
// State
|
|
1663
1666
|
isBusy,
|
|
1664
1667
|
documents,
|
|
1665
1668
|
locales,
|
|
1666
1669
|
autoRefresh,
|
|
1670
|
+
autoImport,
|
|
1671
|
+
autoPatchReferences,
|
|
1672
|
+
autoPublish,
|
|
1667
1673
|
loadingDocuments,
|
|
1668
1674
|
importProgress,
|
|
1669
1675
|
importedTranslations,
|
|
@@ -1673,9 +1679,13 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
|
|
|
1673
1679
|
isRefreshing,
|
|
1674
1680
|
loadingSecrets,
|
|
1675
1681
|
secrets,
|
|
1682
|
+
branchId,
|
|
1676
1683
|
// Actions
|
|
1677
1684
|
setLocales,
|
|
1678
1685
|
setAutoRefresh,
|
|
1686
|
+
setAutoImport,
|
|
1687
|
+
setAutoPatchReferences,
|
|
1688
|
+
setAutoPublish,
|
|
1679
1689
|
handleTranslateAll,
|
|
1680
1690
|
handleImportAll,
|
|
1681
1691
|
handleImportMissing,
|
|
@@ -2939,6 +2949,7 @@ const WrapText = dt(Box)`
|
|
|
2939
2949
|
documents,
|
|
2940
2950
|
locales,
|
|
2941
2951
|
translationStatuses,
|
|
2952
|
+
branchId,
|
|
2942
2953
|
isBusy,
|
|
2943
2954
|
handleTranslateAll,
|
|
2944
2955
|
handleImportDocument,
|
|
@@ -2947,8 +2958,16 @@ const WrapText = dt(Box)`
|
|
|
2947
2958
|
importedTranslations,
|
|
2948
2959
|
setLocales,
|
|
2949
2960
|
handlePatchDocumentReferences,
|
|
2950
|
-
handlePublishAllTranslations
|
|
2951
|
-
|
|
2961
|
+
handlePublishAllTranslations,
|
|
2962
|
+
autoRefresh,
|
|
2963
|
+
setAutoRefresh,
|
|
2964
|
+
autoImport,
|
|
2965
|
+
setAutoImport,
|
|
2966
|
+
autoPatchReferences,
|
|
2967
|
+
setAutoPatchReferences,
|
|
2968
|
+
autoPublish,
|
|
2969
|
+
setAutoPublish
|
|
2970
|
+
} = useTranslations(), [isImporting, setIsImporting] = useState(!1), [isPublishing, setIsPublishing] = useState(!1), toast = useToast(), document2 = documents[0], currentDocumentLanguage = useMemo(() => {
|
|
2952
2971
|
if (!document2) return null;
|
|
2953
2972
|
const languageField = pluginConfig.getLanguageField();
|
|
2954
2973
|
return document2[languageField] || pluginConfig.getSourceLocale();
|
|
@@ -2962,7 +2981,7 @@ const WrapText = dt(Box)`
|
|
|
2962
2981
|
const { autoOnly = !1 } = options;
|
|
2963
2982
|
if (isImporting || !documentId || autoOnly && !autoImport) return;
|
|
2964
2983
|
const readyTranslations = availableLocales.filter((locale) => {
|
|
2965
|
-
const key = `${documentId}:${locale.localeId}`;
|
|
2984
|
+
const key = `${branchId}:${documentId}:${document2._rev}:${locale.localeId}`;
|
|
2966
2985
|
return translationStatuses.get(key)?.isReady && !importedTranslations.has(key);
|
|
2967
2986
|
});
|
|
2968
2987
|
if (readyTranslations.length !== 0) {
|
|
@@ -2970,7 +2989,7 @@ const WrapText = dt(Box)`
|
|
|
2970
2989
|
try {
|
|
2971
2990
|
await Promise.all(
|
|
2972
2991
|
readyTranslations.map(
|
|
2973
|
-
(locale) => handleImportDocument(documentId, locale.localeId)
|
|
2992
|
+
(locale) => handleImportDocument(documentId, document2._rev, locale.localeId)
|
|
2974
2993
|
)
|
|
2975
2994
|
), autoPatchReferences && await handlePatchDocumentReferences(), autoPublish && await handlePublishAllTranslations();
|
|
2976
2995
|
} finally {
|
|
@@ -2996,20 +3015,8 @@ const WrapText = dt(Box)`
|
|
|
2996
3015
|
useEffect(() => {
|
|
2997
3016
|
handleImportTranslations({ autoOnly: !0 });
|
|
2998
3017
|
}, [handleImportTranslations]), useEffect(() => {
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
await handleRefreshAll(), await handleImportTranslations({ autoOnly: !0 });
|
|
3002
|
-
}, 1e4);
|
|
3003
|
-
return () => clearInterval(interval);
|
|
3004
|
-
}, [
|
|
3005
|
-
autoRefresh,
|
|
3006
|
-
documentId,
|
|
3007
|
-
availableLocales.length,
|
|
3008
|
-
handleRefreshAll,
|
|
3009
|
-
handleImportTranslations
|
|
3010
|
-
]), useEffect(() => {
|
|
3011
|
-
(async () => (await handleRefreshAll(), await handleImportTranslations({ autoOnly: !0 })))();
|
|
3012
|
-
}, []);
|
|
3018
|
+
setAutoRefresh(!0), setAutoPatchReferences(!0), setAutoPublish(!0);
|
|
3019
|
+
}, [setAutoRefresh, setAutoPatchReferences, setAutoPublish]);
|
|
3013
3020
|
const toggleLocale = useCallback(
|
|
3014
3021
|
(localeId, shouldEnable) => {
|
|
3015
3022
|
const updatedLocales = locales.map(
|
|
@@ -3089,13 +3096,13 @@ const WrapText = dt(Box)`
|
|
|
3089
3096
|
padding: 2,
|
|
3090
3097
|
text: "Refresh Status",
|
|
3091
3098
|
onClick: handleRefreshAll,
|
|
3092
|
-
disabled: isRefreshing
|
|
3099
|
+
disabled: isRefreshing || isBusy
|
|
3093
3100
|
}
|
|
3094
3101
|
)
|
|
3095
3102
|
] })
|
|
3096
3103
|
] }),
|
|
3097
3104
|
/* @__PURE__ */ jsx(Box, { children: availableLocales.map((locale) => {
|
|
3098
|
-
const key = `${documentId}:${locale.localeId}`, status = translationStatuses.get(key), progress = status?.progress || 0, isImported = importedTranslations.has(key);
|
|
3105
|
+
const key = `${branchId}:${documentId}:${document2._rev}:${locale.localeId}`, status = translationStatuses.get(key), progress = status?.progress || 0, isImported = importedTranslations.has(key);
|
|
3099
3106
|
return /* @__PURE__ */ jsx(
|
|
3100
3107
|
LanguageStatus,
|
|
3101
3108
|
{
|
|
@@ -3103,7 +3110,11 @@ const WrapText = dt(Box)`
|
|
|
3103
3110
|
progress,
|
|
3104
3111
|
isImported,
|
|
3105
3112
|
importFile: async () => {
|
|
3106
|
-
!isImported && status?.isReady && await handleImportDocument(
|
|
3113
|
+
!isImported && status?.isReady && await handleImportDocument(
|
|
3114
|
+
documentId,
|
|
3115
|
+
document2._rev,
|
|
3116
|
+
locale.localeId
|
|
3117
|
+
);
|
|
3107
3118
|
}
|
|
3108
3119
|
},
|
|
3109
3120
|
key
|
|
@@ -3121,7 +3132,7 @@ const WrapText = dt(Box)`
|
|
|
3121
3132
|
text: isImporting ? "Importing..." : "Import All",
|
|
3122
3133
|
icon: DownloadIcon,
|
|
3123
3134
|
disabled: isImporting || availableLocales.every((locale) => {
|
|
3124
|
-
const key = `${documentId}:${locale.localeId}`;
|
|
3135
|
+
const key = `${branchId}:${documentId}:${document2._rev}:${locale.localeId}`;
|
|
3125
3136
|
return !translationStatuses.get(key)?.isReady || importedTranslations.has(key);
|
|
3126
3137
|
}),
|
|
3127
3138
|
style: { minWidth: "180px" }
|
|
@@ -3143,12 +3154,12 @@ const WrapText = dt(Box)`
|
|
|
3143
3154
|
"Imported",
|
|
3144
3155
|
" ",
|
|
3145
3156
|
availableLocales.filter((locale) => {
|
|
3146
|
-
const key = `${documentId}:${locale.localeId}`;
|
|
3157
|
+
const key = `${branchId}:${documentId}:${document2._rev}:${locale.localeId}`;
|
|
3147
3158
|
return importedTranslations.has(key);
|
|
3148
3159
|
}).length,
|
|
3149
3160
|
"/",
|
|
3150
3161
|
availableLocales.filter((locale) => {
|
|
3151
|
-
const key = `${documentId}:${locale.localeId}`;
|
|
3162
|
+
const key = `${branchId}:${documentId}:${document2._rev}:${locale.localeId}`;
|
|
3152
3163
|
return translationStatuses.get(key)?.isReady;
|
|
3153
3164
|
}).length
|
|
3154
3165
|
] })
|
|
@@ -3260,7 +3271,8 @@ const WrapText = dt(Box)`
|
|
|
3260
3271
|
translationStatuses,
|
|
3261
3272
|
downloadStatus,
|
|
3262
3273
|
importedTranslations,
|
|
3263
|
-
handleImportDocument
|
|
3274
|
+
handleImportDocument,
|
|
3275
|
+
branchId
|
|
3264
3276
|
} = useTranslations();
|
|
3265
3277
|
return loadingDocuments ? /* @__PURE__ */ jsx(Flex, { align: "center", justify: "center", padding: 4, children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsx(Box, { style: { maxHeight: "60vh", overflowY: "auto" }, children: /* @__PURE__ */ jsx(Stack, { space: 2, children: documents.map((document2) => /* @__PURE__ */ jsx(Card, { shadow: 1, padding: 3, children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
3266
3278
|
/* @__PURE__ */ jsx(Flex, { justify: "space-between", align: "flex-start", children: /* @__PURE__ */ jsxs(Box, { flex: 1, children: [
|
|
@@ -3268,7 +3280,7 @@ const WrapText = dt(Box)`
|
|
|
3268
3280
|
/* @__PURE__ */ jsx(Text, { size: 0, muted: !0, style: { marginTop: "2px" }, children: document2._type })
|
|
3269
3281
|
] }) }),
|
|
3270
3282
|
/* @__PURE__ */ jsx(Stack, { space: 2, children: locales.length > 0 ? locales.filter((locale) => locale.enabled !== !1).map((locale) => {
|
|
3271
|
-
const documentId = document2._id?.replace("drafts.", "") || document2._id, key = `${documentId}:${locale.localeId}`, status = translationStatuses.get(key), isDownloaded = downloadStatus.downloaded.has(key), isImported = importedTranslations.has(key);
|
|
3283
|
+
const documentId = document2._id?.replace("drafts.", "") || document2._id, key = `${branchId}:${documentId}:${document2._rev}:${locale.localeId}`, status = translationStatuses.get(key), isDownloaded = downloadStatus.downloaded.has(key), isImported = importedTranslations.has(key);
|
|
3272
3284
|
return /* @__PURE__ */ jsx(
|
|
3273
3285
|
LanguageStatus,
|
|
3274
3286
|
{
|
|
@@ -3278,11 +3290,12 @@ const WrapText = dt(Box)`
|
|
|
3278
3290
|
importFile: async () => {
|
|
3279
3291
|
await handleImportDocument(
|
|
3280
3292
|
documentId,
|
|
3293
|
+
document2._rev,
|
|
3281
3294
|
locale.localeId
|
|
3282
3295
|
);
|
|
3283
3296
|
}
|
|
3284
3297
|
},
|
|
3285
|
-
`${document2._id}-${locale.localeId}`
|
|
3298
|
+
`${document2._id}-${document2._rev}-${locale.localeId}`
|
|
3286
3299
|
);
|
|
3287
3300
|
}) : /* @__PURE__ */ jsx(Text, { size: 1, muted: !0, children: "No locales configured" }) })
|
|
3288
3301
|
] }) }, document2._id)) }) });
|