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:
31
packages/services/src/Domain/Item/ItemCounter.spec.ts
Normal file
31
packages/services/src/Domain/Item/ItemCounter.spec.ts
Normal 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,
|
||||
})
|
||||
})
|
||||
})
|
||||
40
packages/services/src/Domain/Item/ItemCounter.ts
Normal file
40
packages/services/src/Domain/Item/ItemCounter.ts
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { SNNote, SNTag, ItemCounts } from '@standardnotes/models'
|
||||
|
||||
export interface ItemCounterInterface {
|
||||
countNotesAndTags(items: Array<SNNote | SNTag>): ItemCounts
|
||||
}
|
||||
@@ -50,6 +50,8 @@ export * from './Internal/InternalEventHandlerInterface'
|
||||
export * from './Internal/InternalEventInterface'
|
||||
export * from './Internal/InternalEventPublishStrategy'
|
||||
export * from './Internal/InternalEventType'
|
||||
export * from './Item/ItemCounter'
|
||||
export * from './Item/ItemCounterInterface'
|
||||
export * from './Item/ItemManagerInterface'
|
||||
export * from './Item/ItemsClientInterface'
|
||||
export * from './Item/ItemsServerInterface'
|
||||
|
||||
Reference in New Issue
Block a user