Fix legacy connection profile migration
This commit is contained in:
@@ -2,7 +2,7 @@ import { AppState } from '../reducers'
|
|||||||
import { ConnectionOptions, createEmptyConnection, makeDefaultConnections } from '../model/ConnectionOptions'
|
import { ConnectionOptions, createEmptyConnection, makeDefaultConnections } from '../model/ConnectionOptions'
|
||||||
import { default as persistantStorage, StorageIdentifier } from '../PersistantStorage'
|
import { default as persistantStorage, StorageIdentifier } from '../PersistantStorage'
|
||||||
import { Dispatch } from 'redux'
|
import { Dispatch } from 'redux'
|
||||||
import { loadLegacyConnectionOptions } from '../model/LegacyConnectionSettings'
|
import { loadLegacyConnectionOptions, clearLegacyConnectionOptions } from '../model/LegacyConnectionSettings'
|
||||||
import {
|
import {
|
||||||
ActionTypes,
|
ActionTypes,
|
||||||
Action,
|
Action,
|
||||||
@@ -92,17 +92,18 @@ export const deleteConnection = (connectionId: string) => (dispatch: Dispatch<an
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ensureConnectionsHaveBeenInitialized() {
|
function ensureConnectionsHaveBeenInitialized() {
|
||||||
const connections = persistantStorage.load(storedConnectionsIdentifier)
|
const connections = persistantStorage.load(storedConnectionsIdentifier)
|
||||||
|
|
||||||
const requiresInitialization = !connections
|
const requiresInitialization = !connections
|
||||||
if (requiresInitialization) {
|
if (requiresInitialization) {
|
||||||
console.log('requires initialization')
|
|
||||||
const migratedConnection = loadLegacyConnectionOptions()
|
const migratedConnection = loadLegacyConnectionOptions()
|
||||||
const defaultConnections = makeDefaultConnections()
|
const defaultConnections = makeDefaultConnections()
|
||||||
persistantStorage.store(storedConnectionsIdentifier, {
|
persistantStorage.store(storedConnectionsIdentifier, {
|
||||||
...migratedConnection,
|
...migratedConnection,
|
||||||
...defaultConnections,
|
...defaultConnections,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
clearLegacyConnectionOptions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export function createEmptyConnection(): ConnectionOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function defaultConnections() {
|
export function makeDefaultConnections() {
|
||||||
return {
|
return {
|
||||||
'iot.eclipse.org': {
|
'iot.eclipse.org': {
|
||||||
...createEmptyConnection(),
|
...createEmptyConnection(),
|
||||||
|
|||||||
Reference in New Issue
Block a user