Skip to content

Commit 5bd4b67

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(planetscale): retain active backup branch context
1 parent eb06454 commit 5bd4b67

3 files changed

Lines changed: 72 additions & 3 deletions

File tree

‎apps/sim/blocks/blocks/planetscale.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,11 @@ export const PlanetScaleBlock: BlockConfig = {
353353
type: 'file-selector',
354354
canonicalParamId: 'backupId',
355355
selectorKey: 'planetscale.backups',
356-
dependsOn: ['serviceTokenId', 'serviceToken', 'organization', 'databaseSelector'],
356+
dependsOn: {
357+
all: ['serviceTokenId', 'serviceToken', 'organization', 'databaseSelector'],
358+
// Database enables the default-parent lookup; branch dependencies retain explicit context.
359+
any: ['databaseSelector', 'branchSelector', 'parentBranchSelector'],
360+
},
357361
placeholder: 'Select backup',
358362
mode: 'basic',
359363
required: { field: 'operation', value: ['get_backup'] },

‎apps/sim/lib/selectors/context.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ export function buildSelectorContextFromValues(
141141
canonicalIndex.groupsById[dependency]?.canonicalId ??
142142
canonicalIndex.canonicalIdBySubBlockId[dependency]
143143
if (canonicalId) {
144+
const group = canonicalIndex.groupsById[canonicalId]
145+
if (![group.basicId, ...group.advancedIds].some((id) => id && configById.has(id))) continue
144146
if (resolvedGroups.has(canonicalId)) continue
145147
resolvedGroups.add(canonicalId)
146148
candidate[canonicalId] = resolveActiveCanonicalValue(

‎apps/sim/lib/selectors/server/providers/planetscale.test.ts‎

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { beforeEach, describe, expect, it, vi } from 'vitest'
2+
import {
3+
buildSelectorContextFromValues,
4+
getSelectorContextSubBlocks,
5+
} from '@/lib/selectors/context'
26
import { createSelectorProtectedValues } from '@/lib/selectors/server/protected-values'
37
import { planetScaleSelectorAttachments } from '@/lib/selectors/server/providers/planetscale'
48
import type { ExecuteServerSelectorArgs } from '@/lib/selectors/server/types'
9+
import { getDependsOnFields } from '@/lib/workflows/subblocks/dependencies'
10+
import { buildCanonicalIndexForSurface } from '@/lib/workflows/subblocks/visibility'
11+
import { PlanetScaleBlock } from '@/blocks/blocks/planetscale'
512

613
function args(overrides: Partial<ExecuteServerSelectorArgs> = {}): ExecuteServerSelectorArgs {
714
return {
@@ -110,13 +117,69 @@ describe('PlanetScale server selectors', () => {
110117
).resolves.toEqual({ kind: 'list', items: [option] })
111118
})
112119

120+
it.each([
121+
['get_backup', 'branchSelector'],
122+
['create_branch', 'parentBranchSelector'],
123+
])(
124+
'loads backups from the selected branch on the %s block surface',
125+
async (operation, branchField) => {
126+
fetchMock.mockResolvedValueOnce(page([{ id: 'backup-id', name: 'Before migration' }]))
127+
const values = {
128+
serviceTokenId: 'test-id',
129+
serviceToken: 'test-secret',
130+
organization: 'example',
131+
databaseSelector: 'test-db',
132+
operation,
133+
[branchField]: 'development',
134+
[branchField === 'branchSelector' ? 'parentBranchSelector' : 'branchSelector']:
135+
'stale-hidden',
136+
}
137+
const backupPicker = PlanetScaleBlock.subBlocks.find(
138+
(field) => field.id === 'backupIdSelector'
139+
)!
140+
const context = buildSelectorContextFromValues({
141+
selectorKey: 'planetscale.backups',
142+
contextConfigs: getSelectorContextSubBlocks(PlanetScaleBlock.subBlocks, values),
143+
values,
144+
dependsOn: getDependsOnFields(backupPicker.dependsOn),
145+
canonicalIndex: buildCanonicalIndexForSurface(PlanetScaleBlock.subBlocks, false),
146+
})
147+
await expect(
148+
planetScaleSelectorAttachments['planetscale.backups'].execute(
149+
args({ selectorKey: 'planetscale.backups', context })
150+
)
151+
).resolves.toEqual({ kind: 'list', items: [{ id: 'backup-id', label: 'Before migration' }] })
152+
expect(fetchMock.mock.calls.map(([url]) => new URL(String(url)).pathname)).toEqual([
153+
'/v1/organizations/example/databases/test-db/branches/development/backups',
154+
])
155+
}
156+
)
157+
113158
it.each([undefined, ''])(
114159
'discovers backups from the default branch when parent is %s',
115160
async (branch) => {
116161
fetchMock.mockResolvedValueOnce(Response.json({ default_branch: 'production' }))
117162
fetchMock.mockResolvedValueOnce(page([{ id: 'backup-id', name: 'Before migration' }]))
118-
const input = args({ selectorKey: 'planetscale.backups' })
119-
input.context.branch = branch
163+
const values = {
164+
serviceTokenId: 'test-id',
165+
serviceToken: 'test-secret',
166+
organization: 'example',
167+
databaseSelector: 'test-db',
168+
operation: 'create_branch',
169+
branchSelector: 'stale-hidden',
170+
parentBranchSelector: branch,
171+
}
172+
const backupPicker = PlanetScaleBlock.subBlocks.find(
173+
(field) => field.id === 'backupIdSelector'
174+
)!
175+
const context = buildSelectorContextFromValues({
176+
selectorKey: 'planetscale.backups',
177+
contextConfigs: getSelectorContextSubBlocks(PlanetScaleBlock.subBlocks, values),
178+
values,
179+
dependsOn: getDependsOnFields(backupPicker.dependsOn),
180+
canonicalIndex: buildCanonicalIndexForSurface(PlanetScaleBlock.subBlocks, false),
181+
})
182+
const input = args({ selectorKey: 'planetscale.backups', context })
120183
await expect(
121184
planetScaleSelectorAttachments['planetscale.backups'].execute(input)
122185
).resolves.toEqual({

0 commit comments

Comments
 (0)