Skip to content

Commit d9673ce

Browse files
committed
refactor: simplify organizationSettingsVersion to use number with -1 default
- Change organizationSettingsVersion from number | undefined to number with default -1 - Simplify fetch check in MarketplaceView to just currentVersion !== lastOrganizationSettingsVersion - Update test to verify -1 behavior instead of undefined behavior - All tests pass and TypeScript compilation successful
1 parent 630ad04 commit d9673ce

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

webview-ui/src/components/marketplace/MarketplaceView.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ export function MarketplaceView({ stateManager, onDone, targetTab }: Marketplace
2727
// Track when organization settings version changes and trigger refresh
2828
useEffect(() => {
2929
const currentVersion = extensionState?.organizationSettingsVersion ?? -1
30-
if (
31-
currentVersion !== -1 &&
32-
lastOrganizationSettingsVersion !== -1 &&
33-
currentVersion !== lastOrganizationSettingsVersion
34-
) {
30+
if (currentVersion !== lastOrganizationSettingsVersion) {
3531
// Organization settings version changed, refresh marketplace data
3632
vscode.postMessage({
3733
type: "fetchMarketplaceData",

webview-ui/src/components/marketplace/__tests__/MarketplaceView.spec.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ describe("MarketplaceView", () => {
104104
})
105105
})
106106

107-
it("should not trigger fetchMarketplaceData when organization settings version is undefined", async () => {
108-
// Start with undefined version
107+
it("should trigger fetchMarketplaceData when organization settings version changes from -1", async () => {
108+
// Start with -1 version (default)
109109
mockExtensionState = {
110110
...mockExtensionState,
111-
organizationSettingsVersion: undefined,
111+
organizationSettingsVersion: -1,
112112
}
113113

114114
const { rerender } = render(
@@ -117,6 +117,9 @@ describe("MarketplaceView", () => {
117117
</ExtensionStateContext.Provider>,
118118
)
119119

120+
// Clear any initial calls
121+
vi.clearAllMocks()
122+
120123
// Update to a defined version
121124
mockExtensionState = {
122125
...mockExtensionState,
@@ -129,9 +132,9 @@ describe("MarketplaceView", () => {
129132
</ExtensionStateContext.Provider>,
130133
)
131134

132-
// Should not trigger fetch when transitioning from undefined
135+
// Should trigger fetch when transitioning from -1 to 1
133136
await waitFor(() => {
134-
expect(vscode.postMessage).not.toHaveBeenCalledWith({
137+
expect(vscode.postMessage).toHaveBeenCalledWith({
135138
type: "fetchMarketplaceData",
136139
})
137140
})

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface ExtensionStateContextType extends ExtensionState {
3535
openedTabs: Array<{ label: string; isActive: boolean; path?: string }>
3636
commands: Command[]
3737
organizationAllowList: OrganizationAllowList
38-
organizationSettingsVersion?: number
38+
organizationSettingsVersion: number
3939
cloudIsAuthenticated: boolean
4040
sharingEnabled: boolean
4141
maxConcurrentFileReads?: number
@@ -227,7 +227,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
227227
cloudIsAuthenticated: false,
228228
sharingEnabled: false,
229229
organizationAllowList: ORGANIZATION_ALLOW_ALL,
230-
organizationSettingsVersion: undefined,
230+
organizationSettingsVersion: -1,
231231
autoCondenseContext: true,
232232
autoCondenseContextPercent: 100,
233233
profileThresholds: {},
@@ -394,7 +394,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
394394
screenshotQuality: state.screenshotQuality,
395395
routerModels: extensionRouterModels,
396396
cloudIsAuthenticated: state.cloudIsAuthenticated ?? false,
397-
organizationSettingsVersion: state.organizationSettingsVersion,
397+
organizationSettingsVersion: state.organizationSettingsVersion ?? -1,
398398
marketplaceItems,
399399
marketplaceInstalledMetadata,
400400
profileThresholds: state.profileThresholds ?? {},

0 commit comments

Comments
 (0)