Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified the global default viewport size for the app back to the original size #10579

Merged
11 changes: 11 additions & 0 deletions app-shell/src/config/__fixtures__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ConfigV5,
ConfigV6,
ConfigV7,
ConfigV8,
} from '@opentrons/app/src/redux/config/types'

export const MOCK_CONFIG_V0: ConfigV0 = {
Expand Down Expand Up @@ -130,3 +131,13 @@ export const MOCK_CONFIG_V7: ConfigV7 = {
height: 760,
},
}

export const MOCK_CONFIG_V8: ConfigV8 = {
...MOCK_CONFIG_V7,
version: 8,
ui: {
...MOCK_CONFIG_V7.ui,
width: 1024,
height: 768,
},
}
43 changes: 26 additions & 17 deletions app-shell/src/config/__tests__/migrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
MOCK_CONFIG_V5,
MOCK_CONFIG_V6,
MOCK_CONFIG_V7,
MOCK_CONFIG_V8,
} from '../__fixtures__'
import { migrate } from '../migrate'

Expand All @@ -16,63 +17,71 @@ describe('config migration', () => {
const v0Config = MOCK_CONFIG_V0
const result = migrate(v0Config)

expect(result.version).toBe(7)
expect(result).toEqual(MOCK_CONFIG_V7)
expect(result.version).toBe(8)
expect(result).toEqual(MOCK_CONFIG_V8)
})

it('should migrate version 1 to latest', () => {
const v1Config = MOCK_CONFIG_V1
const result = migrate(v1Config)

expect(result.version).toBe(7)
expect(result).toEqual(MOCK_CONFIG_V7)
expect(result.version).toBe(8)
expect(result).toEqual(MOCK_CONFIG_V8)
})

it('should migrate version 2 to latest', () => {
const v2Config = MOCK_CONFIG_V2
const result = migrate(v2Config)

expect(result.version).toBe(7)
expect(result).toEqual(MOCK_CONFIG_V7)
expect(result.version).toBe(8)
expect(result).toEqual(MOCK_CONFIG_V8)
})

it('should migrate version 3 to latest', () => {
const v3Config = MOCK_CONFIG_V3
const result = migrate(v3Config)

expect(result.version).toBe(7)
expect(result).toEqual(MOCK_CONFIG_V7)
expect(result.version).toBe(8)
expect(result).toEqual(MOCK_CONFIG_V8)
})

it('should migrate version 4 to latest', () => {
const v4Config = MOCK_CONFIG_V4
const result = migrate(v4Config)

expect(result.version).toBe(7)
expect(result).toEqual(MOCK_CONFIG_V7)
expect(result.version).toBe(8)
expect(result).toEqual(MOCK_CONFIG_V8)
})

it('should migrate version 5 to latest', () => {
const v5Config = MOCK_CONFIG_V5
const result = migrate(v5Config)

expect(result.version).toBe(7)
expect(result).toEqual(MOCK_CONFIG_V7)
expect(result.version).toBe(8)
expect(result).toEqual(MOCK_CONFIG_V8)
})

it('should migrate version 6 to latest', () => {
const v6Config = MOCK_CONFIG_V6
const result = migrate(v6Config)

expect(result.version).toBe(7)
expect(result).toEqual(MOCK_CONFIG_V7)
expect(result.version).toBe(8)
expect(result).toEqual(MOCK_CONFIG_V8)
})

it('should keep version 7', () => {
it('should migrate version 7 to latest', () => {
const v7Config = MOCK_CONFIG_V7
const result = migrate(v7Config)

expect(result.version).toBe(7)
expect(result).toEqual(v7Config)
expect(result.version).toBe(8)
expect(result).toEqual(MOCK_CONFIG_V8)
})

it('should keep version 8', () => {
const v8Config = MOCK_CONFIG_V8
const result = migrate(v8Config)

expect(result.version).toBe(8)
expect(result).toEqual(v8Config)
})
})
20 changes: 19 additions & 1 deletion app-shell/src/config/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
ConfigV5,
ConfigV6,
ConfigV7,
ConfigV8,
} from '@opentrons/app/src/redux/config/types'

// base config v0 defaults
Expand Down Expand Up @@ -187,14 +188,29 @@ const toVersion7 = (prevConfig: ConfigV6): ConfigV7 => {
return nextConfig
}

// config version 8 migration and defaults
const toVersion8 = (prevConfig: ConfigV7): ConfigV8 => {
const nextConfig = {
...prevConfig,
version: 8 as const,
ui: {
...prevConfig.ui,
width: 1024,
height: 768,
},
}

return nextConfig
}
const MIGRATIONS: [
(prevConfig: ConfigV0) => ConfigV1,
(prevConfig: ConfigV1) => ConfigV2,
(prevConfig: ConfigV2) => ConfigV3,
(prevConfig: ConfigV3) => ConfigV4,
(prevConfig: ConfigV4) => ConfigV5,
(prevConfig: ConfigV5) => ConfigV6,
(prevConfig: ConfigV6) => ConfigV7
(prevConfig: ConfigV6) => ConfigV7,
(prevConfig: ConfigV7) => ConfigV8
] = [
toVersion1,
toVersion2,
Expand All @@ -203,6 +219,7 @@ const MIGRATIONS: [
toVersion5,
toVersion6,
toVersion7,
toVersion8,
]

export const DEFAULTS: Config = migrate(DEFAULTS_V0)
Expand All @@ -217,6 +234,7 @@ export function migrate(
| ConfigV5
| ConfigV6
| ConfigV7
| ConfigV8
): Config {
const prevVersion = prevConfig.version
let result = prevConfig
Expand Down
6 changes: 5 additions & 1 deletion app/src/redux/config/schema-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,8 @@ export interface ConfigV7 extends Omit<ConfigV6, 'version'> {
}
}

export type Config = ConfigV7
export interface ConfigV8 extends Omit<ConfigV7, 'version'> {
version: 8
}

export type Config = ConfigV8