Skip to content

Commit 580f1bd

Browse files
committed
fix(workflows): compare against previous saved version by default
1 parent a99b35a commit 580f1bd

3 files changed

Lines changed: 36 additions & 26 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/general/compare-pair.test.ts‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@ import { describe, expect, it } from 'vitest'
55
import { resolveComparePair } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/general/compare-pair'
66

77
describe('resolveComparePair', () => {
8-
it('puts the older version on the base side whichever was clicked', () => {
9-
const expected = {
10-
base: { kind: 'version', version: 3 },
11-
target: { kind: 'version', version: 5 },
12-
}
13-
expect(resolveComparePair(5, 3)).toEqual(expected)
14-
expect(resolveComparePair(3, 5)).toEqual(expected)
8+
it('compares the closest previous saved version to the selected version despite gaps or ordering', () => {
9+
const versions = [{ version: 9 }, { version: 2 }, { version: 7 }, { version: 5 }]
10+
expect(resolveComparePair(7, versions)).toEqual({
11+
base: { kind: 'version', version: 5 },
12+
target: { kind: 'version', version: 7 },
13+
})
14+
expect(resolveComparePair(9, versions)).toEqual({
15+
base: { kind: 'version', version: 7 },
16+
target: { kind: 'version', version: 9 },
17+
})
1518
})
1619

17-
it('compares the live version, or any version with nothing live, against the draft', () => {
18-
expect(resolveComparePair(3, 3)).toEqual({
19-
base: { kind: 'version', version: 3 },
20+
it('compares the earliest available version to draft when it has no predecessor', () => {
21+
expect(resolveComparePair(1, [{ version: 2 }, { version: 1 }])).toEqual({
22+
base: { kind: 'version', version: 1 },
2023
target: { kind: 'draft' },
2124
})
22-
expect(resolveComparePair(2, null)).toEqual({
23-
base: { kind: 'version', version: 2 },
25+
expect(resolveComparePair(4, [{ version: 4 }])).toEqual({
26+
base: { kind: 'version', version: 4 },
2427
target: { kind: 'draft' },
2528
})
2629
})

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/general/compare-pair.ts‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,26 @@ export interface ComparePair {
55
target: CompareSide
66
}
77

8-
/**
9-
* Which two sides a "Compare" on a version opens: the older version on the
10-
* left and the newer on the right, except that the live version (or any
11-
* version when nothing is live) compares against the draft, since that is
12-
* what a redeploy would ship.
13-
*/
14-
export function resolveComparePair(version: number, activeVersion: number | null): ComparePair {
15-
if (activeVersion === null || activeVersion === version) {
8+
/** Compares against the previous saved version, or the draft when no predecessor exists. */
9+
export function resolveComparePair(
10+
version: number,
11+
versions: readonly { version: number }[]
12+
): ComparePair {
13+
let previousVersion: number | null = null
14+
for (const candidate of versions) {
15+
if (
16+
candidate.version < version &&
17+
(previousVersion === null || candidate.version > previousVersion)
18+
) {
19+
previousVersion = candidate.version
20+
}
21+
}
22+
23+
if (previousVersion === null) {
1624
return { base: { kind: 'version', version }, target: { kind: 'draft' } }
1725
}
18-
const [low, high] = version < activeVersion ? [version, activeVersion] : [activeVersion, version]
19-
return { base: { kind: 'version', version: low }, target: { kind: 'version', version: high } }
26+
return {
27+
base: { kind: 'version', version: previousVersion },
28+
target: { kind: 'version', version },
29+
}
2030
}

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/general/general.tsx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ export function GeneralDeploy({
8888
workflowId: string
8989
version: number
9090
} | null>(null)
91-
const activeVersion = versions.find((v) => v.isActive)?.version ?? null
92-
93-
/** See resolveComparePair for which two sides a version opens against. */
9491
const handleCompareVersion = (version: number) => {
95-
setComparePair(resolveComparePair(version, activeVersion))
92+
setComparePair(resolveComparePair(version, versions))
9693
}
9794

9895
const selectedVersionInfo = versions.find((v) => v.version === selectedVersion)

0 commit comments

Comments
 (0)