From dc7e27b85798f2775d7761202fbcf5cb32f4dd3e Mon Sep 17 00:00:00 2001 From: yyassi-heartex <104568407+yyassi-heartex@users.noreply.github.com> Date: Wed, 29 Nov 2023 13:14:53 -0500 Subject: [PATCH] fix: DIA-666: [FE] Semantic search polish (#266) --- src/components/Filters/types/String.js | 7 ----- src/stores/DataStores/tasks.js | 8 ++++-- src/stores/Tabs/tab.js | 36 ++++++++++++++++++++------ src/stores/types.js | 4 +-- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/components/Filters/types/String.js b/src/components/Filters/types/String.js index 02a25365..00c93fc2 100644 --- a/src/components/Filters/types/String.js +++ b/src/components/Filters/types/String.js @@ -1,7 +1,6 @@ import { observer } from "mobx-react"; import React from "react"; import { FilterInput } from "../FilterInput"; -import { VariantSelect } from "./List"; const BaseInput = observer(({ value, onChange, placeholder }) => { return ( @@ -46,10 +45,4 @@ export const StringFilter = [ valueType: "single", input: (props) => , }, - { - key: "similar_to", - label: "similar to", - valueType: "list", - input: (props) => , - }, ]; diff --git a/src/stores/DataStores/tasks.js b/src/stores/DataStores/tasks.js index 1ea7c0e1..fdd76210 100644 --- a/src/stores/DataStores/tasks.js +++ b/src/stores/DataStores/tasks.js @@ -7,6 +7,7 @@ import { DynamicModel, registerModel } from "../DynamicModel"; import { CustomJSON } from "../types"; import { FF_DEV_2536, FF_LOPS_E_3, isFF } from "../../utils/feature-flags"; +const SIMILARITY_UPPER_LIMIT_PRECISION = 1000; const fileAttributes = types.model({ "certainty": types.optional(types.maybeNull(types.number), 0), "distance": types.optional(types.maybeNull(types.number), 0), @@ -218,17 +219,19 @@ export const create = (columns) => { }, postProcessData(data) { - const { total_annotations, total_predictions } = data; + const { total_annotations, total_predictions, similarity_score_upper_limit } = data; if (total_annotations !== null) self.totalAnnotations = total_annotations; if (total_predictions !== null) self.totalPredictions = total_predictions; + if (!isNaN(similarity_score_upper_limit)) + self.similarityUpperLimit = (Math.ceil(similarity_score_upper_limit * SIMILARITY_UPPER_LIMIT_PRECISION) / SIMILARITY_UPPER_LIMIT_PRECISION); }, })) .preProcessSnapshot((snapshot) => { - const { total_annotations, total_predictions, ...sn } = snapshot; + const { total_annotations, total_predictions, similarity_score_upper_limit, ...sn } = snapshot; return { ...sn, @@ -239,6 +242,7 @@ export const create = (columns) => { })), totalAnnotations: total_annotations, totalPredictions: total_predictions, + similarityUpperLimit: similarity_score_upper_limit, }; }); }; diff --git a/src/stores/Tabs/tab.js b/src/stores/Tabs/tab.js index 72b81e54..204f61ee 100644 --- a/src/stores/Tabs/tab.js +++ b/src/stores/Tabs/tab.js @@ -16,8 +16,10 @@ import { TabSelectedItems } from "./tab_selected_items"; import { History } from '../../utils/history'; import { FF_DEV_1470, FF_LOPS_12, isFF } from "../../utils/feature-flags"; import { CustomJSON, StringOrNumberID, ThresholdType } from "../types"; +import { clamp } from "../../utils/helpers"; -const DEFAULT_THRESHOLD = { min: 0, max: 10 }; +const THRESHOLD_MIN = 0; +const THRESHOLD_MIN_DIFF = 0.001; export const Tab = types .model("View", { @@ -53,7 +55,7 @@ export const Tab = types editable: true, deletable: true, semantic_search: types.optional(types.array(CustomJSON), []), - threshold: types.optional(ThresholdType, DEFAULT_THRESHOLD), + threshold: types.optional(types.maybeNull(ThresholdType), null), }) .volatile(() => { const defaultWidth = getComputedStyle(document.body).getPropertyValue("--menu-sidebar-width").replace("px", "").trim(); @@ -218,7 +220,7 @@ export const Tab = types columnsDisplayType: self.columnsDisplayType.toPOJO(), gridWidth: self.gridWidth, semantic_search: self.semantic_search?.toJSON() ?? [], - threshold: self.threshold?.toJSON() ?? DEFAULT_THRESHOLD, + threshold: self.threshold?.toJSON(), }; if (self.saved || apiVersion === 1) { @@ -305,14 +307,30 @@ export const Tab = types self.selected = ids; }, - setSemanticSearch(semanticSearchList) { + setSemanticSearch(semanticSearchList, min, max) { self.semantic_search = semanticSearchList ?? []; - return self.save(); + /* if no semantic search we have to clean up threshold */ + if (self.semantic_search.length === 0) { + self.threshold = null; + return self.save(); + } + /* if we have a min and max we need to make sure we save that too. + this prevents firing 2 view save requests to accomplish the same thing */ + return ( !isNaN(min) && !isNaN(max) ) ? self.setSemanticSearchThreshold(min, max) : self.save(); }, - setSemanticSearchThreshold(min, max) { - self.threshold = { min, max }; - return self.save(); + setSemanticSearchThreshold(_min, max) { + const min = clamp(_min ?? THRESHOLD_MIN, THRESHOLD_MIN, max - THRESHOLD_MIN_DIFF); + + if (self.semantic_search?.length && !isNaN(min) && !isNaN(max)) { + self.threshold = { min, max }; + return self.save(); + } + }, + + clearSemanticSearchThreshold(save = true) { + self.threshold = null; + return save && self.save(); }, selectAll() { @@ -381,6 +399,8 @@ export const Tab = types } else if (isFF(FF_LOPS_12) && self.root.SDK.type === 'labelops') { yield self.dataStore.reload({ query: self.query, interaction }); } + + getRoot(self).SDK.invoke("tabReloaded", self); }), deleteFilter(filter) { diff --git a/src/stores/types.js b/src/stores/types.js index 0c18ed0a..28d7c70d 100644 --- a/src/stores/types.js +++ b/src/stores/types.js @@ -58,6 +58,6 @@ export const HtmlOrReact = types.custom({ }); export const ThresholdType = types.model("ThresholdType", { - min: types.number, - max: types.number, + min: types.maybeNull(types.number), + max: types.maybeNull(types.number), }); \ No newline at end of file