Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
fix: LOPS-185: [FE] resolve issue affecting semantic search when sele…
Browse files Browse the repository at this point in the history
…cting items then changing text in semantic search
  • Loading branch information
yyassi-heartex committed Jun 26, 2023
1 parent 6c32e37 commit 9c37bb5
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions src/stores/Tabs/tab_selected_items.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import { getRoot, types } from "mobx-state-tree";
import { DynamicModel } from "../DynamicModel";
import { StringOrNumber } from "../types";

export const TabSelectedItems = types
.model("TabSelectedItems", {
all: false,
list: types.optional(types.array(types.number), []),
listObject: types.optional(
types.array(
types.late(() => DynamicModel.get("TaskModel")),
)
, []),
list: types.optional(types.array(StringOrNumber), []),
})
.views((self) => ({
get snapshot() {
return {
all: self.all,
[self.listName]: Array.from(self.list),
listObject: Array.from(self.listObject),
};
},

Expand Down Expand Up @@ -69,50 +63,37 @@ export const TabSelectedItems = types
}

self.list = [];
self.listObject = [];
self._invokeChangeEvent();
},

addItem(id) {
const item = getRoot(self).taskStore.list.find(rec => rec.id === id);

self.list.push(id);
self.listObject = [...self.listObject, item.toJSON()];
self._invokeChangeEvent();
},

removeItem(id) {
self.list.splice(self.list.indexOf(id), 1);
self.listObject = self.listObject.filter(rec => rec.id !== id);
self._invokeChangeEvent();
},

toggleItem(id) {
const item = getRoot(self).taskStore.list.find(rec => rec.id === id);

if (self.list.includes(id)) {
self.list.splice(self.list.indexOf(id), 1);
self.listObject = self.listObject.filter(rec => rec.id !== id);
} else {
self.list.push(id);
self.listObject = [...self.listObject, item.toJSON()];
}
self._invokeChangeEvent();
},

update(data) {
const taskStoreList = getRoot(self).taskStore.list;

self.all = data?.all ?? self.all;
self.list = data?.[self.listName] ?? self.list;
self.listObject = data?.[self.listName] ? data?.[self.listName]?.map(id => taskStoreList.find(rec => rec.id === id)) : self.listObject;
self._invokeChangeEvent();
},

clear() {
self.all = false;
self.list = [];
self.listObject = [];
self._invokeChangeEvent();
},

Expand All @@ -121,8 +102,8 @@ export const TabSelectedItems = types
},
}))
.preProcessSnapshot((sn) => {
const { included, excluded, all, listObject } = sn ?? {};
const result = { all, list: sn.list ?? (all ? excluded : included), listObject };
const { included, excluded, all } = sn ?? {};
const result = { all, list: sn.list ?? (all ? excluded : included) };

return result;
});

0 comments on commit 9c37bb5

Please sign in to comment.