Files
product_inventory/src/initMenu.ts
Ben Miller 8554ae9610 Fix duplicate media import bug and rename MediaSidebar to MediaManager
- Renamed src/MediaSidebar.html to src/MediaManager.html to align with modal UI.
- Fixed race condition in Photo Picker polling preventing duplicate imports.
- Updated global.ts, initMenu.ts, and mediaHandlers.ts used in the fix.
- Fixed unit tests for mediaHandlers.
2025-12-26 22:57:46 -07:00

81 lines
3.0 KiB
TypeScript

import { getShopifyProducts, runShopifyOrders } from "./shopifyApi"
import { fillProductFromTemplate } from "./fillProductFromTemplate"
import { createMissingPhotoFolders } from "./createMissingPhotoFolders"
import { matchProductToShopify, updateProductToShopify } from "./match"
import { reinstallTriggers, installSalesSyncTrigger } from "./triggers"
import { reconcileSalesHandler } from "./salesSync"
import { toastAndLog } from "./sheetUtils"
import { showSidebar } from "./sidebar"
import { showMediaManager, debugScopes } from "./mediaHandlers"
import { runSystemDiagnostics } from "./verificationSuite"
export function initMenu() {
let ui = SpreadsheetApp.getUi()
ui.createMenu("BLM")
.addSubMenu(
ui
.createMenu("This row...")
.addItem("Fill out product from template", fillProductFromTemplate.name)
.addItem("Match product to Shopify", matchProductToShopifyHandler.name)
.addItem("Update Shopify Product", updateShopifyProductHandler.name)
.addItem("Media Manager", showMediaManager.name)
)
.addSeparator()
.addSubMenu(
ui
.createMenu("Bulk operations...")
.addItem("Create missing photo folders", createMissingPhotoFolders.name)
.addItem("Run Shopify Orders", runShopifyOrders.name)
.addItem("Get Shopify Products", getShopifyProducts.name)
.addItem("Reconcile Sales...", reconcileSalesHandler.name)
)
.addSeparator()
.addSubMenu(
ui
.createMenu("Utilities...")
.addItem("Reauthorize script", reauthorizeScript.name)
.addItem("Reinstall triggers", reinstallTriggers.name)
.addItem("Update Sales Sync Trigger", installSalesSyncTrigger.name)
.addItem("Troubleshoot", showSidebar.name)
.addItem("Run System Diagnostics", runSystemDiagnostics.name)
.addItem("Debug Scopes", "debugScopes")
.addItem("Debug Folder Access", "debugFolderAccess")
)
.addToUi()
}
export function matchProductToShopifyHandler() {
var sheet = SpreadsheetApp.getActive().getActiveSheet()
if (sheet.getName() !== "product_inventory") {
console.log("skipping edit on sheet " + sheet.getName())
return
}
let row = SpreadsheetApp.getCurrentCell().getRow()
matchProductToShopify(row)
}
export function updateShopifyProductHandler() {
var sheet = SpreadsheetApp.getActive().getActiveSheet()
if (sheet.getName() !== "product_inventory") {
console.log("skipping edit on sheet " + sheet.getName())
return
}
let selectedRanges = SpreadsheetApp.getActiveRangeList().getRanges()
if (selectedRanges == null || selectedRanges.length == 0) {
toastAndLog("Select ranges to be updated")
return
}
for (let i = 0; i < selectedRanges.length; i++) {
let range = selectedRanges[i]
let firstRow = range.getRow()
let lastRow = range.getLastRow()
for (let row = firstRow; row <= lastRow; row++) {
updateProductToShopify(row)
}
}
}
export function reauthorizeScript() {
ScriptApp.invalidateAuth()
}