From 0263d0789d16cbbef956fe879245b379edfd3ce6 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 6 Jun 2024 05:13:19 +0530 Subject: [PATCH] feat: selector already in workflow --- server/src/workflow-management/selector.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/server/src/workflow-management/selector.ts b/server/src/workflow-management/selector.ts index 61ad07b9..79bbbc07 100644 --- a/server/src/workflow-management/selector.ts +++ b/server/src/workflow-management/selector.ts @@ -686,9 +686,24 @@ export const getSelectors = async (page: Page, coordinates: Coordinates) => { return null; }; - - - +/** + * Returns the first pair from the given workflow that contains the given selector + * inside the where condition, and it is the only selector there. + * If a match is not found, returns undefined. + * @param selector The selector to find. + * @param workflow The workflow to search in. + * @category WorkflowManagement + * @returns {Promise} + */ +export const selectorAlreadyInWorkflow = (selector: string, workflow: Workflow) => { + return workflow.find((pair: WhereWhatPair) => { + if (pair.where.selectors?.includes(selector)) { + if (pair.where.selectors?.length === 1) { + return pair; + } + } + }); +};