From 9b25816b6a432e7cc5c1722d6be3ad846aaa61ff Mon Sep 17 00:00:00 2001 From: Jonathan Payne Date: Thu, 3 Dec 2026 03:49:09 -0500 Subject: [PATCH 1/2] OpenConceptLab/ocl_online#870 | The bridge can be chosen as soon as it has loaded, and a saved one runs only for a user who is still offered it On a new project the bridge stayed greyed out until another field changed, because its answer was read once, before it had loaded. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AaZ4qTEw8c6qZh5C69F1V4 --- src/components/map-projects/MapProject.jsx | 20 +++++++++++++++---- .../__tests__/autoMatchRows.test.js | 16 ++++++++++++++- src/components/map-projects/autoMatchRows.js | 9 +++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/components/map-projects/MapProject.jsx b/src/components/map-projects/MapProject.jsx index 5db29a09..8cbc861c 100644 --- a/src/components/map-projects/MapProject.jsx +++ b/src/components/map-projects/MapProject.jsx @@ -90,7 +90,7 @@ import MapProjectDeleteConfirmDialog from './MapProjectDeleteConfirmDialog'; import ConfigurationForm from './ConfigurationForm' import Controls from './Controls' import DataGridControls from './DataGridControls' -import { getPreviewEligibleRowIndexes, getRowsToProcess, countAIOnlyRows, getAutoMatchAIOnOpen, takeRunRows, clearRunRowStatuses, canRunAlgorithm, spendsMatchQuota, shouldStopAIStep, getAIRequestIdempotencyKey, getCandidatePoolFingerprint, hasCurrentAnalysis, getScispacyRowResults, getPendingRowLookups, waitForLookups, AI_LOOKUP_WAIT_MS, RERANK_LOOKUP_WAIT_MS, RERANK_MAX_IN_FLIGHT, isScispacyWarmingUp } from './autoMatchRows' +import { getPreviewEligibleRowIndexes, getRowsToProcess, countAIOnlyRows, getAutoMatchAIOnOpen, takeRunRows, clearRunRowStatuses, canRunAlgorithm, getBridgeToLoad, spendsMatchQuota, shouldStopAIStep, getAIRequestIdempotencyKey, getCandidatePoolFingerprint, hasCurrentAnalysis, getScispacyRowResults, getPendingRowLookups, waitForLookups, AI_LOOKUP_WAIT_MS, RERANK_LOOKUP_WAIT_MS, RERANK_MAX_IN_FLIGHT, isScispacyWarmingUp } from './autoMatchRows' import { aiOnByDefault, getMaxRunRows, getMapperSettings } from '@openconceptlab/oclmap-extensions' import { createAutosaveScheduler, createLatestSender, isToldOnLeave, recordReadOnlyRefusal, saveOnLeave, sendAfter, trackSave, whenSaved, installUnloadGuard, SAVE_SKIPPED } from './autosave' import { blockLeaving, continueLeaving, createEditTracker, createRunClosers, getRunLeaveMessageKey, isUnsavedNewProject, shouldAskBeforeLeaving, shouldWarnBeforeUnload } from './leaveGuard' @@ -195,6 +195,18 @@ const MapProject = () => { }, [location.search]) const bridgeRef = React.useRef() + // In state, so that the page shows BridgeMatch's answer, which comes only once it has loaded. + // It sets its ref on every render, so null alone doesn't mean that it's gone. + const [canBridge, setCanBridge] = React.useState(false) + const setBridgeMatch = React.useCallback(bridgeMatch => { + bridgeRef.current = bridgeMatch + if(bridgeMatch) + setCanBridge(Boolean(bridgeMatch.canBridge())) + }, []) + React.useEffect(() => { + if(!bridgeRef.current) + setCanBridge(false) + }) // Column mapping of the project being copied, applied to the next upload. const templateColumnsRef = React.useRef([]) const facetsRequestsRef = React.useRef({}) @@ -790,7 +802,6 @@ const MapProject = () => { // gets the project's template and its default model. const { canSelectAIModel, canSetAIOutputLocale } = getAIAssistantChoices(user) const CANDIDATES_LIMIT = 15 - const canBridge = bridgeRef?.current?.canBridge() const canScispacy = Boolean( hasCapability(user, 'users.mapper_scispacy') && canBridge && SCISPACY_API_URL && toggles.SCISPACY_LOINC_TOGGLE === true ) @@ -842,7 +853,8 @@ const MapProject = () => { // canBridge comes from the BridgeMatch component, which only mounts once it has a // bridge repo. Before any bridge algo is selected (new project) fall back to the // one the API offers, otherwise the option can never be enabled to select it. - const bridgeProbeAlgo = bridgeAlgo || find(apiAlgos, a => ['ocl-bridge', 'ocl-ciel-bridge'].includes(a.type)) + // A saved bridge this user isn't offered doesn't mount it, so it doesn't run. + const bridgeProbeAlgo = getBridgeToLoad(bridgeAlgo, apiAlgos) React.useEffect(() => { if (!OCL_ONLINE_API_URL) return; @@ -6602,7 +6614,7 @@ const MapProject = () => { bridgeRepoVersion={bridgeProbeAlgo?.target_repo_version} limit={CANDIDATES_LIMIT} user={user} - ref={bridgeRef} + ref={setBridgeMatch} mappedRepoURLs={mappedSrcs.map(source => source.url)} /> })() diff --git a/src/components/map-projects/__tests__/autoMatchRows.test.js b/src/components/map-projects/__tests__/autoMatchRows.test.js index 79249f4c..06191cca 100644 --- a/src/components/map-projects/__tests__/autoMatchRows.test.js +++ b/src/components/map-projects/__tests__/autoMatchRows.test.js @@ -4,7 +4,7 @@ import assert from 'node:assert/strict' import { getPreviewEligibleRowIndexes, getRowsToProcess, spendsMatchQuota, takeRunRows, clearRunRowStatuses, shouldStopAIStep, getAIRequestIdempotencyKey, getCandidatePoolFingerprint, hasCurrentAnalysis, getScispacyRowResults, getPendingRowLookups, waitForLookups, RERANK_LOOKUP_WAIT_MS, AI_LOOKUP_WAIT_MS, isScispacyWarmingUp, RERANK_MAX_IN_FLIGHT, - countAIOnlyRows, getAutoMatchBlocker, getAutoMatchAIDefault, getAutoMatchAIOnOpen, canRunAlgorithm + countAIOnlyRows, getAutoMatchBlocker, getAutoMatchAIDefault, getAutoMatchAIOnOpen, canRunAlgorithm, getBridgeToLoad } from '../autoMatchRows.js' import { createLimiter } from '../../../services/capacity.js' @@ -404,6 +404,20 @@ test('canRunAlgorithm: a bridge runs only for a user who can bridge', () => { }) }) +test('getBridgeToLoad: a project\'s own bridge loads only for a user still offered it', () => { + const saved = { id: 'bridge', type: 'ocl-bridge', target_repo_url: '/orgs/A/sources/Saved/' } + const offered = { id: 'bridge', type: 'ocl-bridge', target_repo_url: '/orgs/A/sources/Offered/' } + assert.equal(getBridgeToLoad(saved, [{ id: 'search', type: 'ocl-search' }, offered]), saved) + assert.equal(getBridgeToLoad(saved, [{ id: 'other', type: 'ocl-bridge' }]), undefined) + assert.equal(getBridgeToLoad(saved, []), undefined) +}) + +test('getBridgeToLoad: a project without one loads the first bridge the user could add', () => { + const offered = [{ id: 'search', type: 'ocl-search' }, { id: 'first', type: 'ocl-ciel-bridge' }, { id: 'second', type: 'ocl-bridge' }] + assert.equal(getBridgeToLoad(undefined, offered).id, 'first') + assert.equal(getBridgeToLoad(undefined, undefined), undefined) +}) + test('canRunAlgorithm: ScispaCy runs only for a user who can run it', () => { assert.equal(canRunAlgorithm({ type: 'ocl-scispacy' }, { canBridge: true }), false) assert.equal(canRunAlgorithm({ type: 'ocl-scispacy' }, { canScispacy: true }), true) diff --git a/src/components/map-projects/autoMatchRows.js b/src/components/map-projects/autoMatchRows.js index f01e8139..1b7fb066 100644 --- a/src/components/map-projects/autoMatchRows.js +++ b/src/components/map-projects/autoMatchRows.js @@ -55,6 +55,15 @@ export const canRunAlgorithm = (algo, { canBridge = false, canScispacy = false } return ['custom', 'ocl-search', 'ocl-semantic'].includes(algo?.type) } +// The bridge to load: the project's own, if this user is still offered it, or, +// in a project without one, the first they could add. +export const getBridgeToLoad = (projectBridge, offeredAlgos) => { + const offered = offeredAlgos || [] + return projectBridge + ? offered.some(algo => algo?.id === projectBridge.id) ? projectBridge : undefined + : offered.find(algo => ['ocl-bridge', 'ocl-ciel-bridge'].includes(algo?.type)) +} + // The rows a run includes: the first maxRows of them, or all of them when // maxRows is null. export const takeRunRows = (rows, maxRows) => { From dae09267d55521a246c6732f9a86948105b29288 Mon Sep 17 00:00:00 2001 From: Jonathan Payne Date: Thu, 3 Dec 2026 03:57:48 -0500 Subject: [PATCH 2/2] OpenConceptLab/ocl_online#870 | Plainer bridge choice Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AaZ4qTEw8c6qZh5C69F1V4 --- src/components/map-projects/MapProject.jsx | 1 - src/components/map-projects/autoMatchRows.js | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/map-projects/MapProject.jsx b/src/components/map-projects/MapProject.jsx index 8cbc861c..cf3424dd 100644 --- a/src/components/map-projects/MapProject.jsx +++ b/src/components/map-projects/MapProject.jsx @@ -853,7 +853,6 @@ const MapProject = () => { // canBridge comes from the BridgeMatch component, which only mounts once it has a // bridge repo. Before any bridge algo is selected (new project) fall back to the // one the API offers, otherwise the option can never be enabled to select it. - // A saved bridge this user isn't offered doesn't mount it, so it doesn't run. const bridgeProbeAlgo = getBridgeToLoad(bridgeAlgo, apiAlgos) React.useEffect(() => { if (!OCL_ONLINE_API_URL) return; diff --git a/src/components/map-projects/autoMatchRows.js b/src/components/map-projects/autoMatchRows.js index 1b7fb066..c0027bb7 100644 --- a/src/components/map-projects/autoMatchRows.js +++ b/src/components/map-projects/autoMatchRows.js @@ -58,10 +58,9 @@ export const canRunAlgorithm = (algo, { canBridge = false, canScispacy = false } // The bridge to load: the project's own, if this user is still offered it, or, // in a project without one, the first they could add. export const getBridgeToLoad = (projectBridge, offeredAlgos) => { - const offered = offeredAlgos || [] - return projectBridge - ? offered.some(algo => algo?.id === projectBridge.id) ? projectBridge : undefined - : offered.find(algo => ['ocl-bridge', 'ocl-ciel-bridge'].includes(algo?.type)) + if(projectBridge) + return offeredAlgos?.some(algo => algo?.id === projectBridge.id) ? projectBridge : undefined + return offeredAlgos?.find(algo => ['ocl-bridge', 'ocl-ciel-bridge'].includes(algo?.type)) } // The rows a run includes: the first maxRows of them, or all of them when