feat: publish HoloLake model-native living system source
This commit is contained in:
parent
6ad10edde1
commit
c395dd3a99
2467 changed files with 615073 additions and 0 deletions
|
|
@ -0,0 +1,42 @@
|
|||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { APP_STORAGE_KEYS, LEGACY_APP_STORAGE_KEYS, copyLegacyAppStorageKeys, getAppStorageItem } from './appStorage'
|
||||
|
||||
describe('appStorage legacy migration', () => {
|
||||
let store: Record<string, string>
|
||||
|
||||
beforeEach(() => {
|
||||
store = {}
|
||||
vi.stubGlobal('localStorage', {
|
||||
getItem: vi.fn((key: string) => store[key] ?? null),
|
||||
setItem: vi.fn((key: string, value: string) => { store[key] = value }),
|
||||
})
|
||||
})
|
||||
|
||||
it('copies legacy values to Tolaria keys without overwriting existing values', () => {
|
||||
store[LEGACY_APP_STORAGE_KEYS.theme] = 'dark'
|
||||
store[LEGACY_APP_STORAGE_KEYS.zoom] = '125'
|
||||
store[APP_STORAGE_KEYS.zoom] = '100'
|
||||
|
||||
copyLegacyAppStorageKeys()
|
||||
|
||||
expect(store[APP_STORAGE_KEYS.theme]).toBe('dark')
|
||||
expect(store[APP_STORAGE_KEYS.zoom]).toBe('100')
|
||||
expect(store[APP_STORAGE_KEYS.legacyMigrationFlag]).toBe('1')
|
||||
})
|
||||
|
||||
it('falls back to legacy values when the Tolaria key is absent', () => {
|
||||
store[LEGACY_APP_STORAGE_KEYS.viewMode] = 'editor-list'
|
||||
|
||||
expect(getAppStorageItem('viewMode')).toBe('editor-list')
|
||||
})
|
||||
|
||||
it('returns safely when localStorage is restricted', () => {
|
||||
vi.stubGlobal('localStorage', {
|
||||
getItem: vi.fn(() => { throw new Error('SecurityError') }),
|
||||
setItem: vi.fn(() => { throw new Error('SecurityError') }),
|
||||
})
|
||||
|
||||
expect(() => copyLegacyAppStorageKeys()).not.toThrow()
|
||||
expect(getAppStorageItem('theme')).toBeNull()
|
||||
})
|
||||
})
|
||||
75
product-source/hololake-platform/src/constants/appStorage.ts
Normal file
75
product-source/hololake-platform/src/constants/appStorage.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
export const APP_STORAGE_KEYS = {
|
||||
theme: 'tolaria-theme',
|
||||
zoom: 'tolaria:zoom-level',
|
||||
viewMode: 'tolaria-view-mode',
|
||||
tagColors: 'tolaria:tag-color-overrides',
|
||||
statusColors: 'tolaria:status-color-overrides',
|
||||
propertyModes: 'tolaria:display-mode-overrides',
|
||||
configMigrationFlag: 'tolaria:config-migrated-to-vault',
|
||||
legacyMigrationFlag: 'tolaria:legacy-storage-migrated',
|
||||
sortPreferences: 'tolaria-sort-preferences',
|
||||
sidebarCollapsed: 'tolaria:sidebar-collapsed',
|
||||
layoutPanels: 'tolaria:layout-panels',
|
||||
welcomeDismissed: 'tolaria_welcome_dismissed',
|
||||
} as const
|
||||
|
||||
export const LEGACY_APP_STORAGE_KEYS = {
|
||||
theme: 'laputa-theme',
|
||||
zoom: 'laputa:zoom-level',
|
||||
viewMode: 'laputa-view-mode',
|
||||
tagColors: 'laputa:tag-color-overrides',
|
||||
statusColors: 'laputa:status-color-overrides',
|
||||
propertyModes: 'laputa:display-mode-overrides',
|
||||
configMigrationFlag: 'laputa:config-migrated-to-vault',
|
||||
sortPreferences: 'laputa-sort-preferences',
|
||||
sidebarCollapsed: 'laputa:sidebar-collapsed',
|
||||
layoutPanels: 'laputa:layout-panels',
|
||||
welcomeDismissed: 'laputa_welcome_dismissed',
|
||||
} as const
|
||||
|
||||
type MigratableStorageKey = keyof typeof LEGACY_APP_STORAGE_KEYS
|
||||
|
||||
const MIGRATABLE_STORAGE_KEYS: MigratableStorageKey[] = [
|
||||
'theme',
|
||||
'zoom',
|
||||
'viewMode',
|
||||
'tagColors',
|
||||
'statusColors',
|
||||
'propertyModes',
|
||||
'configMigrationFlag',
|
||||
'sortPreferences',
|
||||
'sidebarCollapsed',
|
||||
'layoutPanels',
|
||||
'welcomeDismissed',
|
||||
]
|
||||
|
||||
export function copyLegacyAppStorageKeys(): void {
|
||||
try {
|
||||
if (localStorage.getItem(APP_STORAGE_KEYS.legacyMigrationFlag) === '1') return
|
||||
|
||||
for (const key of MIGRATABLE_STORAGE_KEYS) {
|
||||
const storageKey = Reflect.get(APP_STORAGE_KEYS, key) as string
|
||||
const legacyStorageKey = Reflect.get(LEGACY_APP_STORAGE_KEYS, key) as string
|
||||
if (localStorage.getItem(storageKey) !== null) continue
|
||||
|
||||
const legacyValue = localStorage.getItem(legacyStorageKey)
|
||||
if (legacyValue !== null) {
|
||||
localStorage.setItem(storageKey, legacyValue)
|
||||
}
|
||||
}
|
||||
|
||||
localStorage.setItem(APP_STORAGE_KEYS.legacyMigrationFlag, '1')
|
||||
} catch {
|
||||
// Ignore unavailable or restricted localStorage implementations.
|
||||
}
|
||||
}
|
||||
|
||||
export function getAppStorageItem(key: MigratableStorageKey): string | null {
|
||||
try {
|
||||
const storageKey = Reflect.get(APP_STORAGE_KEYS, key) as string
|
||||
const legacyStorageKey = Reflect.get(LEGACY_APP_STORAGE_KEYS, key) as string
|
||||
return localStorage.getItem(storageKey) ?? localStorage.getItem(legacyStorageKey)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
12
product-source/hololake-platform/src/constants/feedback.ts
Normal file
12
product-source/hololake-platform/src/constants/feedback.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
export const REFACTORING_HOME_URL = 'https://refactoring.fm/'
|
||||
export const CODACY_HOME_URL = 'https://www.codacy.com/'
|
||||
export const CODESCENE_HOME_URL = 'https://codescene.com/'
|
||||
export const CIRCLECI_HOME_URL = 'https://circleci.com/'
|
||||
export const UNBLOCKED_HOME_URL = 'https://getunblocked.com/'
|
||||
export const TOLARIA_DOCS_URL = 'https://guanghulab.com/fifth-domain/bingshuo/hololake-platform/src/branch/main/docs'
|
||||
export const TOLARIA_FIRST_LAUNCH_DOCS_URL = TOLARIA_DOCS_URL
|
||||
export const TOLARIA_PRODUCT_BOARD_URL = 'https://guanghulab.com/fifth-domain/bingshuo/hololake-platform/issues'
|
||||
export const TOLARIA_GITHUB_DISCUSSIONS_URL = 'https://guanghulab.com/fifth-domain/bingshuo/hololake-platform/issues'
|
||||
export const TOLARIA_GITHUB_CONTRIBUTING_URL = 'https://guanghulab.com/fifth-domain/bingshuo/hololake-platform'
|
||||
export const TOLARIA_GITHUB_ISSUES_URL = 'https://guanghulab.com/fifth-domain/bingshuo/hololake-platform/issues'
|
||||
export const TOLARIA_GITHUB_PULL_REQUESTS_URL = 'https://guanghulab.com/fifth-domain/bingshuo/hololake-platform/pulls'
|
||||
Loading…
Reference in a new issue