chore: remove the option to trigger transition from the UI (#2489)
This commit is contained in:
@@ -13,8 +13,6 @@ import {
|
|||||||
MfaServiceInterface,
|
MfaServiceInterface,
|
||||||
GenerateUuid,
|
GenerateUuid,
|
||||||
CreateDecryptedBackupFile,
|
CreateDecryptedBackupFile,
|
||||||
GetTransitionStatus,
|
|
||||||
StartTransition,
|
|
||||||
} from '@standardnotes/services'
|
} from '@standardnotes/services'
|
||||||
import { VaultLockServiceInterface } from './../VaultLock/VaultLockServiceInterface'
|
import { VaultLockServiceInterface } from './../VaultLock/VaultLockServiceInterface'
|
||||||
import { HistoryServiceInterface } from './../History/HistoryServiceInterface'
|
import { HistoryServiceInterface } from './../History/HistoryServiceInterface'
|
||||||
@@ -78,8 +76,6 @@ export interface ApplicationInterface {
|
|||||||
get generateUuid(): GenerateUuid
|
get generateUuid(): GenerateUuid
|
||||||
get getHost(): GetHost
|
get getHost(): GetHost
|
||||||
get setHost(): SetHost
|
get setHost(): SetHost
|
||||||
get getTransitionStatus(): GetTransitionStatus
|
|
||||||
get startTransition(): StartTransition
|
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
get alerts(): AlertService
|
get alerts(): AlertService
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
export enum InternalFeature {
|
export enum InternalFeature {
|
||||||
Vaults = 'vaults',
|
Vaults = 'vaults',
|
||||||
HomeServer = 'home-server',
|
HomeServer = 'home-server',
|
||||||
Transition = 'transition',
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
import { HttpServiceInterface } from '@standardnotes/api'
|
|
||||||
|
|
||||||
import { GetTransitionStatus } from './GetTransitionStatus'
|
|
||||||
|
|
||||||
describe('GetTransitionStatus', () => {
|
|
||||||
let httpService: HttpServiceInterface
|
|
||||||
|
|
||||||
const createUseCase = () => new GetTransitionStatus(httpService)
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
httpService = {
|
|
||||||
get: jest.fn(),
|
|
||||||
} as unknown as HttpServiceInterface
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should get transition status', async () => {
|
|
||||||
const useCase = createUseCase()
|
|
||||||
;(httpService.get as jest.Mock).mockResolvedValueOnce({ status: 200, data: { status: 'TO-DO' } })
|
|
||||||
|
|
||||||
const result = await useCase.execute()
|
|
||||||
|
|
||||||
expect(result.isFailed()).toBe(false)
|
|
||||||
expect(result.getValue()).toBe('TO-DO')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should fail to get transition status', async () => {
|
|
||||||
const useCase = createUseCase()
|
|
||||||
;(httpService.get as jest.Mock).mockResolvedValueOnce({ status: 400 })
|
|
||||||
|
|
||||||
const result = await useCase.execute()
|
|
||||||
|
|
||||||
expect(result.isFailed()).toBe(true)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
|
||||||
import { HttpServiceInterface } from '@standardnotes/api'
|
|
||||||
import { HttpStatusCode } from '@standardnotes/responses'
|
|
||||||
|
|
||||||
export class GetTransitionStatus implements UseCaseInterface<'TO-DO' | 'STARTED' | 'FINISHED' | 'FAILED'> {
|
|
||||||
constructor(private httpService: HttpServiceInterface) {}
|
|
||||||
|
|
||||||
async execute(): Promise<Result<'TO-DO' | 'STARTED' | 'FINISHED' | 'FAILED'>> {
|
|
||||||
const response = await this.httpService.get('/v1/users/transition-status')
|
|
||||||
|
|
||||||
if (response.status !== HttpStatusCode.Success) {
|
|
||||||
return Result.fail('Failed to get transition status')
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.ok((response.data as { status: 'TO-DO' | 'STARTED' | 'FINISHED' | 'FAILED' }).status)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import { HttpServiceInterface } from '@standardnotes/api'
|
|
||||||
|
|
||||||
import { StartTransition } from './StartTransition'
|
|
||||||
|
|
||||||
describe('StartTransition', () => {
|
|
||||||
let httpService: HttpServiceInterface
|
|
||||||
|
|
||||||
const createUseCase = () => new StartTransition(httpService)
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
httpService = {
|
|
||||||
post: jest.fn(),
|
|
||||||
} as unknown as HttpServiceInterface
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should start transition', async () => {
|
|
||||||
const useCase = createUseCase()
|
|
||||||
;(httpService.post as jest.Mock).mockResolvedValueOnce({ status: 200 })
|
|
||||||
|
|
||||||
const result = await useCase.execute()
|
|
||||||
|
|
||||||
expect(result.isFailed()).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should fail to start transition', async () => {
|
|
||||||
const useCase = createUseCase()
|
|
||||||
;(httpService.post as jest.Mock).mockResolvedValueOnce({ status: 400 })
|
|
||||||
|
|
||||||
const result = await useCase.execute()
|
|
||||||
|
|
||||||
expect(result.isFailed()).toBe(true)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import { HttpServiceInterface } from '@standardnotes/api'
|
|
||||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
|
||||||
import { HttpStatusCode } from '@standardnotes/responses'
|
|
||||||
|
|
||||||
export class StartTransition implements UseCaseInterface<void> {
|
|
||||||
constructor(private httpService: HttpServiceInterface) {}
|
|
||||||
|
|
||||||
async execute(): Promise<Result<void>> {
|
|
||||||
const response = await this.httpService.post('/v1/items/transition')
|
|
||||||
|
|
||||||
if (response.status !== HttpStatusCode.Success) {
|
|
||||||
return Result.fail('Failed to start transition')
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.ok()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -187,8 +187,6 @@ export * from './Sync/SyncOptions'
|
|||||||
export * from './Sync/SyncQueueStrategy'
|
export * from './Sync/SyncQueueStrategy'
|
||||||
export * from './Sync/SyncServiceInterface'
|
export * from './Sync/SyncServiceInterface'
|
||||||
export * from './Sync/SyncSource'
|
export * from './Sync/SyncSource'
|
||||||
export * from './UseCase/Transition/GetTransitionStatus/GetTransitionStatus'
|
|
||||||
export * from './UseCase/Transition/StartTransition/StartTransition'
|
|
||||||
export * from './UseCase/ChangeAndSaveItem'
|
export * from './UseCase/ChangeAndSaveItem'
|
||||||
export * from './UseCase/DiscardItemsLocally'
|
export * from './UseCase/DiscardItemsLocally'
|
||||||
export * from './UseCase/GenerateUuid'
|
export * from './UseCase/GenerateUuid'
|
||||||
|
|||||||
@@ -80,8 +80,6 @@ import {
|
|||||||
GenerateUuid,
|
GenerateUuid,
|
||||||
CreateDecryptedBackupFile,
|
CreateDecryptedBackupFile,
|
||||||
CreateEncryptedBackupFile,
|
CreateEncryptedBackupFile,
|
||||||
GetTransitionStatus,
|
|
||||||
StartTransition,
|
|
||||||
WebSocketsService,
|
WebSocketsService,
|
||||||
} from '@standardnotes/services'
|
} from '@standardnotes/services'
|
||||||
import {
|
import {
|
||||||
@@ -1140,14 +1138,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
return this.dependencies.get<SetHost>(TYPES.SetHost)
|
return this.dependencies.get<SetHost>(TYPES.SetHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
get getTransitionStatus(): GetTransitionStatus {
|
|
||||||
return this.dependencies.get<GetTransitionStatus>(TYPES.GetTransitionStatus)
|
|
||||||
}
|
|
||||||
|
|
||||||
get startTransition(): StartTransition {
|
|
||||||
return this.dependencies.get<StartTransition>(TYPES.StartTransition)
|
|
||||||
}
|
|
||||||
|
|
||||||
public get legacyApi(): LegacyApiService {
|
public get legacyApi(): LegacyApiService {
|
||||||
return this.dependencies.get<LegacyApiService>(TYPES.LegacyApiService)
|
return this.dependencies.get<LegacyApiService>(TYPES.LegacyApiService)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,8 +140,6 @@ import {
|
|||||||
CreateDecryptedBackupFile,
|
CreateDecryptedBackupFile,
|
||||||
CreateEncryptedBackupFile,
|
CreateEncryptedBackupFile,
|
||||||
SyncLocalVaultsWithRemoteSharedVaults,
|
SyncLocalVaultsWithRemoteSharedVaults,
|
||||||
GetTransitionStatus,
|
|
||||||
StartTransition,
|
|
||||||
WebSocketsService,
|
WebSocketsService,
|
||||||
} from '@standardnotes/services'
|
} from '@standardnotes/services'
|
||||||
import { ItemManager } from '../../Services/Items/ItemManager'
|
import { ItemManager } from '../../Services/Items/ItemManager'
|
||||||
@@ -155,7 +153,6 @@ import {
|
|||||||
AuthenticatorApiService,
|
AuthenticatorApiService,
|
||||||
AuthenticatorServer,
|
AuthenticatorServer,
|
||||||
HttpService,
|
HttpService,
|
||||||
HttpServiceInterface,
|
|
||||||
RevisionApiService,
|
RevisionApiService,
|
||||||
RevisionServer,
|
RevisionServer,
|
||||||
SharedVaultInvitesServer,
|
SharedVaultInvitesServer,
|
||||||
@@ -1027,14 +1024,6 @@ export class Dependencies {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.factory.set(TYPES.GetTransitionStatus, () => {
|
|
||||||
return new GetTransitionStatus(this.get<HttpServiceInterface>(TYPES.HttpService))
|
|
||||||
})
|
|
||||||
|
|
||||||
this.factory.set(TYPES.StartTransition, () => {
|
|
||||||
return new StartTransition(this.get<HttpServiceInterface>(TYPES.HttpService))
|
|
||||||
})
|
|
||||||
|
|
||||||
this.factory.set(TYPES.ListRevisions, () => {
|
this.factory.set(TYPES.ListRevisions, () => {
|
||||||
return new ListRevisions(this.get<RevisionManager>(TYPES.RevisionManager))
|
return new ListRevisions(this.get<RevisionManager>(TYPES.RevisionManager))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -171,8 +171,6 @@ export const TYPES = {
|
|||||||
AuthorizeVaultDeletion: Symbol.for('AuthorizeVaultDeletion'),
|
AuthorizeVaultDeletion: Symbol.for('AuthorizeVaultDeletion'),
|
||||||
CreateDecryptedBackupFile: Symbol.for('CreateDecryptedBackupFile'),
|
CreateDecryptedBackupFile: Symbol.for('CreateDecryptedBackupFile'),
|
||||||
CreateEncryptedBackupFile: Symbol.for('CreateEncryptedBackupFile'),
|
CreateEncryptedBackupFile: Symbol.for('CreateEncryptedBackupFile'),
|
||||||
GetTransitionStatus: Symbol.for('GetTransitionStatus'),
|
|
||||||
StartTransition: Symbol.for('StartTransition'),
|
|
||||||
|
|
||||||
// Mappers
|
// Mappers
|
||||||
SessionStorageMapper: Symbol.for('SessionStorageMapper'),
|
SessionStorageMapper: Symbol.for('SessionStorageMapper'),
|
||||||
|
|||||||
@@ -245,8 +245,6 @@ export async function awaitFunctionInvokation(object, functionName) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ServerTransitionDelay = 1.5
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signing out of an application deinits it.
|
* Signing out of an application deinits it.
|
||||||
* A new one must be created.
|
* A new one must be created.
|
||||||
@@ -254,7 +252,6 @@ export const ServerTransitionDelay = 1.5
|
|||||||
export async function signOutApplicationAndReturnNew(application) {
|
export async function signOutApplicationAndReturnNew(application) {
|
||||||
const isRealCrypto = application.crypto instanceof SNWebCrypto
|
const isRealCrypto = application.crypto instanceof SNWebCrypto
|
||||||
await application.user.signOut()
|
await application.user.signOut()
|
||||||
await sleep(ServerTransitionDelay, 'transition triggered during sign out')
|
|
||||||
if (isRealCrypto) {
|
if (isRealCrypto) {
|
||||||
return createInitAppWithRealCrypto()
|
return createInitAppWithRealCrypto()
|
||||||
} else {
|
} else {
|
||||||
@@ -265,7 +262,6 @@ export async function signOutApplicationAndReturnNew(application) {
|
|||||||
export async function signOutAndBackIn(application, email, password) {
|
export async function signOutAndBackIn(application, email, password) {
|
||||||
const isRealCrypto = application.crypto instanceof SNWebCrypto
|
const isRealCrypto = application.crypto instanceof SNWebCrypto
|
||||||
await application.user.signOut()
|
await application.user.signOut()
|
||||||
await sleep(ServerTransitionDelay, 'transition triggered during sign out')
|
|
||||||
const newApplication = isRealCrypto ? await createInitAppWithRealCrypto() : await createInitAppWithFakeCrypto()
|
const newApplication = isRealCrypto ? await createInitAppWithRealCrypto() : await createInitAppWithFakeCrypto()
|
||||||
await this.loginToApplication({
|
await this.loginToApplication({
|
||||||
application: newApplication,
|
application: newApplication,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ export class DevMode {
|
|||||||
constructor(private application: WebApplicationInterface) {
|
constructor(private application: WebApplicationInterface) {
|
||||||
InternalFeatureService.get().enableFeature(InternalFeature.Vaults)
|
InternalFeatureService.get().enableFeature(InternalFeature.Vaults)
|
||||||
InternalFeatureService.get().enableFeature(InternalFeature.HomeServer)
|
InternalFeatureService.get().enableFeature(InternalFeature.HomeServer)
|
||||||
InternalFeatureService.get().enableFeature(InternalFeature.Transition)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Valid only when running a mock event publisher on port 3124 */
|
/** Valid only when running a mock event publisher on port 3124 */
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FunctionComponent, useCallback, useEffect, useState } from 'react'
|
import { FunctionComponent, useState } from 'react'
|
||||||
import { observer } from 'mobx-react-lite'
|
import { observer } from 'mobx-react-lite'
|
||||||
|
|
||||||
import { Text, Title } from '@/Components/Preferences/PreferencesComponents/Content'
|
import { Text, Title } from '@/Components/Preferences/PreferencesComponents/Content'
|
||||||
@@ -9,83 +9,15 @@ import { WebApplication } from '@/Application/WebApplication'
|
|||||||
import { formatLastSyncDate } from '@/Utils/DateUtils'
|
import { formatLastSyncDate } from '@/Utils/DateUtils'
|
||||||
import PreferencesGroup from '../../PreferencesComponents/PreferencesGroup'
|
import PreferencesGroup from '../../PreferencesComponents/PreferencesGroup'
|
||||||
import PreferencesSegment from '../../PreferencesComponents/PreferencesSegment'
|
import PreferencesSegment from '../../PreferencesComponents/PreferencesSegment'
|
||||||
import HorizontalSeparator from '@/Components/Shared/HorizontalSeparator'
|
|
||||||
import { featureTrunkTransitionEnabled } from '@/FeatureTrunk'
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
}
|
}
|
||||||
|
|
||||||
const Sync: FunctionComponent<Props> = ({ application }: Props) => {
|
const Sync: FunctionComponent<Props> = ({ application }: Props) => {
|
||||||
const TRANSITION_STATUS_REFRESH_INTERVAL = 5000
|
|
||||||
|
|
||||||
const [isSyncingInProgress, setIsSyncingInProgress] = useState(false)
|
const [isSyncingInProgress, setIsSyncingInProgress] = useState(false)
|
||||||
const [isTransitionInProgress, setIsTransitionInProgress] = useState(false)
|
|
||||||
const [showTransitionSegment, setShowTransitionSegment] = useState(false)
|
|
||||||
const [transitionStatus, setTransitionStatus] = useState('')
|
|
||||||
const [transitionStatusIntervalRef, setTransitionStatusIntervalRef] = useState<NodeJS.Timer | null>(null)
|
|
||||||
const [lastSyncDate, setLastSyncDate] = useState(formatLastSyncDate(application.sync.getLastSyncDate() as Date))
|
const [lastSyncDate, setLastSyncDate] = useState(formatLastSyncDate(application.sync.getLastSyncDate() as Date))
|
||||||
|
|
||||||
const setupTransitionStatusRefresh = useCallback(async () => {
|
|
||||||
const interval = setInterval(async () => {
|
|
||||||
const statusOrError = await application.getTransitionStatus.execute()
|
|
||||||
if (statusOrError.isFailed()) {
|
|
||||||
await application.alerts.alert(statusOrError.getError())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const status = statusOrError.getValue()
|
|
||||||
|
|
||||||
setTransitionStatus(status)
|
|
||||||
}, TRANSITION_STATUS_REFRESH_INTERVAL)
|
|
||||||
|
|
||||||
setTransitionStatusIntervalRef(interval)
|
|
||||||
}, [application, setTransitionStatus, setTransitionStatusIntervalRef])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!featureTrunkTransitionEnabled()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
async function checkTransitionStatus() {
|
|
||||||
const statusOrError = await application.getTransitionStatus.execute()
|
|
||||||
if (statusOrError.isFailed()) {
|
|
||||||
await application.alerts.alert(statusOrError.getError())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const status = statusOrError.getValue()
|
|
||||||
|
|
||||||
if (status === 'FINISHED') {
|
|
||||||
if (transitionStatusIntervalRef) {
|
|
||||||
clearInterval(transitionStatusIntervalRef)
|
|
||||||
}
|
|
||||||
setIsTransitionInProgress(false)
|
|
||||||
setTransitionStatus(status)
|
|
||||||
setShowTransitionSegment(false)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
setShowTransitionSegment(true)
|
|
||||||
setTransitionStatus(status)
|
|
||||||
|
|
||||||
if (status === 'STARTED') {
|
|
||||||
setIsTransitionInProgress(true)
|
|
||||||
if (!transitionStatusIntervalRef) {
|
|
||||||
await setupTransitionStatusRefresh()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkTransitionStatus()
|
|
||||||
}, [
|
|
||||||
application,
|
|
||||||
setIsTransitionInProgress,
|
|
||||||
setTransitionStatus,
|
|
||||||
setShowTransitionSegment,
|
|
||||||
setupTransitionStatusRefresh,
|
|
||||||
transitionStatusIntervalRef,
|
|
||||||
])
|
|
||||||
|
|
||||||
const doSynchronization = async () => {
|
const doSynchronization = async () => {
|
||||||
setIsSyncingInProgress(true)
|
setIsSyncingInProgress(true)
|
||||||
|
|
||||||
@@ -101,19 +33,6 @@ const Sync: FunctionComponent<Props> = ({ application }: Props) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const doTransition = useCallback(async () => {
|
|
||||||
const resultOrError = await application.startTransition.execute()
|
|
||||||
if (resultOrError.isFailed()) {
|
|
||||||
await application.alerts.alert(resultOrError.getError())
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsTransitionInProgress(true)
|
|
||||||
|
|
||||||
await setupTransitionStatusRefresh()
|
|
||||||
}, [application, setupTransitionStatusRefresh])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PreferencesGroup>
|
<PreferencesGroup>
|
||||||
<PreferencesSegment>
|
<PreferencesSegment>
|
||||||
@@ -132,35 +51,6 @@ const Sync: FunctionComponent<Props> = ({ application }: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</PreferencesSegment>
|
</PreferencesSegment>
|
||||||
{showTransitionSegment && (
|
|
||||||
<>
|
|
||||||
<HorizontalSeparator classes="my-4" />
|
|
||||||
<PreferencesSegment>
|
|
||||||
<div className="flex flex-row items-center">
|
|
||||||
<div className="flex flex-grow flex-col">
|
|
||||||
<Title>Transition Account</Title>
|
|
||||||
<Text>
|
|
||||||
Transition your account to our new infrastructure in order to enable new features and improve your
|
|
||||||
overall experience. Depending on the amount of data you have, this process may take a few moments.
|
|
||||||
</Text>
|
|
||||||
{isTransitionInProgress && (
|
|
||||||
<Text>
|
|
||||||
<span className="font-bold">Transition status:</span> {transitionStatus}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
{!isTransitionInProgress && (
|
|
||||||
<Button
|
|
||||||
className="mt-3 min-w-20"
|
|
||||||
label="Start transition"
|
|
||||||
disabled={isTransitionInProgress}
|
|
||||||
onClick={doTransition}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</PreferencesSegment>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</PreferencesGroup>
|
</PreferencesGroup>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,3 @@ export function featureTrunkVaultsEnabled(): boolean {
|
|||||||
export function featureTrunkHomeServerEnabled(): boolean {
|
export function featureTrunkHomeServerEnabled(): boolean {
|
||||||
return InternalFeatureService.get().isFeatureEnabled(InternalFeature.HomeServer)
|
return InternalFeatureService.get().isFeatureEnabled(InternalFeature.HomeServer)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function featureTrunkTransitionEnabled(): boolean {
|
|
||||||
return InternalFeatureService.get().isFeatureEnabled(InternalFeature.Transition)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user