|
40 | 40 | // Pre-populate form |
41 | 41 | warehouseName = catalog.warehouse_name || ''; |
42 | 42 | storageLocation = catalog.storage_location || ''; |
| 43 | + // Mark as manually set initially to prevent auto-overwriting existing custom paths on load |
| 44 | + manualLocation = true; |
43 | 45 | } catch (error: any) { |
44 | 46 | notifications.error(`Failed to load catalog: ${error.message}`); |
45 | 47 | goto('/catalogs'); |
|
66 | 68 | return Object.keys(errors).length === 0; |
67 | 69 | } |
68 | 70 |
|
| 71 | + let manualLocation = false; |
| 72 | +
|
| 73 | + // Helper to determine type from config keys |
| 74 | + function getStorageType(config: Record<string, string> | undefined): 's3' | 'azure' | 'gcs' | 's3' { |
| 75 | + if (!config) return 's3'; |
| 76 | + if (config['s3.bucket']) return 's3'; |
| 77 | + if (config['adls.account-name'] || config['azure.container']) return 'azure'; |
| 78 | + if (config['gcs.bucket']) return 'gcs'; |
| 79 | + return 's3'; |
| 80 | + } |
| 81 | +
|
| 82 | + // Reactive update for storage location |
| 83 | + $: if (warehouseName && !manualLocation) { |
| 84 | + const selected = warehouses.find(w => w.name === warehouseName); |
| 85 | + if (selected?.storage_config) { |
| 86 | + const config = selected.storage_config; |
| 87 | + const bucket = config['s3.bucket'] |
| 88 | + || config['adls.container'] |
| 89 | + || config['azure.container'] |
| 90 | + || config['gcs.bucket']; |
| 91 | + |
| 92 | + const type = getStorageType(config); |
| 93 | + |
| 94 | + // Only auto-update if we have a valid bucket to form a path |
| 95 | + if (bucket) { |
| 96 | + if (type === 'azure') { |
| 97 | + const account = config['adls.account-name']; |
| 98 | + if (account) { |
| 99 | + storageLocation = `abfss://${bucket}@${account}.dfs.core.windows.net/${catalog?.name || 'catalog'}`; |
| 100 | + } |
| 101 | + } else if (type === 's3') { |
| 102 | + storageLocation = `s3://${bucket}/${catalog?.name || 'catalog'}`; |
| 103 | + } else if (type === 'gcs') { |
| 104 | + storageLocation = `gs://${bucket}/${catalog?.name || 'catalog'}`; |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | +
|
69 | 110 | async function handleSubmit() { |
70 | 111 | if (!validateForm() || !catalogName) return; |
71 | 112 |
|
|
137 | 178 | label="Warehouse" |
138 | 179 | bind:value={warehouseName} |
139 | 180 | options={warehouseOptions} |
| 181 | + on:change={() => manualLocation = false} |
140 | 182 | placeholder="Select a warehouse..." |
141 | 183 | helpText="Optional: Link this catalog to a warehouse for credential vending" |
142 | 184 | /> |
143 | 185 |
|
144 | 186 | <Input |
145 | 187 | label="Storage Location" |
146 | 188 | bind:value={storageLocation} |
| 189 | + on:input={() => manualLocation = true} |
147 | 190 | error={errors.storageLocation} |
148 | 191 | required |
149 | 192 | placeholder="s3://bucket/path or /local/path" |
|
0 commit comments