@fgv/ts-res-browser 1.0.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/.rush/temp/5fc90bc7c2ccf812114ea099111568e5429be2a2.tar.log +15 -0
- package/.rush/temp/chunked-rush-logs/ts-res-browser.build.chunks.jsonl +35 -0
- package/.rush/temp/operation/build/all.log +35 -0
- package/.rush/temp/operation/build/log-chunks.jsonl +35 -0
- package/.rush/temp/operation/build/state.json +3 -0
- package/.rush/temp/shrinkwrap-deps.json +1217 -0
- package/README.md +95 -0
- package/TS_RES_BROWSER_PLAN.md +689 -0
- package/babel.config.js +17 -0
- package/config/jest.config.json +13 -0
- package/config/rig.json +16 -0
- package/dist/bundle.js +2 -0
- package/dist/bundle.js.LICENSE.txt +62 -0
- package/dist/index.html +1 -0
- package/package.json +78 -0
- package/postcss.config.js +3 -0
- package/public/index.html +15 -0
- package/rush-logs/ts-res-browser.build.cache.log +3 -0
- package/rush-logs/ts-res-browser.build.log +35 -0
- package/src/App.tsx +153 -0
- package/src/cli.ts +44 -0
- package/src/components/common/FileImporter.tsx +138 -0
- package/src/components/common/NavigationWarningModal.tsx +62 -0
- package/src/components/layout/AppLayout.tsx +46 -0
- package/src/components/layout/Header.tsx +22 -0
- package/src/components/layout/MessagesWindow.tsx +108 -0
- package/src/components/layout/Sidebar.tsx +92 -0
- package/src/components/tools/CompiledBrowser.tsx +949 -0
- package/src/components/tools/ConfigurationTool.tsx +1402 -0
- package/src/components/tools/FilterTool.tsx +1027 -0
- package/src/components/tools/ImportTool.tsx +246 -0
- package/src/components/tools/ResolutionViewer.tsx +1672 -0
- package/src/components/tools/SourceBrowser.tsx +496 -0
- package/src/hooks/useAppState.ts +107 -0
- package/src/hooks/useFileImport.ts +86 -0
- package/src/hooks/useNavigationWarning.ts +67 -0
- package/src/hooks/useResourceManager.ts +244 -0
- package/src/index.css +38 -0
- package/src/main.tsx +16 -0
- package/src/types/app.ts +62 -0
- package/src/types/fileSystemAccess.d.ts +94 -0
- package/src/utils/browserFileTreeAccessors.ts +245 -0
- package/src/utils/fileImport.ts +334 -0
- package/src/utils/filterResources.ts +677 -0
- package/src/utils/tsResIntegration.ts +467 -0
- package/tailwind.config.js +21 -0
- package/test-data/README.md +184 -0
- package/test-data/config-variations/README.md +64 -0
- package/test-data/config-variations/composition-terminology.json +112 -0
- package/test-data/config-variations/enterprise-complex.json +129 -0
- package/test-data/config-variations/gaming-app.json +87 -0
- package/test-data/config-variations/high-priority-language.json +65 -0
- package/test-data/config-variations/minimal-basic.json +37 -0
- package/test-data/config-variations/qualifier-default-values.json +71 -0
- package/test-data/config-variations/territory-first.json +68 -0
- package/test-data/config-variations/territory-hierarchy-test.json +31 -0
- package/test-data/config-variations/territory-hierarchy-unconstrained.json +32 -0
- package/test-data/default-matching-test/greeting.res.json +83 -0
- package/test-data/default-matching-test/only-defaults.res.json +48 -0
- package/test-data/sample-project/package.json +27 -0
- package/test-data/sample-project/src/resources/app-config.json +27 -0
- package/test-data/sample-project/src/resources/app.json +177 -0
- package/test-data/sample-project/src/resources/config/app.env=development.json +21 -0
- package/test-data/sample-project/src/resources/config/app.json +21 -0
- package/test-data/sample-project/src/resources/config/app.platform=mobile.json +23 -0
- package/test-data/sample-project/src/resources/feature-flags.json +23 -0
- package/test-data/sample-project/src/resources/home=CA/common.json +16 -0
- package/test-data/sample-project/src/resources/images/density=hdpi.json +29 -0
- package/test-data/sample-project/src/resources/images/home.json +29 -0
- package/test-data/sample-project/src/resources/images/logout.json +14 -0
- package/test-data/sample-project/src/resources/images/settings.json +14 -0
- package/test-data/sample-project/src/resources/images/ui-icons.json +29 -0
- package/test-data/sample-project/src/resources/images/user.density=hdpi.json +14 -0
- package/test-data/sample-project/src/resources/images/user.json +14 -0
- package/test-data/sample-project/src/resources/lang=en-US/common.json +15 -0
- package/test-data/sample-project/src/resources/language=en-CA/ui-terms.json +19 -0
- package/test-data/sample-project/src/resources/language=en-GB/ui-terms.json +30 -0
- package/test-data/sample-project/src/resources/language=fr-CA/ui-terms.json +25 -0
- package/test-data/sample-project/src/resources/language=nl-BE/ui-terms.json +17 -0
- package/test-data/sample-project/src/resources/region=europe/feature-flags.json +17 -0
- package/test-data/sample-project/src/resources/region=north-america/feature-flags.json +18 -0
- package/test-data/sample-project/src/resources/strings/dashboard.home=CA,language=fr.json +20 -0
- package/test-data/sample-project/src/resources/strings/dashboard.json +18 -0
- package/test-data/sample-project/src/resources/strings/dashboard.role=admin.json +23 -0
- package/test-data/sample-project/src/resources/strings/dashboard.role=user.json +21 -0
- package/test-data/sample-project/src/resources/strings/language=en-US.json +16 -0
- package/test-data/sample-project/src/resources/strings.json +78 -0
- package/test-data/sample-project/src/resources/territory=BE/app-config.json +19 -0
- package/test-data/sample-project/src/resources/territory=CA/app-config.json +21 -0
- package/test-data/sample-project/src/resources/territory=GB/app-config.json +25 -0
- package/test-data/sample-project/src/resources/territory=NL/app-config.json +25 -0
- package/test-data/sample-project/src/resources/ui-terms.json +96 -0
- package/test-data/sample-project/src/resources-config.json +111 -0
- package/tsconfig.json +27 -0
- package/webpack.config.js +54 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { DocumentArrowUpIcon, CheckCircleIcon, ExclamationTriangleIcon } from '@heroicons/react/24/outline';
|
|
3
|
+
import { Message } from '../../types/app';
|
|
4
|
+
import { UseFileImportReturn } from '../../hooks/useFileImport';
|
|
5
|
+
import { UseResourceManagerReturn } from '../../hooks/useResourceManager';
|
|
6
|
+
import FileImporter from '../common/FileImporter';
|
|
7
|
+
|
|
8
|
+
interface ImportToolProps {
|
|
9
|
+
onMessage: (type: Message['type'], message: string) => void;
|
|
10
|
+
fileImport: UseFileImportReturn;
|
|
11
|
+
resourceManager: UseResourceManagerReturn;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ImportTool: React.FC<ImportToolProps> = ({ onMessage, fileImport, resourceManager }) => {
|
|
15
|
+
const { state: fileImportState, actions: fileImportActions } = fileImport;
|
|
16
|
+
const { state: resourceState, actions: resourceActions } = resourceManager;
|
|
17
|
+
|
|
18
|
+
// Track if we've already processed the current import to prevent infinite loops
|
|
19
|
+
const lastProcessedImport = useRef<{
|
|
20
|
+
directory: any;
|
|
21
|
+
files: any[];
|
|
22
|
+
hasProcessedData: boolean;
|
|
23
|
+
}>({
|
|
24
|
+
directory: null,
|
|
25
|
+
files: [],
|
|
26
|
+
hasProcessedData: false
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Handle file import completion
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (fileImportState.hasImportedData) {
|
|
32
|
+
const currentDirectory = fileImportState.importedDirectory;
|
|
33
|
+
const currentFiles = fileImportState.importedFiles;
|
|
34
|
+
|
|
35
|
+
// Check if this is a new import that we haven't processed yet
|
|
36
|
+
const isNewImport =
|
|
37
|
+
currentDirectory !== lastProcessedImport.current.directory ||
|
|
38
|
+
currentFiles !== lastProcessedImport.current.files ||
|
|
39
|
+
fileImportState.hasImportedData !== lastProcessedImport.current.hasProcessedData;
|
|
40
|
+
|
|
41
|
+
if (isNewImport && !resourceState.isProcessing) {
|
|
42
|
+
// Update our tracking reference
|
|
43
|
+
lastProcessedImport.current = {
|
|
44
|
+
directory: currentDirectory,
|
|
45
|
+
files: currentFiles,
|
|
46
|
+
hasProcessedData: fileImportState.hasImportedData
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
if (currentDirectory) {
|
|
50
|
+
onMessage('info', 'Directory imported successfully. Processing resources...');
|
|
51
|
+
resourceActions.processDirectory(currentDirectory);
|
|
52
|
+
} else if (currentFiles.length > 0) {
|
|
53
|
+
onMessage('info', `${currentFiles.length} files imported successfully. Processing resources...`);
|
|
54
|
+
resourceActions.processFiles(currentFiles);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}, [
|
|
59
|
+
fileImportState.hasImportedData,
|
|
60
|
+
fileImportState.importedDirectory,
|
|
61
|
+
fileImportState.importedFiles,
|
|
62
|
+
resourceState.isProcessing,
|
|
63
|
+
resourceActions,
|
|
64
|
+
onMessage
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
// Handle resource processing completion
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (resourceState.processedResources) {
|
|
70
|
+
const resourceCount = resourceState.processedResources.summary.resourceIds.length;
|
|
71
|
+
onMessage('success', `Resources processed successfully! Found ${resourceCount} resources.`);
|
|
72
|
+
}
|
|
73
|
+
}, [resourceState.processedResources, onMessage]);
|
|
74
|
+
|
|
75
|
+
// Handle errors
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (fileImportState.error) {
|
|
78
|
+
onMessage('error', `Import error: ${fileImportState.error}`);
|
|
79
|
+
}
|
|
80
|
+
}, [fileImportState.error, onMessage]);
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (resourceState.error) {
|
|
84
|
+
onMessage('error', `Processing error: ${resourceState.error}`);
|
|
85
|
+
}
|
|
86
|
+
}, [resourceState.error, onMessage]);
|
|
87
|
+
|
|
88
|
+
const handleReset = () => {
|
|
89
|
+
// Reset the tracking reference
|
|
90
|
+
lastProcessedImport.current = {
|
|
91
|
+
directory: null,
|
|
92
|
+
files: [],
|
|
93
|
+
hasProcessedData: false
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
fileImportActions.reset();
|
|
97
|
+
resourceActions.reset();
|
|
98
|
+
onMessage('info', 'Import data cleared');
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<div className="p-6">
|
|
103
|
+
<div className="flex items-center space-x-3 mb-6">
|
|
104
|
+
<DocumentArrowUpIcon className="h-8 w-8 text-blue-600" />
|
|
105
|
+
<h2 className="text-2xl font-bold text-gray-900">Import Resources</h2>
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
|
109
|
+
{/* Left column: File Import */}
|
|
110
|
+
<div className="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
|
|
111
|
+
<h3 className="text-lg font-semibold text-gray-900 mb-4">Import Files</h3>
|
|
112
|
+
|
|
113
|
+
<FileImporter
|
|
114
|
+
onDirectoryImported={fileImportActions.handleDirectoryImport}
|
|
115
|
+
onFilesImported={fileImportActions.handleFilesImport}
|
|
116
|
+
onError={fileImportActions.handleError}
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
{/* Right column: Status & Info */}
|
|
121
|
+
<div className="space-y-6">
|
|
122
|
+
{/* Import Status */}
|
|
123
|
+
<div className="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
|
|
124
|
+
<h3 className="text-lg font-semibold text-gray-900 mb-4">Import Status</h3>
|
|
125
|
+
|
|
126
|
+
<div className="space-y-3">
|
|
127
|
+
{/* File Import Status */}
|
|
128
|
+
<div className="flex items-center space-x-3">
|
|
129
|
+
{fileImportState.hasImportedData ? (
|
|
130
|
+
<>
|
|
131
|
+
<CheckCircleIcon className="w-5 h-5 text-green-500" />
|
|
132
|
+
<span className="text-sm text-gray-900">
|
|
133
|
+
{fileImportState.importedDirectory
|
|
134
|
+
? 'Directory imported'
|
|
135
|
+
: `${fileImportState.importedFiles.length} files imported`}
|
|
136
|
+
</span>
|
|
137
|
+
</>
|
|
138
|
+
) : (
|
|
139
|
+
<>
|
|
140
|
+
<div className="w-5 h-5 rounded-full border-2 border-gray-300"></div>
|
|
141
|
+
<span className="text-sm text-gray-500">No files imported yet</span>
|
|
142
|
+
</>
|
|
143
|
+
)}
|
|
144
|
+
</div>
|
|
145
|
+
|
|
146
|
+
{/* Resource Processing Status */}
|
|
147
|
+
<div className="flex items-center space-x-3">
|
|
148
|
+
{resourceState.isProcessing ? (
|
|
149
|
+
<>
|
|
150
|
+
<div className="w-5 h-5 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"></div>
|
|
151
|
+
<span className="text-sm text-gray-900">Processing resources...</span>
|
|
152
|
+
</>
|
|
153
|
+
) : resourceState.processedResources ? (
|
|
154
|
+
<>
|
|
155
|
+
<CheckCircleIcon className="w-5 h-5 text-green-500" />
|
|
156
|
+
<span className="text-sm text-gray-900">
|
|
157
|
+
{resourceState.processedResources.summary.resourceIds.length} resources processed
|
|
158
|
+
</span>
|
|
159
|
+
</>
|
|
160
|
+
) : (
|
|
161
|
+
<>
|
|
162
|
+
<div className="w-5 h-5 rounded-full border-2 border-gray-300"></div>
|
|
163
|
+
<span className="text-sm text-gray-500">No resources processed yet</span>
|
|
164
|
+
</>
|
|
165
|
+
)}
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
{/* Reset Button */}
|
|
170
|
+
{(fileImportState.hasImportedData || resourceState.hasProcessedData) && (
|
|
171
|
+
<button
|
|
172
|
+
onClick={handleReset}
|
|
173
|
+
className="mt-4 px-4 py-2 text-sm bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors"
|
|
174
|
+
>
|
|
175
|
+
Clear Import Data
|
|
176
|
+
</button>
|
|
177
|
+
)}
|
|
178
|
+
</div>
|
|
179
|
+
|
|
180
|
+
{/* Resource Summary */}
|
|
181
|
+
{resourceState.processedResources && (
|
|
182
|
+
<div className="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
|
|
183
|
+
<h3 className="text-lg font-semibold text-gray-900 mb-4">Resource Summary</h3>
|
|
184
|
+
|
|
185
|
+
<div className="space-y-2 text-sm">
|
|
186
|
+
<div className="flex justify-between">
|
|
187
|
+
<span className="text-gray-600">Total Resources:</span>
|
|
188
|
+
<span className="font-medium">
|
|
189
|
+
{resourceState.processedResources.summary.resourceIds.length}
|
|
190
|
+
</span>
|
|
191
|
+
</div>
|
|
192
|
+
<div className="flex justify-between">
|
|
193
|
+
<span className="text-gray-600">Total Count:</span>
|
|
194
|
+
<span className="font-medium">
|
|
195
|
+
{resourceState.processedResources.summary.totalResources}
|
|
196
|
+
</span>
|
|
197
|
+
</div>
|
|
198
|
+
{resourceState.processedResources.summary.warnings.length > 0 && (
|
|
199
|
+
<div className="flex justify-between">
|
|
200
|
+
<span className="text-gray-600">Warnings:</span>
|
|
201
|
+
<span className="font-medium text-yellow-600">
|
|
202
|
+
{resourceState.processedResources.summary.warnings.length}
|
|
203
|
+
</span>
|
|
204
|
+
</div>
|
|
205
|
+
)}
|
|
206
|
+
{resourceState.processedResources.summary.errorCount > 0 && (
|
|
207
|
+
<div className="flex justify-between">
|
|
208
|
+
<span className="text-gray-600">Errors:</span>
|
|
209
|
+
<span className="font-medium text-red-600">
|
|
210
|
+
{resourceState.processedResources.summary.errorCount}
|
|
211
|
+
</span>
|
|
212
|
+
</div>
|
|
213
|
+
)}
|
|
214
|
+
</div>
|
|
215
|
+
|
|
216
|
+
<div className="mt-4 p-3 bg-green-50 rounded-lg">
|
|
217
|
+
<div className="flex items-start space-x-2">
|
|
218
|
+
<CheckCircleIcon className="w-5 h-5 text-green-600 mt-0.5" />
|
|
219
|
+
<div className="text-sm text-green-800">
|
|
220
|
+
<p className="font-medium">Resources Ready!</p>
|
|
221
|
+
<p>Use the Source Browser to explore imported resources.</p>
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
</div>
|
|
226
|
+
)}
|
|
227
|
+
|
|
228
|
+
{/* Error Display */}
|
|
229
|
+
{(fileImportState.error || resourceState.error) && (
|
|
230
|
+
<div className="bg-white rounded-lg shadow-sm border border-red-200 p-6">
|
|
231
|
+
<div className="flex items-start space-x-2">
|
|
232
|
+
<ExclamationTriangleIcon className="w-5 h-5 text-red-600 mt-0.5" />
|
|
233
|
+
<div className="text-sm text-red-800">
|
|
234
|
+
<p className="font-medium">Error</p>
|
|
235
|
+
<p>{fileImportState.error || resourceState.error}</p>
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
</div>
|
|
239
|
+
)}
|
|
240
|
+
</div>
|
|
241
|
+
</div>
|
|
242
|
+
</div>
|
|
243
|
+
);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export default ImportTool;
|