Merge branch 'mp/os1/metadata-remove' (#2401)

* origin/mp/os1/metadata-remove:
  groups: reduce metadata updates, removal
  chat: reducer handles metadata removal

Signed-off-by: Jared Tobin <jared@tlon.io>
This commit is contained in:
Jared Tobin 2020-03-05 14:35:01 +04:00
commit 2bf46d7d26
No known key found for this signature in database
GPG Key ID: 0E4647D58F8A69E4
2 changed files with 40 additions and 1 deletions

View File

@ -7,6 +7,7 @@ export class MetadataReducer {
this.associations(data, state);
this.add(data, state);
this.update(data, state);
this.remove(data, state);
}
}
@ -39,4 +40,13 @@ export class MetadataReducer {
state.associations = metadata;
}
}
remove(json, state) {
let data = _.get(json, 'remove', false);
if (data) {
let metadata = state.associations;
metadata.delete(data["app-path"]);
state.associations = metadata;
}
}
}

View File

@ -6,6 +6,8 @@ export class MetadataReducer {
if (data) {
this.associations(data, state);
this.add(data, state);
this.update(data, state);
this.remove(data, state);
}
}
@ -34,8 +36,35 @@ export class MetadataReducer {
}
metadata[data['group-path']]
[`${data["group-path"]}/${data["app-name"]}${data["app-path"]}`] = data;
state.associations = metadata;
}
}
update(json, state) {
let data = _.get(json, 'update-metadata', false);
if (data) {
let metadata = state.associations;
if (!(data["group-path"] in metadata)) {
metadata[data["group-path"]] = {};
}
metadata[data["group-path"]][
`${data["group-path"]}/${data["app-name"]}${data["app-path"]}`
] = data;
state.associations = metadata;
}
}
remove(json, state) {
let data = _.get(json, 'remove', false);
if (data) {
let metadata = state.associations;
if (data['group-path'] in metadata) {
let path =
`${data['group-path']}/${data['app-name']}${data['app-path']}`
delete metadata[data["group-path"]][path];
state.associations = metadata;
}
}
}
}