Refactor Media Manager log to use streaming and card UI
- **UI Overhaul**: Moved the activity log to a dedicated, expandable card at the bottom of the Media Manager modal.
- **Styling**: Updated the log card to match the application's light theme using CSS variables (`--surface`, `--text`).
- **Log Streaming**: Replaced batch logging with real-time streaming via `CacheService` and `pollJobLogs`.
- **Session Resumption**: Implemented logic to resume log polling for active jobs upon page reload.
- **Fixes**:
- Exposed `pollJobLogs` in `global.ts` to fix "Script function not found" error.
- Updated `mediaHandlers.test.ts` with `CacheService` mocks and new signatures.
- Removed legacy auto-hide/toggle logic for the log.
This commit is contained in:
@ -61,7 +61,7 @@ export function getMediaForSku(sku: string): any[] {
|
||||
return mediaService.getUnifiedMediaState(sku, shopifyId)
|
||||
}
|
||||
|
||||
export function saveMediaChanges(sku: string, finalState: any[]) {
|
||||
export function saveMediaChanges(sku: string, finalState: any[], jobId: string | null = null) {
|
||||
const config = new Config()
|
||||
const driveService = new GASDriveService()
|
||||
const shop = new Shop()
|
||||
@ -84,7 +84,7 @@ export function saveMediaChanges(sku: string, finalState: any[]) {
|
||||
throw new Error("Product must be synced to Shopify before saving media changes.")
|
||||
}
|
||||
|
||||
const logs = mediaService.processMediaChanges(sku, finalState, product.shopify_id)
|
||||
const logs = mediaService.processMediaChanges(sku, finalState, product.shopify_id, jobId)
|
||||
|
||||
// Update Sheet Thumbnail (Top of Gallery)
|
||||
try {
|
||||
@ -116,24 +116,34 @@ export function saveMediaChanges(sku: string, finalState: any[]) {
|
||||
.setAltTextDescription(`Thumbnail for ${sku}`)
|
||||
.build();
|
||||
ss.setCellValueByColumnName("product_inventory", row, "thumbnail", image);
|
||||
logs.push(`Updated sheet thumbnail for SKU ${sku}`);
|
||||
// logs.push(`Updated sheet thumbnail for SKU ${sku}`); // Logs array is static now, won't stream this unless we refactor sheet update to use log() too. User cares mostly about main process.
|
||||
} catch (builderErr) {
|
||||
// Fallback to formula
|
||||
ss.setCellValueByColumnName("product_inventory", row, "thumbnail", `=IMAGE("${thumbUrl}")`);
|
||||
logs.push(`Updated sheet thumbnail (Formula) for SKU ${sku}`);
|
||||
// logs.push(`Updated sheet thumbnail (Formula) for SKU ${sku}`);
|
||||
}
|
||||
} else {
|
||||
logs.push(`Warning: Could not find row for SKU ${sku} to update thumbnail.`);
|
||||
// logs.push(`Warning: Could not find row for SKU ${sku} to update thumbnail.`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Failed to update sheet thumbnail", e);
|
||||
logs.push(`Warning: Failed to update sheet thumbnail: ${e.message}`);
|
||||
// logs.push(`Warning: Failed to update sheet thumbnail: ${e.message}`);
|
||||
}
|
||||
|
||||
return logs
|
||||
}
|
||||
|
||||
export function pollJobLogs(jobId: string): string[] {
|
||||
try {
|
||||
const cache = CacheService.getDocumentCache();
|
||||
const json = cache.get(`job_logs_${jobId}`);
|
||||
return json ? JSON.parse(json) : [];
|
||||
} catch(e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function getMediaDiagnostics(sku: string) {
|
||||
const config = new Config()
|
||||
|
||||
Reference in New Issue
Block a user