feat(snjs): add revisions api v2 (#2154)
* feat(snjs): add revisions api v2 * fix(snjs): reference listing and getting revisions in specs * fix(snjs): revisions specs * fix(web): usage of revision metadata * fix(snjs): add specs for decryption revision * fix(snjs): issue with building mocked specs * fix(snjs): adjust revision creation delay
This commit is contained in:
@@ -15,7 +15,8 @@ import {
|
||||
HistoryEntry,
|
||||
NoteHistoryEntry,
|
||||
PayloadEmitSource,
|
||||
RevisionListEntry,
|
||||
RevisionMetadata,
|
||||
RoleName,
|
||||
SNNote,
|
||||
} from '@standardnotes/snjs'
|
||||
import { makeObservable, observable, action } from 'mobx'
|
||||
@@ -29,7 +30,7 @@ type LegacyHistory = Action[]
|
||||
|
||||
type SelectedRevision = HistoryEntry | LegacyHistoryEntry | undefined
|
||||
|
||||
type SelectedEntry = RevisionListEntry | NoteHistoryEntry | Action | undefined
|
||||
type SelectedEntry = RevisionMetadata | NoteHistoryEntry | Action | undefined
|
||||
|
||||
export enum RevisionContentState {
|
||||
Idle,
|
||||
@@ -114,12 +115,12 @@ export class NoteHistoryController {
|
||||
this.contentState = contentState
|
||||
}
|
||||
|
||||
selectRemoteRevision = async (entry: RevisionListEntry) => {
|
||||
selectRemoteRevision = async (entry: RevisionMetadata) => {
|
||||
if (!this.note) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.application.features.hasMinimumRole(entry.required_role)) {
|
||||
if (!this.application.features.hasMinimumRole(entry.required_role as RoleName)) {
|
||||
this.setContentState(RevisionContentState.NotEntitled)
|
||||
this.setSelectedRevision(undefined)
|
||||
return
|
||||
@@ -130,7 +131,14 @@ export class NoteHistoryController {
|
||||
|
||||
try {
|
||||
this.setSelectedEntry(entry)
|
||||
const remoteRevision = await this.application.historyManager.fetchRemoteRevision(this.note, entry)
|
||||
const remoteRevisionOrError = await this.application.getRevision.execute({
|
||||
itemUuid: this.note.uuid,
|
||||
revisionUuid: entry.uuid,
|
||||
})
|
||||
if (remoteRevisionOrError.isFailed()) {
|
||||
throw new Error(remoteRevisionOrError.getError())
|
||||
}
|
||||
const remoteRevision = remoteRevisionOrError.getValue()
|
||||
this.setSelectedRevision(remoteRevision)
|
||||
} catch (err) {
|
||||
this.clearSelection()
|
||||
@@ -211,7 +219,7 @@ export class NoteHistoryController {
|
||||
}
|
||||
}
|
||||
|
||||
selectPrevOrNextRemoteRevision = (revisionEntry: RevisionListEntry) => {
|
||||
selectPrevOrNextRemoteRevision = (revisionEntry: RevisionMetadata) => {
|
||||
const currentIndex = this.flattenedRemoteHistory.findIndex((entry) => entry?.uuid === revisionEntry.uuid)
|
||||
|
||||
const previousEntry = this.flattenedRemoteHistory[currentIndex - 1]
|
||||
@@ -234,9 +242,13 @@ export class NoteHistoryController {
|
||||
if (this.note) {
|
||||
this.setIsFetchingRemoteHistory(true)
|
||||
try {
|
||||
const initialRemoteHistory = await this.application.historyManager.remoteHistoryForItem(this.note)
|
||||
const revisionsListOrError = await this.application.listRevisions.execute({ itemUuid: this.note.uuid })
|
||||
if (revisionsListOrError.isFailed()) {
|
||||
throw new Error(revisionsListOrError.getError())
|
||||
}
|
||||
const revisionsList = revisionsListOrError.getValue()
|
||||
|
||||
this.setRemoteHistory(sortRevisionListIntoGroups<RevisionListEntry>(initialRemoteHistory))
|
||||
this.setRemoteHistory(sortRevisionListIntoGroups<RevisionMetadata>(revisionsList))
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
} finally {
|
||||
@@ -341,7 +353,7 @@ export class NoteHistoryController {
|
||||
this.selectionController.selectItem(duplicatedItem.uuid).catch(console.error)
|
||||
}
|
||||
|
||||
deleteRemoteRevision = async (revisionEntry: RevisionListEntry) => {
|
||||
deleteRemoteRevision = async (revisionEntry: RevisionMetadata) => {
|
||||
const shouldDelete = await this.application.alertService.confirm(
|
||||
'Are you sure you want to delete this revision?',
|
||||
'Delete revision?',
|
||||
@@ -354,10 +366,12 @@ export class NoteHistoryController {
|
||||
return
|
||||
}
|
||||
|
||||
const response = await this.application.historyManager.deleteRemoteRevision(this.note, revisionEntry)
|
||||
|
||||
if (response.error?.message) {
|
||||
throw new Error(response.error.message)
|
||||
const deleteRevisionOrError = await this.application.deleteRevision.execute({
|
||||
itemUuid: this.note.uuid,
|
||||
revisionUuid: revisionEntry.uuid,
|
||||
})
|
||||
if (deleteRevisionOrError.isFailed()) {
|
||||
throw new Error(deleteRevisionOrError.getError())
|
||||
}
|
||||
|
||||
this.clearSelection()
|
||||
|
||||
Reference in New Issue
Block a user