gt-sanity 1.0.2 → 1.0.4

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 CHANGED
@@ -1427,170 +1427,167 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
1427
1427
  }
1428
1428
  }, [secrets, documents, locales]), handleImportDocument = o.useCallback(
1429
1429
  async (documentId, localeId) => {
1430
- if (secrets)
1431
- try {
1432
- const key = `${documentId}:${localeId}`, status = translationStatuses.get(key);
1433
- if (!status?.isReady || !status.translationId) {
1434
- toast.push({
1435
- title: `Translation not ready for ${documentId} (${localeId})`,
1436
- status: "warning",
1430
+ if (!secrets) return;
1431
+ const key = `${documentId}:${localeId}`, status = translationStatuses.get(key);
1432
+ if (!status?.isReady || !status.translationId) {
1433
+ toast.push({
1434
+ title: `Translation not ready for ${documentId} (${localeId})`,
1435
+ status: "warning",
1436
+ closable: !0
1437
+ });
1438
+ return;
1439
+ }
1440
+ const document2 = documents.find(
1441
+ (doc) => (doc._id?.replace("drafts.", "") || doc._id) === documentId
1442
+ );
1443
+ if (!document2) {
1444
+ toast.push({
1445
+ title: `Document ${documentId} not found`,
1446
+ status: "error",
1447
+ closable: !0
1448
+ });
1449
+ return;
1450
+ }
1451
+ try {
1452
+ const downloadedFiles = await downloadTranslations(
1453
+ [
1454
+ {
1455
+ documentId,
1456
+ versionId: document2._rev,
1457
+ translationId: status.translationId,
1458
+ locale: localeId
1459
+ }
1460
+ ],
1461
+ secrets
1462
+ );
1463
+ if (downloadedFiles.length > 0)
1464
+ try {
1465
+ const docInfo = {
1466
+ documentId,
1467
+ versionId: document2._rev
1468
+ };
1469
+ await importDocument(
1470
+ docInfo,
1471
+ localeId,
1472
+ downloadedFiles[0].data,
1473
+ translationContext,
1474
+ !1
1475
+ ), setDownloadStatus((prev2) => ({
1476
+ ...prev2,
1477
+ downloaded: /* @__PURE__ */ new Set([...prev2.downloaded, key])
1478
+ })), setImportedTranslations((prev2) => /* @__PURE__ */ new Set([...prev2, key])), toast.push({
1479
+ title: `Successfully imported translation for ${documentId} (${localeId})`,
1480
+ status: "success",
1437
1481
  closable: !0
1438
1482
  });
1439
- return;
1440
- }
1441
- const document2 = documents.find(
1442
- (doc) => (doc._id?.replace("drafts.", "") || doc._id) === documentId
1443
- );
1444
- if (!document2) {
1445
- toast.push({
1446
- title: `Document ${documentId} not found`,
1483
+ } catch (importError) {
1484
+ console.error("Failed to import translation:", importError), toast.push({
1485
+ title: `Failed to import translation for ${documentId} (${localeId})`,
1447
1486
  status: "error",
1448
1487
  closable: !0
1449
1488
  });
1450
- return;
1451
1489
  }
1452
- const downloadedFiles = await downloadTranslations(
1453
- [
1454
- {
1455
- documentId,
1456
- versionId: document2._rev,
1457
- translationId: status.translationId,
1458
- locale: localeId
1459
- }
1460
- ],
1461
- secrets
1462
- );
1463
- if (downloadedFiles.length > 0)
1464
- try {
1465
- const docInfo = {
1466
- documentId,
1467
- versionId: document2._rev
1468
- };
1469
- await importDocument(
1470
- docInfo,
1471
- localeId,
1472
- downloadedFiles[0].data,
1473
- translationContext,
1474
- !1
1475
- ), setDownloadStatus((prev2) => ({
1476
- ...prev2,
1477
- downloaded: /* @__PURE__ */ new Set([...prev2.downloaded, key])
1478
- })), setImportedTranslations((prev2) => /* @__PURE__ */ new Set([...prev2, key])), toast.push({
1479
- title: `Successfully imported translation for ${documentId} (${localeId})`,
1480
- status: "success",
1481
- closable: !0
1482
- });
1483
- } catch (importError) {
1484
- console.error("Failed to import translation:", importError), toast.push({
1485
- title: `Failed to import translation for ${documentId} (${localeId})`,
1486
- status: "error",
1487
- closable: !0
1488
- });
1489
- }
1490
- else
1491
- toast.push({
1492
- title: `No translation content received for ${documentId}`,
1493
- status: "warning",
1494
- closable: !0
1495
- });
1496
- } catch (error) {
1497
- console.error("Error importing translation:", error), toast.push({
1498
- title: `Error importing translation for ${documentId}`,
1499
- status: "error",
1490
+ else
1491
+ toast.push({
1492
+ title: `No translation content received for ${documentId}`,
1493
+ status: "warning",
1500
1494
  closable: !0
1501
1495
  });
1502
- }
1503
- },
1504
- [secrets, documents, translationContext]
1505
- ), handlePatchDocumentReferences = o.useCallback(async () => {
1506
- if (!(!secrets || documents.length === 0)) {
1507
- setIsBusy(!0);
1508
- try {
1509
- const availableLocaleIds = locales.filter((locale) => locale.enabled !== !1).map((locale) => locale.localeId), patchTasks = [];
1510
- for (const doc of documents)
1511
- for (const localeId of availableLocaleIds)
1512
- patchTasks.push({ doc, localeId });
1513
- setImportProgress({
1514
- current: 0,
1515
- total: patchTasks.length,
1516
- isImporting: !0
1517
- });
1518
- const result = await processBatch(
1519
- patchTasks,
1520
- async ({ doc, localeId }) => {
1521
- const sourceLocale = pluginConfig.getSourceLocale();
1522
- if (localeId === sourceLocale)
1523
- return { patched: !1, doc, localeId, skipped: !0 };
1524
- const translatedDoc = await findTranslatedDocumentForLocale(
1525
- doc._id,
1526
- localeId,
1527
- client
1528
- );
1529
- if (!translatedDoc)
1530
- return { patched: !1, doc, localeId, noTranslation: !0 };
1531
- const resolvedDoc = await resolveRefs(
1532
- translatedDoc,
1533
- localeId,
1534
- client
1535
- );
1536
- if (resolvedDoc !== translatedDoc) {
1537
- const mutation = {
1538
- patch: {
1539
- id: translatedDoc._id,
1540
- set: resolvedDoc
1541
- }
1542
- };
1543
- return await client.mutate([mutation]), { patched: !0, doc: translatedDoc, localeId };
1544
- }
1545
- return { patched: !1, doc: translatedDoc, localeId };
1546
- },
1547
- {
1548
- onProgress: (current, total) => {
1549
- setImportProgress({
1550
- current,
1551
- total,
1552
- isImporting: !0
1553
- });
1554
- },
1555
- onItemFailure: ({ doc, localeId }, error) => {
1556
- console.error(
1557
- `Failed to patch references for ${doc._id} (${localeId}):`,
1558
- error
1559
- );
1560
- }
1561
- }
1562
- ), patchedCount = result.successfulItems.filter(
1563
- (item) => item.patched
1564
- ).length;
1565
- toast.push({
1566
- title: `Patched references in ${patchedCount} documents${result.failureCount > 0 ? `, ${result.failureCount} failed` : ""}`,
1567
- status: patchedCount > 0 || result.failureCount === 0 ? "success" : "error",
1568
- closable: !0
1569
- });
1570
1496
  } catch (error) {
1571
- console.error("Error patching document references:", error), toast.push({
1572
- title: "Error patching document references",
1497
+ console.error("Error importing translation:", error), toast.push({
1498
+ title: `Error importing translation for ${documentId}`,
1573
1499
  status: "error",
1574
1500
  closable: !0
1575
1501
  });
1576
- } finally {
1577
- setIsBusy(!1), setImportProgress({ current: 0, total: 0, isImporting: !1 });
1578
1502
  }
1503
+ },
1504
+ [secrets, documents, translationContext, translationStatuses]
1505
+ ), handlePatchDocumentReferences = o.useCallback(async () => {
1506
+ if (!secrets || documents.length === 0) return 0;
1507
+ setIsBusy(!0);
1508
+ try {
1509
+ const availableLocaleIds = locales.filter((locale) => locale.enabled !== !1).map((locale) => locale.localeId), patchTasks = [];
1510
+ for (const doc of documents)
1511
+ for (const localeId of availableLocaleIds)
1512
+ patchTasks.push({ doc, localeId });
1513
+ setImportProgress({
1514
+ current: 0,
1515
+ total: patchTasks.length,
1516
+ isImporting: !0
1517
+ });
1518
+ const result = await processBatch(
1519
+ patchTasks,
1520
+ async ({ doc, localeId }) => {
1521
+ const sourceLocale = pluginConfig.getSourceLocale();
1522
+ if (localeId === sourceLocale)
1523
+ return { patched: !1, doc, localeId, skipped: !0 };
1524
+ const translatedDoc = await findTranslatedDocumentForLocale(
1525
+ doc._id,
1526
+ localeId,
1527
+ client
1528
+ );
1529
+ if (!translatedDoc)
1530
+ return { patched: !1, doc, localeId, noTranslation: !0 };
1531
+ const resolvedDoc = await resolveRefs(
1532
+ translatedDoc,
1533
+ localeId,
1534
+ client
1535
+ );
1536
+ if (resolvedDoc !== translatedDoc) {
1537
+ const mutation = {
1538
+ patch: {
1539
+ id: translatedDoc._id,
1540
+ set: resolvedDoc
1541
+ }
1542
+ };
1543
+ return await client.mutate([mutation]), { patched: !0, doc: translatedDoc, localeId };
1544
+ }
1545
+ return { patched: !1, doc: translatedDoc, localeId };
1546
+ },
1547
+ {
1548
+ onProgress: (current, total) => {
1549
+ setImportProgress({
1550
+ current,
1551
+ total,
1552
+ isImporting: !0
1553
+ });
1554
+ },
1555
+ onItemFailure: ({ doc, localeId }, error) => {
1556
+ console.error(
1557
+ `Failed to patch references for ${doc._id} (${localeId}):`,
1558
+ error
1559
+ );
1560
+ }
1561
+ }
1562
+ ), patchedCount = result.successfulItems.filter(
1563
+ (item) => item.patched
1564
+ ).length;
1565
+ return toast.push({
1566
+ title: `Patched references in ${patchedCount} documents${result.failureCount > 0 ? `, ${result.failureCount} failed` : ""}`,
1567
+ status: patchedCount > 0 || result.failureCount === 0 ? "success" : "error",
1568
+ closable: !0
1569
+ }), patchedCount;
1570
+ } catch (error) {
1571
+ return console.error("Error patching document references:", error), toast.push({
1572
+ title: "Error patching document references",
1573
+ status: "error",
1574
+ closable: !0
1575
+ }), 0;
1576
+ } finally {
1577
+ setIsBusy(!1), setImportProgress({ current: 0, total: 0, isImporting: !1 });
1579
1578
  }
1580
1579
  }, [secrets, documents, locales, client]), handlePublishAllTranslations = o.useCallback(async () => {
1581
- if (!(!secrets || documents.length === 0)) {
1582
- setIsBusy(!0);
1583
- try {
1584
- const sourceLocale = pluginConfig.getSourceLocale(), publishedDocumentIds = documents.filter((doc) => !doc._id.startsWith("drafts.")).map((doc) => doc._id);
1585
- if (publishedDocumentIds.length === 0) {
1586
- toast.push({
1587
- title: "No published source documents found to publish translations for",
1588
- status: "warning",
1589
- closable: !0
1590
- });
1591
- return;
1592
- }
1593
- const translationMetadata = await client.fetch(`*[
1580
+ if (!secrets || documents.length === 0) return 0;
1581
+ setIsBusy(!0);
1582
+ try {
1583
+ const sourceLocale = pluginConfig.getSourceLocale(), publishedDocumentIds = documents.filter((doc) => !doc._id.startsWith("drafts.")).map((doc) => doc._id);
1584
+ if (publishedDocumentIds.length === 0)
1585
+ return toast.push({
1586
+ title: "No published source documents found to publish translations for",
1587
+ status: "warning",
1588
+ closable: !0
1589
+ }), 0;
1590
+ const translationMetadata = await client.fetch(`*[
1594
1591
  _type == 'translation.metadata' &&
1595
1592
  translations[_key == $sourceLocale][0].value._ref in $publishedDocumentIds
1596
1593
  ] {
@@ -1600,39 +1597,36 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
1600
1597
  'docId': value._ref
1601
1598
  }
1602
1599
  }`, {
1603
- sourceLocale,
1604
- publishedDocumentIds
1605
- }), translationDocIds = [];
1606
- if (translationMetadata.forEach((metadata) => {
1607
- metadata.translationDocs?.forEach((translation) => {
1608
- translation.docId && translationDocIds.push(translation.docId);
1609
- });
1610
- }), translationDocIds.length === 0) {
1611
- toast.push({
1612
- title: "No translation documents found to publish",
1613
- status: "warning",
1614
- closable: !0
1615
- });
1616
- return;
1617
- }
1618
- const translatedDocumentIds = await publishTranslations(
1619
- translationDocIds,
1620
- client
1621
- );
1622
- toast.push({
1623
- title: `Published ${translatedDocumentIds.length} translation documents`,
1624
- status: "success",
1625
- closable: !0
1600
+ sourceLocale,
1601
+ publishedDocumentIds
1602
+ }), translationDocIds = [];
1603
+ if (translationMetadata.forEach((metadata) => {
1604
+ metadata.translationDocs?.forEach((translation) => {
1605
+ translation.docId && translationDocIds.push(translation.docId);
1626
1606
  });
1627
- } catch (error) {
1628
- console.error("Error publishing translations:", error), toast.push({
1629
- title: "Error publishing translations",
1630
- status: "error",
1607
+ }), translationDocIds.length === 0)
1608
+ return toast.push({
1609
+ title: "No translation documents found to publish",
1610
+ status: "warning",
1631
1611
  closable: !0
1632
- });
1633
- } finally {
1634
- setIsBusy(!1);
1635
- }
1612
+ }), 0;
1613
+ const translatedDocumentIds = await publishTranslations(
1614
+ translationDocIds,
1615
+ client
1616
+ );
1617
+ return toast.push({
1618
+ title: `Published ${translatedDocumentIds.length} translation documents`,
1619
+ status: "success",
1620
+ closable: !0
1621
+ }), translatedDocumentIds.length;
1622
+ } catch (error) {
1623
+ return console.error("Error publishing translations:", error), toast.push({
1624
+ title: "Error publishing translations",
1625
+ status: "error",
1626
+ closable: !0
1627
+ }), 0;
1628
+ } finally {
1629
+ setIsBusy(!1);
1636
1630
  }
1637
1631
  }, [secrets, documents, client]);
1638
1632
  o.useEffect(() => {
@@ -2940,8 +2934,9 @@ const WrapText = dt(ui.Box)`
2940
2934
  isRefreshing,
2941
2935
  importedTranslations,
2942
2936
  setLocales,
2943
- handlePatchDocumentReferences
2944
- } = useTranslations(), [autoImport, setAutoImport] = o.useState(!1), [isImporting, setIsImporting] = o.useState(!1), [autoRefresh, setAutoRefresh] = o.useState(!0), document2 = documents[0], currentDocumentLanguage = o.useMemo(() => {
2937
+ handlePatchDocumentReferences,
2938
+ handlePublishAllTranslations
2939
+ } = useTranslations(), [autoImport, setAutoImport] = o.useState(!1), [isImporting, setIsImporting] = o.useState(!1), [autoRefresh, setAutoRefresh] = o.useState(!0), [autoPatchReferences, setAutoPatchReferences] = o.useState(!0), [autoPublish, setAutoPublish] = o.useState(!0), [isPublishing, setIsPublishing] = o.useState(!1), toast = ui.useToast(), document2 = documents[0], currentDocumentLanguage = o.useMemo(() => {
2945
2940
  if (!document2) return null;
2946
2941
  const languageField = pluginConfig.getLanguageField();
2947
2942
  return document2[languageField] || pluginConfig.getSourceLocale();
@@ -2950,57 +2945,48 @@ const WrapText = dt(ui.Box)`
2950
2945
  return locales.filter(
2951
2946
  (locale) => locale.enabled !== !1 && locale.localeId !== sourceLocale
2952
2947
  );
2953
- }, [locales]), documentId = o.useMemo(() => document2 ? document2._id?.replace("drafts.", "") || document2._id : null, [document2]), checkAndImportCompletedTranslations = o.useCallback(async () => {
2954
- if (!autoImport || isImporting || !documentId) return;
2955
- const completedTranslations = availableLocales.filter((locale) => {
2956
- const key = `${documentId}:${locale.localeId}`, status = translationStatuses.get(key);
2957
- return (status?.progress || 0) >= 100 && status?.isReady && !importedTranslations.has(key);
2958
- });
2959
- if (completedTranslations.length !== 0) {
2960
- setIsImporting(!0);
2961
- try {
2962
- for (const locale of completedTranslations)
2963
- await handleImportDocument(documentId, locale.localeId);
2964
- } finally {
2965
- setIsImporting(!1);
2966
- }
2967
- }
2968
- }, [
2969
- autoImport,
2970
- isImporting,
2971
- documentId,
2972
- availableLocales,
2973
- translationStatuses,
2974
- importedTranslations,
2975
- handleImportDocument
2976
- ]), handleImportAll = o.useCallback(async () => {
2977
- if (!(isImporting || !documentId)) {
2978
- setIsImporting(!0);
2979
- try {
2980
- const readyTranslations = availableLocales.filter((locale) => {
2981
- const key = `${documentId}:${locale.localeId}`;
2982
- return translationStatuses.get(key)?.isReady && !importedTranslations.has(key);
2983
- });
2984
- for (const locale of readyTranslations)
2985
- await handleImportDocument(documentId, locale.localeId);
2986
- } finally {
2987
- setIsImporting(!1);
2948
+ }, [locales]), documentId = o.useMemo(() => document2 ? document2._id?.replace("drafts.", "") || document2._id : null, [document2]), handleImportTranslations = o.useCallback(
2949
+ async (options = {}) => {
2950
+ const { autoOnly = !1 } = options;
2951
+ if (isImporting || !documentId || autoOnly && !autoImport) return;
2952
+ const readyTranslations = availableLocales.filter((locale) => {
2953
+ const key = `${documentId}:${locale.localeId}`;
2954
+ return translationStatuses.get(key)?.isReady && !importedTranslations.has(key);
2955
+ });
2956
+ if (readyTranslations.length !== 0) {
2957
+ setIsImporting(!0);
2958
+ try {
2959
+ await Promise.all(
2960
+ readyTranslations.map(
2961
+ (locale) => handleImportDocument(documentId, locale.localeId)
2962
+ )
2963
+ ), autoPatchReferences && await handlePatchDocumentReferences(), autoPublish && await handlePublishAllTranslations();
2964
+ } finally {
2965
+ setIsImporting(!1);
2966
+ }
2988
2967
  }
2989
- }
2990
- }, [
2991
- isImporting,
2992
- documentId,
2993
- availableLocales,
2994
- translationStatuses,
2995
- importedTranslations,
2996
- handleImportDocument
2997
- ]);
2968
+ },
2969
+ [
2970
+ autoImport,
2971
+ isImporting,
2972
+ documentId,
2973
+ availableLocales,
2974
+ translationStatuses,
2975
+ importedTranslations,
2976
+ handleImportDocument,
2977
+ autoPatchReferences,
2978
+ handlePatchDocumentReferences,
2979
+ autoPublish,
2980
+ handlePublishAllTranslations,
2981
+ toast
2982
+ ]
2983
+ );
2998
2984
  o.useEffect(() => {
2999
- checkAndImportCompletedTranslations();
3000
- }, [checkAndImportCompletedTranslations]), o.useEffect(() => {
2985
+ handleImportTranslations({ autoOnly: !0 });
2986
+ }, [handleImportTranslations]), o.useEffect(() => {
3001
2987
  if (!autoRefresh || !documentId || availableLocales.length === 0) return;
3002
2988
  const interval = setInterval(async () => {
3003
- await handleRefreshAll(), await checkAndImportCompletedTranslations();
2989
+ await handleRefreshAll(), await handleImportTranslations({ autoOnly: !0 });
3004
2990
  }, 1e4);
3005
2991
  return () => clearInterval(interval);
3006
2992
  }, [
@@ -3008,9 +2994,9 @@ const WrapText = dt(ui.Box)`
3008
2994
  documentId,
3009
2995
  availableLocales.length,
3010
2996
  handleRefreshAll,
3011
- checkAndImportCompletedTranslations
2997
+ handleImportTranslations
3012
2998
  ]), o.useEffect(() => {
3013
- (async () => (await handleRefreshAll(), await checkAndImportCompletedTranslations()))();
2999
+ (async () => (await handleRefreshAll(), await handleImportTranslations({ autoOnly: !0 })))();
3014
3000
  }, []);
3015
3001
  const toggleLocale = o.useCallback(
3016
3002
  (localeId, shouldEnable) => {
@@ -3118,59 +3104,116 @@ const WrapText = dt(ui.Box)`
3118
3104
  ui.Button,
3119
3105
  {
3120
3106
  mode: "ghost",
3121
- onClick: handleImportAll,
3107
+ tone: "primary",
3108
+ onClick: () => handleImportTranslations(),
3122
3109
  text: isImporting ? "Importing..." : "Import All",
3123
3110
  icon: icons.DownloadIcon,
3124
3111
  disabled: isImporting || availableLocales.every((locale) => {
3125
3112
  const key = `${documentId}:${locale.localeId}`;
3126
3113
  return !translationStatuses.get(key)?.isReady || importedTranslations.has(key);
3127
- })
3114
+ }),
3115
+ style: { minWidth: "180px" }
3128
3116
  }
3129
3117
  ),
3130
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, muted: !0, children: [
3131
- "Imported",
3132
- " ",
3133
- availableLocales.filter((locale) => {
3134
- const key = `${documentId}:${locale.localeId}`;
3135
- return importedTranslations.has(key);
3136
- }).length,
3137
- "/",
3138
- availableLocales.filter((locale) => {
3139
- const key = `${documentId}:${locale.localeId}`;
3140
- return translationStatuses.get(key)?.isReady;
3141
- }).length
3118
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "center", children: [
3119
+ /* @__PURE__ */ jsxRuntime.jsx(
3120
+ ui.Switch,
3121
+ {
3122
+ checked: autoImport,
3123
+ onChange: () => setAutoImport(!autoImport),
3124
+ disabled: isImporting
3125
+ }
3126
+ ),
3127
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "Auto-import when complete" })
3142
3128
  ] })
3143
3129
  ] }),
3144
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "center", style: { whiteSpace: "nowrap" }, children: [
3145
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "Auto-import when complete" }),
3130
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, muted: !0, children: [
3131
+ "Imported",
3132
+ " ",
3133
+ availableLocales.filter((locale) => {
3134
+ const key = `${documentId}:${locale.localeId}`;
3135
+ return importedTranslations.has(key);
3136
+ }).length,
3137
+ "/",
3138
+ availableLocales.filter((locale) => {
3139
+ const key = `${documentId}:${locale.localeId}`;
3140
+ return translationStatuses.get(key)?.isReady;
3141
+ }).length
3142
+ ] })
3143
+ ] }),
3144
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "center", justify: "flex-start", children: [
3145
+ /* @__PURE__ */ jsxRuntime.jsx(
3146
+ ui.Tooltip,
3147
+ {
3148
+ placement: "top",
3149
+ content: `Replaces references to ${pluginConfig.getSourceLocale()} documents in this document with the corresponding translated document reference`,
3150
+ children: /* @__PURE__ */ jsxRuntime.jsx(
3151
+ ui.Button,
3152
+ {
3153
+ mode: "ghost",
3154
+ tone: "caution",
3155
+ onClick: async () => {
3156
+ await handlePatchDocumentReferences();
3157
+ },
3158
+ text: isBusy ? "Patching..." : "Patch References",
3159
+ icon: isBusy ? null : icons.LinkIcon,
3160
+ disabled: isBusy || isImporting,
3161
+ style: { minWidth: "180px" }
3162
+ }
3163
+ )
3164
+ }
3165
+ ),
3166
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "center", children: [
3146
3167
  /* @__PURE__ */ jsxRuntime.jsx(
3147
3168
  ui.Switch,
3148
3169
  {
3149
- checked: autoImport,
3150
- onChange: () => setAutoImport(!autoImport),
3151
- disabled: isImporting
3170
+ checked: autoPatchReferences,
3171
+ onChange: () => setAutoPatchReferences(!autoPatchReferences),
3172
+ disabled: isImporting || isBusy
3152
3173
  }
3153
- )
3174
+ ),
3175
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "Auto-patch after import" })
3154
3176
  ] })
3155
3177
  ] }),
3156
- /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { justify: "flex-start", children: /* @__PURE__ */ jsxRuntime.jsx(
3157
- ui.Tooltip,
3158
- {
3159
- placement: "top",
3160
- content: `Replaces references to ${pluginConfig.getSourceLocale()} documents in this document with the corresponding translated document reference`,
3161
- children: /* @__PURE__ */ jsxRuntime.jsx(
3162
- ui.Button,
3178
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "center", justify: "flex-start", children: [
3179
+ /* @__PURE__ */ jsxRuntime.jsx(
3180
+ ui.Tooltip,
3181
+ {
3182
+ placement: "top",
3183
+ content: "Publishes all translations (if the source document is published)",
3184
+ children: /* @__PURE__ */ jsxRuntime.jsx(
3185
+ ui.Button,
3186
+ {
3187
+ mode: "ghost",
3188
+ tone: "positive",
3189
+ onClick: async () => {
3190
+ setIsPublishing(!0);
3191
+ try {
3192
+ await handlePublishAllTranslations();
3193
+ } finally {
3194
+ setIsPublishing(!1);
3195
+ }
3196
+ },
3197
+ text: isPublishing ? "Publishing..." : "Publish Translations",
3198
+ icon: isPublishing ? null : icons.PublishIcon,
3199
+ disabled: isBusy || isPublishing || isImporting,
3200
+ style: { minWidth: "180px" }
3201
+ }
3202
+ )
3203
+ }
3204
+ ),
3205
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "center", children: [
3206
+ /* @__PURE__ */ jsxRuntime.jsx(
3207
+ ui.Switch,
3163
3208
  {
3164
- mode: "ghost",
3165
- tone: "caution",
3166
- onClick: handlePatchDocumentReferences,
3167
- text: isBusy ? "Patching..." : "Patch Document References",
3168
- icon: isBusy ? null : icons.LinkIcon,
3169
- disabled: isBusy
3209
+ checked: autoPublish,
3210
+ onChange: () => setAutoPublish(!autoPublish),
3211
+ disabled: isPublishing || isImporting || isBusy
3170
3212
  }
3171
- )
3172
- }
3173
- ) })
3213
+ ),
3214
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "Auto-publish after import" })
3215
+ ] })
3216
+ ] })
3174
3217
  ] })
3175
3218
  ] })
3176
3219
  ] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 4, tone: "neutral", border: !0, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, muted: !0, children: [
@@ -3182,6 +3225,21 @@ const WrapText = dt(ui.Box)`
3182
3225
  }, TranslationTab = (props) => {
3183
3226
  const { displayed } = props.document;
3184
3227
  return /* @__PURE__ */ jsxRuntime.jsx(BaseTranslationWrapper, { showContainer: !1, children: /* @__PURE__ */ jsxRuntime.jsx(TranslationsProvider, { singleDocument: displayed, children: /* @__PURE__ */ jsxRuntime.jsx(TranslationView, {}) }) });
3228
+ }, translateAction = (props) => {
3229
+ const router$1 = router.useRouter();
3230
+ return {
3231
+ label: "Translate",
3232
+ icon: icons.TranslateIcon,
3233
+ tone: "primary",
3234
+ onHandle: () => {
3235
+ const { id, type } = props;
3236
+ router$1.navigateIntent("edit", {
3237
+ id,
3238
+ type,
3239
+ view: "general-translation"
3240
+ });
3241
+ }
3242
+ };
3185
3243
  }, TranslationsTable = () => {
3186
3244
  const {
3187
3245
  documents,
@@ -3611,7 +3669,17 @@ const WrapText = dt(ui.Box)`
3611
3669
  component: TranslationsTool,
3612
3670
  router: router.route.create("/*")
3613
3671
  }
3614
- ]
3672
+ ],
3673
+ document: {
3674
+ views: [
3675
+ {
3676
+ id: "general-translation",
3677
+ title: "Translations",
3678
+ component: TranslationTab
3679
+ }
3680
+ ],
3681
+ actions: (prev2) => [...prev2, translateAction]
3682
+ }
3615
3683
  })
3616
3684
  );
3617
3685
  exports.BaseDocumentDeserializer = BaseDocumentDeserializer;
@@ -3624,4 +3692,5 @@ exports.defaultStopTypes = defaultStopTypes;
3624
3692
  exports.detachGTData = detachGTData;
3625
3693
  exports.findLatestDraft = findLatestDraft;
3626
3694
  exports.gtPlugin = gtPlugin;
3695
+ exports.translateAction = translateAction;
3627
3696
  //# sourceMappingURL=index.js.map