aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Doc.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-08-27 12:43:33 -0400
committerbobzel <zzzman@gmail.com>2023-08-27 12:43:33 -0400
commit35295e152b138e75e63161d8c644861c5c59f5a3 (patch)
treea243d33430f0b9b1b051a329b0a702a7edc2cc8e /src/fields/Doc.ts
parentf03492f21046840d51ae59de53e87b769f764a79 (diff)
parentbf1777b93be0707e17e3b3c0ca6c965facebfe14 (diff)
Merge branch 'master' into data-visualization-sarah
Diffstat (limited to 'src/fields/Doc.ts')
-rw-r--r--src/fields/Doc.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 92d1aef83..716039568 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -510,6 +510,13 @@ export namespace Doc {
export function IsDelegateField(doc: Doc, fieldKey: string) {
return doc && Get(doc, fieldKey, true) !== undefined;
}
+ //
+ // this will write the value to the key on either the data doc or the embedding doc. The choice
+ // of where to write it is based on:
+ // 1) if the embedding Doc already has this field defined on it, then it will be written to the embedding
+ // 2) if the data doc has the field, then it's written there.
+ // 3) if neither already has the field, then 'defaultProto' determines whether to write it to the data doc (or the embedding)
+ //
export async function SetInPlace(doc: Doc, key: string, value: Field | undefined, defaultProto: boolean) {
if (key.startsWith('_')) key = key.substring(1);
const hasProto = Doc.GetProto(doc) !== doc ? Doc.GetProto(doc) : undefined;
@@ -1476,15 +1483,15 @@ export namespace Doc {
// filters document in a container collection:
// all documents with the specified value for the specified key are included/excluded
// based on the modifiers :"check", "x", undefined
- export function setDocFilter(container: Opt<Doc>, key: string, value: any, modifiers: 'remove' | 'match' | 'check' | 'x' | 'exists' | 'unset', toggle?: boolean, fieldPrefix?: string, append: boolean = true) {
+ export function setDocFilter(container: Opt<Doc>, key: string, value: any, modifiers: 'removeAll' | 'remove' | 'match' | 'check' | 'x' | 'exists' | 'unset', toggle?: boolean, fieldPrefix?: string, append: boolean = true) {
if (!container) return;
const filterField = '_' + (fieldPrefix ? fieldPrefix + '_' : '') + 'childFilters';
const childFilters = StrListCast(container[filterField]);
runInAction(() => {
for (let i = 0; i < childFilters.length; i++) {
const fields = childFilters[i].split(FilterSep); // split key:value:modifier
- if (fields[0] === key && (fields[1] === value || modifiers === 'match' || (fields[2] === 'match' && modifiers === 'remove'))) {
- if (fields[2] === modifiers && modifiers && fields[1] === value) {
+ if (fields[0] === key && (fields[1] === value.toString() || modifiers === 'match' || modifiers === 'removeAll' || (fields[2] === 'match' && modifiers === 'remove'))) {
+ if (fields[2] === modifiers && modifiers && fields[1] === value.toString()) {
if (toggle) modifiers = 'remove';
else return;
}
@@ -1495,7 +1502,7 @@ export namespace Doc {
}
if (!childFilters.length && modifiers === 'match' && value === undefined) {
container[filterField] = undefined;
- } else if (modifiers !== 'remove') {
+ } else if (modifiers !== 'remove' && modifiers !== 'removeAll') {
!append && (childFilters.length = 0);
childFilters.push(key + FilterSep + value + FilterSep + modifiers);
container[filterField] = new List<string>(childFilters);