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
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
import { gt, overrideConfig } from '../adapter/core';
|
|
2
|
+
import { FileProperties } from '../adapter/types';
|
|
3
|
+
import { DownloadedFile } from 'generaltranslation/types';
|
|
2
4
|
import type { Secrets } from '../types';
|
|
3
5
|
|
|
4
|
-
export type BatchedFiles = Array<{
|
|
5
|
-
documentId: string;
|
|
6
|
-
versionId: string;
|
|
7
|
-
translationId: string;
|
|
8
|
-
locale: string;
|
|
9
|
-
}>;
|
|
10
|
-
|
|
11
|
-
export type DownloadedFile = {
|
|
12
|
-
docData: {
|
|
13
|
-
documentId: string;
|
|
14
|
-
versionId: string;
|
|
15
|
-
translationId: string;
|
|
16
|
-
locale: string;
|
|
17
|
-
};
|
|
18
|
-
data: string;
|
|
19
|
-
};
|
|
20
6
|
/**
|
|
21
7
|
* Downloads multiple translation files in a single batch request
|
|
22
8
|
* @param files - Array of files to download with their output paths
|
|
@@ -25,38 +11,27 @@ export type DownloadedFile = {
|
|
|
25
11
|
* @returns Object containing successful and failed file IDs
|
|
26
12
|
*/
|
|
27
13
|
export async function downloadTranslations(
|
|
28
|
-
files:
|
|
14
|
+
files: FileProperties[],
|
|
29
15
|
secrets: Secrets,
|
|
30
16
|
maxRetries = 3,
|
|
31
17
|
retryDelay = 1000
|
|
32
18
|
): Promise<DownloadedFile[]> {
|
|
33
19
|
overrideConfig(secrets);
|
|
34
20
|
let retries = 0;
|
|
35
|
-
const fileIds = files.map((file) => file.translationId);
|
|
36
|
-
|
|
37
|
-
const map = new Map(files.map((file) => [file.translationId, file]));
|
|
38
|
-
const result = [] as DownloadedFile[];
|
|
39
21
|
|
|
40
22
|
while (retries <= maxRetries) {
|
|
41
23
|
try {
|
|
42
24
|
// Download the files
|
|
43
|
-
const responseData = await gt.downloadFileBatch(
|
|
25
|
+
const responseData = await gt.downloadFileBatch(
|
|
26
|
+
files.map((file) => ({
|
|
27
|
+
fileId: file.fileId,
|
|
28
|
+
branchId: file.branchId,
|
|
29
|
+
versionId: file.versionId,
|
|
30
|
+
locale: file.locale,
|
|
31
|
+
}))
|
|
32
|
+
);
|
|
44
33
|
const downloadedFiles = responseData.files || [];
|
|
45
|
-
|
|
46
|
-
// Process each file in the response
|
|
47
|
-
for (const file of downloadedFiles) {
|
|
48
|
-
const documentData = map.get(file.id);
|
|
49
|
-
if (!documentData) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
result.push({
|
|
54
|
-
docData: documentData,
|
|
55
|
-
data: file.data,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return result;
|
|
34
|
+
return downloadedFiles;
|
|
60
35
|
} catch (error) {
|
|
61
36
|
// Increment retry counter and wait before next attempt
|
|
62
37
|
retries++;
|
|
@@ -64,5 +39,5 @@ export async function downloadTranslations(
|
|
|
64
39
|
}
|
|
65
40
|
}
|
|
66
41
|
|
|
67
|
-
return
|
|
42
|
+
return [];
|
|
68
43
|
}
|
|
@@ -27,14 +27,17 @@ export async function initProject(
|
|
|
27
27
|
let setupFailedMessage: string | null = null;
|
|
28
28
|
|
|
29
29
|
while (true) {
|
|
30
|
-
const status = await gt.
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const status = await gt.checkJobStatus([setupJobId]);
|
|
31
|
+
if (!status[0]) {
|
|
32
|
+
setupFailedMessage = 'Unknown error';
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
if (status[0].status === 'completed') {
|
|
33
36
|
setupCompleted = true;
|
|
34
37
|
break;
|
|
35
38
|
}
|
|
36
|
-
if (status.status === 'failed') {
|
|
37
|
-
setupFailedMessage = status.error?.message || 'Unknown error';
|
|
39
|
+
if (status[0].status === 'failed') {
|
|
40
|
+
setupFailedMessage = status[0].error?.message || 'Unknown error';
|
|
38
41
|
break;
|
|
39
42
|
}
|
|
40
43
|
if (Date.now() - start > setupTimeoutMs) {
|
package/src/utils/importUtils.ts
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { SanityDocument } from 'sanity';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
downloadTranslations,
|
|
5
|
-
BatchedFiles,
|
|
6
|
-
} from '../translation/downloadTranslations';
|
|
2
|
+
import { Secrets, TranslationFunctionContext } from '../types';
|
|
3
|
+
import { downloadTranslations } from '../translation/downloadTranslations';
|
|
7
4
|
import { processImportBatch, ImportBatchItem } from './batchProcessor';
|
|
8
|
-
|
|
9
|
-
export interface TranslationStatus {
|
|
10
|
-
progress: number;
|
|
11
|
-
isReady: boolean;
|
|
12
|
-
translationId?: string;
|
|
13
|
-
}
|
|
5
|
+
import type { FileProperties, TranslationStatus } from '../adapter/types';
|
|
14
6
|
|
|
15
7
|
export interface ImportResult {
|
|
16
8
|
successCount: number;
|
|
@@ -25,32 +17,20 @@ export interface ImportOptions {
|
|
|
25
17
|
}
|
|
26
18
|
|
|
27
19
|
export async function getReadyFilesForImport(
|
|
28
|
-
documents: SanityDocument[],
|
|
29
20
|
translationStatuses: Map<string, TranslationStatus>,
|
|
30
21
|
options: ImportOptions = {}
|
|
31
|
-
): Promise<
|
|
22
|
+
): Promise<FileProperties[]> {
|
|
32
23
|
const { filterReadyFiles = () => true } = options;
|
|
33
|
-
const readyFiles:
|
|
24
|
+
const readyFiles: FileProperties[] = [];
|
|
34
25
|
|
|
35
26
|
for (const [key, status] of translationStatuses.entries()) {
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
(doc) => (doc._id?.replace('drafts.', '') || doc._id) === documentId
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
if (document) {
|
|
47
|
-
readyFiles.push({
|
|
48
|
-
documentId,
|
|
49
|
-
versionId: document._rev,
|
|
50
|
-
translationId: status.translationId,
|
|
51
|
-
locale,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
27
|
+
if (status.isReady && filterReadyFiles(key, status)) {
|
|
28
|
+
readyFiles.push({
|
|
29
|
+
fileId: status.fileData.fileId,
|
|
30
|
+
versionId: status.fileData.versionId,
|
|
31
|
+
branchId: status.fileData.branchId,
|
|
32
|
+
locale: status.fileData.locale,
|
|
33
|
+
});
|
|
54
34
|
}
|
|
55
35
|
}
|
|
56
36
|
|
|
@@ -58,7 +38,7 @@ export async function getReadyFilesForImport(
|
|
|
58
38
|
}
|
|
59
39
|
|
|
60
40
|
export async function importTranslations(
|
|
61
|
-
readyFiles:
|
|
41
|
+
readyFiles: FileProperties[],
|
|
62
42
|
secrets: Secrets,
|
|
63
43
|
translationContext: TranslationFunctionContext,
|
|
64
44
|
options: ImportOptions = {}
|
|
@@ -71,13 +51,13 @@ export async function importTranslations(
|
|
|
71
51
|
|
|
72
52
|
const importItems: ImportBatchItem[] = downloadedFiles.map((file) => ({
|
|
73
53
|
docInfo: {
|
|
74
|
-
documentId: file.
|
|
75
|
-
versionId: file.
|
|
54
|
+
documentId: file.fileId,
|
|
55
|
+
versionId: file.versionId,
|
|
76
56
|
},
|
|
77
|
-
locale: file.
|
|
57
|
+
locale: file.locale!,
|
|
78
58
|
data: file.data,
|
|
79
59
|
translationContext,
|
|
80
|
-
key: `${file.
|
|
60
|
+
key: `${file.branchId}:${file.fileId}:${file.versionId}:${file.locale}`,
|
|
81
61
|
}));
|
|
82
62
|
|
|
83
63
|
const result = await processImportBatch(importItems, {
|