internal: incomplete vault systems behind feature flag (#2340)
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { ItemCounter } from './ItemCounter'
|
||||
import { NoteContent } from '../../../Syncable/Note/NoteContent'
|
||||
import { ContentType } from '@standardnotes/common'
|
||||
import { DecryptedItem, EncryptedItem } from '../../../Abstract/Item'
|
||||
import { DecryptedPayload, EncryptedPayload, PayloadTimestampDefaults } from '../../../Abstract/Payload'
|
||||
import { ItemCollection } from './ItemCollection'
|
||||
import { FillItemContent } from '../../../Abstract/Content/ItemContent'
|
||||
import { TagItemsIndex } from './TagItemsIndex'
|
||||
import { ItemDelta } from '../../Index/ItemDelta'
|
||||
import { AnyItemInterface } from '../../../Abstract/Item/Interfaces/UnionTypes'
|
||||
|
||||
@@ -48,7 +48,7 @@ describe('tag notes index', () => {
|
||||
|
||||
it('should count both notes and files', () => {
|
||||
const collection = new ItemCollection()
|
||||
const index = new TagItemsIndex(collection)
|
||||
const index = new ItemCounter(collection)
|
||||
|
||||
const decryptedNote = createDecryptedItem('note')
|
||||
const decryptedFile = createDecryptedItem('file')
|
||||
@@ -61,7 +61,7 @@ describe('tag notes index', () => {
|
||||
|
||||
it('should decrement count after decrypted note becomes errored', () => {
|
||||
const collection = new ItemCollection()
|
||||
const index = new TagItemsIndex(collection)
|
||||
const index = new ItemCounter(collection)
|
||||
|
||||
const decryptedItem = createDecryptedItem()
|
||||
collection.set(decryptedItem)
|
||||
@@ -4,25 +4,28 @@ import { isTag, SNTag } from '../../../Syncable/Tag/Tag'
|
||||
import { SNIndex } from '../../Index/SNIndex'
|
||||
import { ItemCollection } from './ItemCollection'
|
||||
import { ItemDelta } from '../../Index/ItemDelta'
|
||||
import { isDecryptedItem, ItemInterface } from '../../../Abstract/Item'
|
||||
import { DecryptedItemInterface, isDecryptedItem, ItemInterface } from '../../../Abstract/Item'
|
||||
import { CriteriaValidatorInterface } from '../../Display/Validator/CriteriaValidatorInterface'
|
||||
import { CollectionCriteriaValidator } from '../../Display/Validator/CollectionCriteriaValidator'
|
||||
import { ExcludeVaultsCriteriaValidator } from '../../Display/Validator/ExcludeVaultsCriteriaValidator'
|
||||
import { ExclusiveVaultCriteriaValidator } from '../../Display/Validator/ExclusiveVaultCriteriaValidator'
|
||||
import { HiddenContentCriteriaValidator } from '../../Display/Validator/HiddenContentCriteriaValidator'
|
||||
import { CustomFilterCriteriaValidator } from '../../Display/Validator/CustomFilterCriteriaValidator'
|
||||
import { AnyDisplayOptions, VaultDisplayOptions } from '../../Display'
|
||||
import { isExclusioanaryOptionsValue } from '../../Display/VaultDisplayOptionsTypes'
|
||||
|
||||
type AllNotesUuidSignifier = undefined
|
||||
export type TagItemCountChangeObserver = (tagUuid: string | AllNotesUuidSignifier) => void
|
||||
|
||||
export class TagItemsIndex implements SNIndex {
|
||||
export class ItemCounter implements SNIndex {
|
||||
private tagToItemsMap: Partial<Record<string, Set<string>>> = {}
|
||||
private allCountableItems = new Set<string>()
|
||||
private countableItemsByType = new Map<ContentType, Set<string>>()
|
||||
private displayOptions?: AnyDisplayOptions
|
||||
private vaultDisplayOptions?: VaultDisplayOptions
|
||||
|
||||
constructor(private collection: ItemCollection, public observers: TagItemCountChangeObserver[] = []) {}
|
||||
|
||||
private isItemCountable = (item: ItemInterface) => {
|
||||
if (isDecryptedItem(item)) {
|
||||
return !item.archived && !item.trashed && !item.conflictOf
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public addCountChangeObserver(observer: TagItemCountChangeObserver): () => void {
|
||||
this.observers.push(observer)
|
||||
|
||||
@@ -32,10 +35,14 @@ export class TagItemsIndex implements SNIndex {
|
||||
}
|
||||
}
|
||||
|
||||
private notifyObservers(tagUuid: string | undefined) {
|
||||
for (const observer of this.observers) {
|
||||
observer(tagUuid)
|
||||
}
|
||||
public setDisplayOptions(options: AnyDisplayOptions) {
|
||||
this.displayOptions = options
|
||||
this.receiveItemChanges(this.collection.all())
|
||||
}
|
||||
|
||||
public setVaultDisplayOptions(options: VaultDisplayOptions) {
|
||||
this.vaultDisplayOptions = options
|
||||
this.receiveItemChanges(this.collection.all())
|
||||
}
|
||||
|
||||
public allCountableItemsCount(): number {
|
||||
@@ -64,6 +71,47 @@ export class TagItemsIndex implements SNIndex {
|
||||
this.receiveTagChanges(tags)
|
||||
}
|
||||
|
||||
private passesAllFilters(element: DecryptedItemInterface): boolean {
|
||||
if (!this.displayOptions) {
|
||||
return true
|
||||
}
|
||||
|
||||
const filters: CriteriaValidatorInterface[] = [new CollectionCriteriaValidator(this.collection, element)]
|
||||
|
||||
if (this.vaultDisplayOptions) {
|
||||
const options = this.vaultDisplayOptions.getOptions()
|
||||
if (isExclusioanaryOptionsValue(options)) {
|
||||
filters.push(new ExcludeVaultsCriteriaValidator([...options.exclude, ...options.locked], element))
|
||||
} else {
|
||||
filters.push(new ExclusiveVaultCriteriaValidator(options.exclusive, element))
|
||||
}
|
||||
}
|
||||
|
||||
if ('hiddenContentTypes' in this.displayOptions && this.displayOptions.hiddenContentTypes) {
|
||||
filters.push(new HiddenContentCriteriaValidator(this.displayOptions.hiddenContentTypes, element))
|
||||
}
|
||||
|
||||
if ('customFilter' in this.displayOptions && this.displayOptions.customFilter) {
|
||||
filters.push(new CustomFilterCriteriaValidator(this.displayOptions.customFilter, element))
|
||||
}
|
||||
|
||||
return filters.every((f) => f.passes())
|
||||
}
|
||||
|
||||
private isItemCountable = (item: ItemInterface) => {
|
||||
if (isDecryptedItem(item)) {
|
||||
const passesFilters = this.passesAllFilters(item)
|
||||
return passesFilters && !item.archived && !item.trashed && !item.conflictOf
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private notifyObservers(tagUuid: string | undefined) {
|
||||
for (const observer of this.observers) {
|
||||
observer(tagUuid)
|
||||
}
|
||||
}
|
||||
|
||||
private receiveTagChanges(tags: SNTag[]): void {
|
||||
for (const tag of tags) {
|
||||
const uuids = tag.references
|
||||
Reference in New Issue
Block a user