fix(web): archived and deleted counts on encryption panel (#1423)

* fix(web): archived and deleted counts on encryption panel

* fix(snjs): yarn build snjs before e2e test suite docker builds
This commit is contained in:
Karol Sójko
2022-08-23 11:38:43 +02:00
committed by GitHub
parent a780fa4e87
commit 2bdd931f6d
9 changed files with 106 additions and 31 deletions

View File

@@ -26,6 +26,8 @@ jobs:
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Install dependencies - name: Install dependencies
run: yarn install --immutable run: yarn install --immutable
- name: Build
run: yarn build:snjs
- name: Login to Docker Hub - name: Login to Docker Hub
uses: docker/login-action@v2 uses: docker/login-action@v2
with: with:

View File

@@ -1,4 +1,4 @@
export type StructuredItemsCount = { export type ItemCounts = {
notes: number notes: number
tags: number tags: number
deleted: number deleted: number

View File

@@ -24,6 +24,7 @@ export * from './Mutator/TransactionalMutation'
export * from './Types/AppDataField' export * from './Types/AppDataField'
export * from './Types/ConflictStrategy' export * from './Types/ConflictStrategy'
export * from './Types/DefaultAppDomain' export * from './Types/DefaultAppDomain'
export * from './Types/ItemCounts'
export * from './Types/ItemStream' export * from './Types/ItemStream'
export * from './Types/MutationType' export * from './Types/MutationType'
export * from './Types/SingletonStrategy' export * from './Types/SingletonStrategy'

View File

@@ -0,0 +1,31 @@
import { ContentType } from '@standardnotes/common'
import { SNNote, SNTag } from '@standardnotes/models'
import { ItemCounter } from './ItemCounter'
describe('ItemCounter', () => {
const createCounter = () => new ItemCounter()
it('should count distinct item counts', () => {
const items = [
{
archived: true,
} as jest.Mocked<SNNote>,
{
trashed: true,
} as jest.Mocked<SNNote>,
{
content_type: ContentType.Note,
} as jest.Mocked<SNNote>,
{
content_type: ContentType.Tag,
} as jest.Mocked<SNTag>,
]
expect(createCounter().countNotesAndTags(items)).toEqual({
archived: 1,
deleted: 1,
notes: 1,
tags: 1,
})
})
})

View File

@@ -0,0 +1,40 @@
import { ContentType } from '@standardnotes/common'
import { SNNote, SNTag, ItemCounts } from '@standardnotes/models'
import { ItemCounterInterface } from './ItemCounterInterface'
export class ItemCounter implements ItemCounterInterface {
countNotesAndTags(items: Array<SNNote | SNTag>): ItemCounts {
const counts: ItemCounts = {
notes: 0,
archived: 0,
deleted: 0,
tags: 0,
}
for (const item of items) {
if (item.archived) {
counts.archived++
continue
}
if (item.trashed) {
counts.deleted++
continue
}
if (item.content_type === ContentType.Note) {
counts.notes++
continue
}
if (item.content_type === ContentType.Tag) {
counts.tags++
continue
}
}
return counts
}
}

View File

@@ -0,0 +1,5 @@
import { SNNote, SNTag, ItemCounts } from '@standardnotes/models'
export interface ItemCounterInterface {
countNotesAndTags(items: Array<SNNote | SNTag>): ItemCounts
}

View File

@@ -50,6 +50,8 @@ export * from './Internal/InternalEventHandlerInterface'
export * from './Internal/InternalEventInterface' export * from './Internal/InternalEventInterface'
export * from './Internal/InternalEventPublishStrategy' export * from './Internal/InternalEventPublishStrategy'
export * from './Internal/InternalEventType' export * from './Internal/InternalEventType'
export * from './Item/ItemCounter'
export * from './Item/ItemCounterInterface'
export * from './Item/ItemManagerInterface' export * from './Item/ItemManagerInterface'
export * from './Item/ItemsClientInterface' export * from './Item/ItemsClientInterface'
export * from './Item/ItemsServerInterface' export * from './Item/ItemsServerInterface'

View File

@@ -1,10 +1,17 @@
import { destroyAllObjectProperties, isDev } from '@/Utils' import { destroyAllObjectProperties, isDev } from '@/Utils'
import { action, computed, makeObservable, observable, runInAction } from 'mobx' import { action, computed, makeObservable, observable, runInAction } from 'mobx'
import { ApplicationEvent, ContentType, InternalEventBus, SNNote, SNTag } from '@standardnotes/snjs' import {
ApplicationEvent,
ContentType,
InternalEventBus,
SNNote,
SNTag,
ItemCounterInterface,
ItemCounts,
} from '@standardnotes/snjs'
import { WebApplication } from '@/Application/Application' import { WebApplication } from '@/Application/Application'
import { AccountMenuPane } from '@/Components/AccountMenu/AccountMenuPane' import { AccountMenuPane } from '@/Components/AccountMenu/AccountMenuPane'
import { AbstractViewController } from '../Abstract/AbstractViewController' import { AbstractViewController } from '../Abstract/AbstractViewController'
import { StructuredItemsCount } from './StructuredItemsCount'
export class AccountMenuController extends AbstractViewController { export class AccountMenuController extends AbstractViewController {
show = false show = false
@@ -28,7 +35,7 @@ export class AccountMenuController extends AbstractViewController {
destroyAllObjectProperties(this) destroyAllObjectProperties(this)
} }
constructor(application: WebApplication, eventBus: InternalEventBus) { constructor(application: WebApplication, eventBus: InternalEventBus, private itemCounter: ItemCounterInterface) {
super(application, eventBus) super(application, eventBus)
makeObservable(this, { makeObservable(this, {
@@ -152,30 +159,7 @@ export class AccountMenuController extends AbstractViewController {
return this.notesAndTags.length return this.notesAndTags.length
} }
get structuredNotesAndTagsCount(): StructuredItemsCount { get structuredNotesAndTagsCount(): ItemCounts {
const count: StructuredItemsCount = { return this.itemCounter.countNotesAndTags(this.notesAndTags)
notes: 0,
archived: 0,
deleted: 0,
tags: 0,
}
for (const item of this.notesAndTags) {
if (item.archived) {
count.archived++
}
if (item.trashed) {
count.deleted++
}
if (item.content_type === ContentType.Note) {
count.notes++
}
if (item.content_type === ContentType.Tag) {
count.tags++
}
}
return count
} }
} }

View File

@@ -2,7 +2,14 @@ import { storage, StorageKey } from '@standardnotes/ui-services'
import { WebApplication } from '@/Application/Application' import { WebApplication } from '@/Application/Application'
import { AccountMenuController } from '@/Controllers/AccountMenu/AccountMenuController' import { AccountMenuController } from '@/Controllers/AccountMenu/AccountMenuController'
import { destroyAllObjectProperties } from '@/Utils' import { destroyAllObjectProperties } from '@/Utils'
import { ApplicationEvent, DeinitSource, WebOrDesktopDeviceInterface, InternalEventBus } from '@standardnotes/snjs' import {
ApplicationEvent,
DeinitSource,
WebOrDesktopDeviceInterface,
InternalEventBus,
ItemCounterInterface,
ItemCounter,
} from '@standardnotes/snjs'
import { action, makeObservable, observable } from 'mobx' import { action, makeObservable, observable } from 'mobx'
import { ActionsMenuController } from './ActionsMenuController' import { ActionsMenuController } from './ActionsMenuController'
import { FeaturesController } from './FeaturesController' import { FeaturesController } from './FeaturesController'
@@ -52,10 +59,13 @@ export class ViewControllerManager {
private appEventObserverRemovers: (() => void)[] = [] private appEventObserverRemovers: (() => void)[] = []
private eventBus: InternalEventBus private eventBus: InternalEventBus
private itemCounter: ItemCounterInterface
constructor(public application: WebApplication, private device: WebOrDesktopDeviceInterface) { constructor(public application: WebApplication, private device: WebOrDesktopDeviceInterface) {
this.eventBus = new InternalEventBus() this.eventBus = new InternalEventBus()
this.itemCounter = new ItemCounter()
this.selectionController = new SelectedItemsController(application, this.eventBus) this.selectionController = new SelectedItemsController(application, this.eventBus)
this.noteTagsController = new NoteTagsController(application, this.eventBus) this.noteTagsController = new NoteTagsController(application, this.eventBus)
@@ -90,7 +100,7 @@ export class ViewControllerManager {
this.noAccountWarningController = new NoAccountWarningController(application, this.eventBus) this.noAccountWarningController = new NoAccountWarningController(application, this.eventBus)
this.accountMenuController = new AccountMenuController(application, this.eventBus) this.accountMenuController = new AccountMenuController(application, this.eventBus, this.itemCounter)
this.subscriptionController = new SubscriptionController(application, this.eventBus) this.subscriptionController = new SubscriptionController(application, this.eventBus)