From 559124f2cd41ce0dad69bbf71a5d4006717aa506 Mon Sep 17 00:00:00 2001 From: Jonathan Payne Date: Thu, 19 Nov 2026 07:14:39 -0500 Subject: [PATCH 1/7] OpenConceptLab/ocl_online#700 | The new-project form shows a line the API sends about the chosen owner's projects Under Project Owner, while the project is new, the form asks the API for GET /capabilities/mapper.projects/note/?owner=&lang= and shows the `message` string it sends, again whenever the owner changes. With no such route, a failure or no string, nothing shows. The Mapper holds no wording or numbers of its own. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AaZ4qTJedFKZzhLXoHiTaG --- .../common/__tests__/capabilityNote.test.js | 25 +++++++++++++ src/components/common/capabilityNote.js | 17 +++++++++ src/components/common/useCapabilityNote.js | 36 +++++++++++++++++++ .../map-projects/ConfigurationForm.jsx | 8 +++++ 4 files changed, 86 insertions(+) create mode 100644 src/components/common/__tests__/capabilityNote.test.js create mode 100644 src/components/common/capabilityNote.js create mode 100644 src/components/common/useCapabilityNote.js diff --git a/src/components/common/__tests__/capabilityNote.test.js b/src/components/common/__tests__/capabilityNote.test.js new file mode 100644 index 0000000..2cea533 --- /dev/null +++ b/src/components/common/__tests__/capabilityNote.test.js @@ -0,0 +1,25 @@ +import test from 'node:test' +import assert from 'node:assert/strict' + +const { getCapabilityNoteRequest, toCapabilityNote } = await import('../capabilityNote.js') + +const REQUEST = {baseURL: 'https://api.example.org/', token: 'personal-token', capability: 'example.capability', owner: '/orgs/Example/', lang: 'pt-BR'} + +test('asks the API about the capability for the chosen owner, in the UI language, with the person\'s token', () => { + assert.deepEqual(getCapabilityNoteRequest(REQUEST), { + url: 'https://api.example.org/capabilities/example.capability/note/', + params: {owner: '/orgs/Example/', lang: 'pt-BR'}, + headers: {Authorization: 'Token personal-token'}, + }) +}) + +test('no API URL, token, capability or owner: no request', () => { + for(const field of ['baseURL', 'token', 'capability', 'owner']) + assert.equal(getCapabilityNoteRequest({...REQUEST, [field]: ''}), null, field) +}) + +test('shows only a non-empty string it is sent', () => { + assert.equal(toCapabilityNote({message: ' A line from the API. '}), 'A line from the API.') + for(const data of [undefined, null, {}, {message: null}, {message: ''}, {message: ' '}, {message: 3}, {message: {text: 'x'}}, 'text']) + assert.equal(toCapabilityNote(data), null, JSON.stringify(data)) +}) diff --git a/src/components/common/capabilityNote.js b/src/components/common/capabilityNote.js new file mode 100644 index 0000000..bbab83e --- /dev/null +++ b/src/components/common/capabilityNote.js @@ -0,0 +1,17 @@ +// A line the API may send to show beside a form, about a capability and the +// owner the form is for (OpenConceptLab/ocl_online#700). Open code shows only +// the text it's sent: an API without the route sends nothing, and nothing shows. + +export const getCapabilityNoteRequest = ({baseURL, token, capability, owner, lang}) => { + if(!baseURL || !token || !capability || !owner) + return null + return { + url: `${baseURL.replace(/\/+$/, '')}/capabilities/${capability}/note/`, + params: {owner, lang}, + headers: {Authorization: `Token ${token}`}, + } +} + +// Only a non-empty string becomes a line. +export const toCapabilityNote = data => + typeof data?.message === 'string' && data.message.trim() ? data.message.trim() : null diff --git a/src/components/common/useCapabilityNote.js b/src/components/common/useCapabilityNote.js new file mode 100644 index 0000000..095fb0f --- /dev/null +++ b/src/components/common/useCapabilityNote.js @@ -0,0 +1,36 @@ +import React from 'react' +import axios from 'axios' +import { useTranslation } from 'react-i18next' + +import { currentUserToken, getAPIURL } from '../../common/utils' +import { getCapabilityNoteRequest, toCapabilityNote } from './capabilityNote' + +// The API's line about `capability` for `owner`, asked for again when the +// owner changes; null while `enabled` is false, and when the API sends none, +// fails or has no such route. axios directly, not APIService, so a missing +// route or a refusal skips its sign-out and throttling handling. +const useCapabilityNote = (capability, owner, enabled = true) => { + const { i18n } = useTranslation() + const [note, setNote] = React.useState(null) + + React.useEffect(() => { + setNote(null) + const request = enabled ? + getCapabilityNoteRequest({baseURL: getAPIURL(), token: currentUserToken(), capability, owner, lang: i18n.language}) : + null + if(!request) + return undefined + // a reply for an owner no longer chosen is dropped + let current = true + axios.get(request.url, {params: request.params, headers: request.headers, timeout: 10000}) + .then(response => current && setNote(toCapabilityNote(response.data))) + .catch(() => {}) + return () => { + current = false + } + }, [capability, owner, enabled, i18n.language]) + + return note +} + +export default useCapabilityNote diff --git a/src/components/map-projects/ConfigurationForm.jsx b/src/components/map-projects/ConfigurationForm.jsx index ba2f2ba..1c58e41 100644 --- a/src/components/map-projects/ConfigurationForm.jsx +++ b/src/components/map-projects/ConfigurationForm.jsx @@ -31,6 +31,7 @@ import { MATCHING_ALGORITHMS_DOC_LINK, MAPPER_DOCS_LINK } from '../../common/con import { COLORS } from '../../common/colors' import { getProjectConfigErrors } from './algorithms' import NamespaceDropdown from '../common/NamespaceDropdown' +import useCapabilityNote from '../common/useCapabilityNote' import RepoSearchAutocomplete from '../repos/RepoSearchAutocomplete' import RepoVersionSearchAutocomplete from '../repos/RepoVersionSearchAutocomplete' import CloseIconButton from '../common/CloseIconButton'; @@ -117,6 +118,9 @@ const ConfigurationForm = ({ project, handleFileUpload, file, owner, setOwner, n canUseCustomAlgorithms, }) const hasAccessErrors = accessErrors.length > 0 + // While the project is new, any line the API sends about the projects + // the chosen owner has (OpenConceptLab/ocl_online#700). + const projectsNote = useCapabilityNote('mapper.projects', owner, !project?.id) // Project-config validation. Currently flags custom algos with missing / // malformed canonical_url. Returned as a structured list so the banner @@ -162,6 +166,10 @@ const ConfigurationForm = ({ project, handleFileUpload, file, owner, setOwner, n personalOnly={!canUseOrgProjects} sx={{marginTop: '12px'}} /> + { + projectsNote && + {projectsNote} + } Date: Thu, 19 Nov 2026 07:22:14 -0500 Subject: [PATCH 2/7] OpenConceptLab/ocl_online#700 | Review pass 1: the line is the owner field's own helper text, and shows only for the owner it was sent for - F1.1: NamespaceDropdown takes helperText, so the line is the field's description (aria-describedby) and its changes are announced politely. - F1.2: each line is kept with the capability, owner and language it was asked for, so a new owner never shows the last one's while its own is on the way. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AaZ4qTJedFKZzhLXoHiTaG --- src/components/common/NamespaceDropdown.jsx | 45 ++++++++++--------- .../common/__tests__/capabilityNote.test.js | 17 ++++++- src/components/common/capabilityNote.js | 8 ++++ src/components/common/useCapabilityNote.js | 15 ++++--- .../map-projects/ConfigurationForm.jsx | 5 +-- 5 files changed, 58 insertions(+), 32 deletions(-) diff --git a/src/components/common/NamespaceDropdown.jsx b/src/components/common/NamespaceDropdown.jsx index e1214df..0e2fa3f 100644 --- a/src/components/common/NamespaceDropdown.jsx +++ b/src/components/common/NamespaceDropdown.jsx @@ -25,7 +25,7 @@ const OwnerOption = ({ option, selected, ...rest }) => { } -const NamespaceDropdown = ({onChange, label, id, owner, backgroundColor, asOwner, personalOnly, size, disabled, sx}) => { +const NamespaceDropdown = ({onChange, label, id, owner, backgroundColor, asOwner, personalOnly, size, disabled, sx, helperText}) => { const { t } = useTranslation() const user = getCurrentUser() const [ownerOptions, setOwnerOptions] = React.useState([]) @@ -67,25 +67,30 @@ const NamespaceDropdown = ({onChange, label, id, owner, backgroundColor, asOwner renderOption={(props, option, { selected }) => } onChange={onChange} renderInput={ - params => ( - - {selectedOption.icon} - - ) - } - } : params.slotProps} - /> - ) + params => { + const slotProps = selectedOption?.icon ? { + ...params.slotProps, + input: { + ...params.slotProps?.input, + startAdornment: ( + + {selectedOption.icon} + + ) + } + } : params.slotProps + return ( + + ) + } } sx={sx} /> diff --git a/src/components/common/__tests__/capabilityNote.test.js b/src/components/common/__tests__/capabilityNote.test.js index 2cea533..acd1929 100644 --- a/src/components/common/__tests__/capabilityNote.test.js +++ b/src/components/common/__tests__/capabilityNote.test.js @@ -1,7 +1,7 @@ import test from 'node:test' import assert from 'node:assert/strict' -const { getCapabilityNoteRequest, toCapabilityNote } = await import('../capabilityNote.js') +const { getCapabilityNoteRequest, getKeptCapabilityNote, toCapabilityNote, toCapabilityNoteKey } = await import('../capabilityNote.js') const REQUEST = {baseURL: 'https://api.example.org/', token: 'personal-token', capability: 'example.capability', owner: '/orgs/Example/', lang: 'pt-BR'} @@ -23,3 +23,18 @@ test('shows only a non-empty string it is sent', () => { for(const data of [undefined, null, {}, {message: null}, {message: ''}, {message: ' '}, {message: 3}, {message: {text: 'x'}}, 'text']) assert.equal(toCapabilityNote(data), null, JSON.stringify(data)) }) + +test('a line is shown only for the owner and language it was sent for', () => { + const key = toCapabilityNoteKey({capability: 'example.capability', owner: '/orgs/Example/', lang: 'en'}) + const kept = {key, note: 'A line from the API.'} + assert.equal(getKeptCapabilityNote(kept, key), 'A line from the API.') + assert.equal(getKeptCapabilityNote(kept, toCapabilityNoteKey({capability: 'example.capability', owner: '/users/someone/', lang: 'en'})), null) + assert.equal(getKeptCapabilityNote(kept, toCapabilityNoteKey({capability: 'example.capability', owner: '/orgs/Example/', lang: 'es'})), null) + assert.equal(getKeptCapabilityNote(null, key), null) +}) + +test('nothing to ask about while disabled or with no owner', () => { + assert.equal(toCapabilityNoteKey({capability: 'example.capability', owner: '/orgs/Example/', lang: 'en', enabled: false}), null) + assert.equal(toCapabilityNoteKey({capability: 'example.capability', owner: '', lang: 'en'}), null) + assert.equal(getKeptCapabilityNote({key: null, note: 'x'}, null), null) +}) diff --git a/src/components/common/capabilityNote.js b/src/components/common/capabilityNote.js index bbab83e..e5d973c 100644 --- a/src/components/common/capabilityNote.js +++ b/src/components/common/capabilityNote.js @@ -15,3 +15,11 @@ export const getCapabilityNoteRequest = ({baseURL, token, capability, owner, lan // Only a non-empty string becomes a line. export const toCapabilityNote = data => typeof data?.message === 'string' && data.message.trim() ? data.message.trim() : null + +// What a line is for: the capability, the owner and the language. None while +// there's nothing to ask about. +export const toCapabilityNoteKey = ({capability, owner, lang, enabled = true}) => + enabled && capability && owner ? JSON.stringify([capability, owner, lang]) : null + +// The line kept for `key`, never one kept for another owner or language. +export const getKeptCapabilityNote = (kept, key) => key && kept?.key === key ? kept.note : null diff --git a/src/components/common/useCapabilityNote.js b/src/components/common/useCapabilityNote.js index 095fb0f..990667f 100644 --- a/src/components/common/useCapabilityNote.js +++ b/src/components/common/useCapabilityNote.js @@ -3,7 +3,7 @@ import axios from 'axios' import { useTranslation } from 'react-i18next' import { currentUserToken, getAPIURL } from '../../common/utils' -import { getCapabilityNoteRequest, toCapabilityNote } from './capabilityNote' +import { getCapabilityNoteRequest, getKeptCapabilityNote, toCapabilityNote, toCapabilityNoteKey } from './capabilityNote' // The API's line about `capability` for `owner`, asked for again when the // owner changes; null while `enabled` is false, and when the API sends none, @@ -11,11 +11,12 @@ import { getCapabilityNoteRequest, toCapabilityNote } from './capabilityNote' // route or a refusal skips its sign-out and throttling handling. const useCapabilityNote = (capability, owner, enabled = true) => { const { i18n } = useTranslation() - const [note, setNote] = React.useState(null) + const key = toCapabilityNoteKey({capability, owner, lang: i18n.language, enabled}) + // each line is kept with what it's for, so a new owner never shows the last one's + const [kept, setKept] = React.useState(null) React.useEffect(() => { - setNote(null) - const request = enabled ? + const request = key ? getCapabilityNoteRequest({baseURL: getAPIURL(), token: currentUserToken(), capability, owner, lang: i18n.language}) : null if(!request) @@ -23,14 +24,14 @@ const useCapabilityNote = (capability, owner, enabled = true) => { // a reply for an owner no longer chosen is dropped let current = true axios.get(request.url, {params: request.params, headers: request.headers, timeout: 10000}) - .then(response => current && setNote(toCapabilityNote(response.data))) + .then(response => current && setKept({key, note: toCapabilityNote(response.data)})) .catch(() => {}) return () => { current = false } - }, [capability, owner, enabled, i18n.language]) + }, [key]) - return note + return getKeptCapabilityNote(kept, key) } export default useCapabilityNote diff --git a/src/components/map-projects/ConfigurationForm.jsx b/src/components/map-projects/ConfigurationForm.jsx index 1c58e41..190804e 100644 --- a/src/components/map-projects/ConfigurationForm.jsx +++ b/src/components/map-projects/ConfigurationForm.jsx @@ -165,11 +165,8 @@ const ConfigurationForm = ({ project, handleFileUpload, file, owner, setOwner, n asOwner personalOnly={!canUseOrgProjects} sx={{marginTop: '12px'}} + helperText={projectsNote} /> - { - projectsNote && - {projectsNote} - } Date: Thu, 19 Nov 2026 07:29:24 -0500 Subject: [PATCH 3/7] OpenConceptLab/ocl_online#700 | Review pass 2: a live region there before the line announces it, and asking again drops the kept line - F2.1: the form keeps a visually hidden status region mounted, so the line is announced when it arrives; the helper text stays the field's description. - F2.2: the hook's state is a reducer (capabilityNoteReducer): every ask drops the kept line, and only a reply to the latest ask is kept, so returning to an owner waits for a fresh reply and a failed one shows nothing. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AaZ4qTJedFKZzhLXoHiTaG --- src/components/common/NamespaceDropdown.jsx | 4 +- .../common/__tests__/capabilityNote.test.js | 37 ++++++++++++++----- src/components/common/capabilityNote.js | 14 ++++++- src/components/common/useCapabilityNote.js | 21 ++++++----- .../map-projects/ConfigurationForm.jsx | 4 ++ 5 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/components/common/NamespaceDropdown.jsx b/src/components/common/NamespaceDropdown.jsx index 0e2fa3f..bf3fd98 100644 --- a/src/components/common/NamespaceDropdown.jsx +++ b/src/components/common/NamespaceDropdown.jsx @@ -85,9 +85,9 @@ const NamespaceDropdown = ({onChange, label, id, owner, backgroundColor, asOwner label={label} size={size || 'medium'} sx={{backgroundColor: backgroundColor || 'primary.contrastText'}} - // the field's description, and announced when it changes + // the field's description (aria-describedby) helperText={helperText} - slotProps={helperText ? {...slotProps, formHelperText: {'aria-live': 'polite'}} : slotProps} + slotProps={slotProps} /> ) } diff --git a/src/components/common/__tests__/capabilityNote.test.js b/src/components/common/__tests__/capabilityNote.test.js index acd1929..575e132 100644 --- a/src/components/common/__tests__/capabilityNote.test.js +++ b/src/components/common/__tests__/capabilityNote.test.js @@ -1,7 +1,9 @@ import test from 'node:test' import assert from 'node:assert/strict' -const { getCapabilityNoteRequest, getKeptCapabilityNote, toCapabilityNote, toCapabilityNoteKey } = await import('../capabilityNote.js') +const { + capabilityNoteReducer, getCapabilityNoteRequest, getKeptCapabilityNote, toCapabilityNote, toCapabilityNoteKey, +} = await import('../capabilityNote.js') const REQUEST = {baseURL: 'https://api.example.org/', token: 'personal-token', capability: 'example.capability', owner: '/orgs/Example/', lang: 'pt-BR'} @@ -24,17 +26,34 @@ test('shows only a non-empty string it is sent', () => { assert.equal(toCapabilityNote(data), null, JSON.stringify(data)) }) -test('a line is shown only for the owner and language it was sent for', () => { - const key = toCapabilityNoteKey({capability: 'example.capability', owner: '/orgs/Example/', lang: 'en'}) - const kept = {key, note: 'A line from the API.'} - assert.equal(getKeptCapabilityNote(kept, key), 'A line from the API.') - assert.equal(getKeptCapabilityNote(kept, toCapabilityNoteKey({capability: 'example.capability', owner: '/users/someone/', lang: 'en'})), null) - assert.equal(getKeptCapabilityNote(kept, toCapabilityNoteKey({capability: 'example.capability', owner: '/orgs/Example/', lang: 'es'})), null) - assert.equal(getKeptCapabilityNote(null, key), null) +const keyFor = (owner, lang = 'en') => toCapabilityNoteKey({capability: 'example.capability', owner, lang}) +const ORG = keyFor('/orgs/Example/') +const PERSONAL = keyFor('/users/someone/') +const run = actions => actions.reduce(capabilityNoteReducer, {asked: null, kept: null}) + +test('a line shows for the owner and language it was sent for, once it arrives', () => { + assert.equal(getKeptCapabilityNote(run([{type: 'ask', key: ORG}]), ORG), null) + const replied = run([{type: 'ask', key: ORG}, {type: 'reply', key: ORG, note: 'A line from the API.'}]) + assert.equal(getKeptCapabilityNote(replied, ORG), 'A line from the API.') + assert.equal(getKeptCapabilityNote(replied, PERSONAL), null) + assert.equal(getKeptCapabilityNote(replied, keyFor('/orgs/Example/', 'es')), null) +}) + +test('a new owner never shows the last one\'s line, and returning waits for a fresh reply', () => { + const asked = [{type: 'ask', key: PERSONAL}, {type: 'reply', key: PERSONAL, note: 'Personal line.'}, {type: 'ask', key: ORG}] + assert.equal(getKeptCapabilityNote(run(asked), ORG), null) + // back to the first owner before the organization replies, and its new request fails (no reply) + const back = run([...asked, {type: 'ask', key: PERSONAL}]) + assert.equal(getKeptCapabilityNote(back, PERSONAL), null) + // the organization's late reply is dropped + assert.equal(getKeptCapabilityNote(run([...asked, {type: 'ask', key: PERSONAL}, {type: 'reply', key: ORG, note: 'Org line.'}]), PERSONAL), null) + assert.equal(getKeptCapabilityNote(run([...asked, {type: 'ask', key: PERSONAL}, {type: 'reply', key: ORG, note: 'Org line.'}]), ORG), null) }) test('nothing to ask about while disabled or with no owner', () => { assert.equal(toCapabilityNoteKey({capability: 'example.capability', owner: '/orgs/Example/', lang: 'en', enabled: false}), null) assert.equal(toCapabilityNoteKey({capability: 'example.capability', owner: '', lang: 'en'}), null) - assert.equal(getKeptCapabilityNote({key: null, note: 'x'}, null), null) + const disabled = run([{type: 'ask', key: ORG}, {type: 'reply', key: ORG, note: 'x'}, {type: 'ask', key: null}, {type: 'reply', key: null, note: 'y'}]) + assert.equal(getKeptCapabilityNote(disabled, null), null) + assert.equal(getKeptCapabilityNote(disabled, ORG), null) }) diff --git a/src/components/common/capabilityNote.js b/src/components/common/capabilityNote.js index e5d973c..6bff0f6 100644 --- a/src/components/common/capabilityNote.js +++ b/src/components/common/capabilityNote.js @@ -21,5 +21,17 @@ export const toCapabilityNote = data => export const toCapabilityNoteKey = ({capability, owner, lang, enabled = true}) => enabled && capability && owner ? JSON.stringify([capability, owner, lang]) : null +// What the form has asked for (`asked`) and the line kept for it. Asking for +// anything drops the kept line, so a line shows only after a reply to the +// latest ask: never the last owner's, or an earlier one's when its new +// request fails. A reply to anything but the latest ask is dropped. +export const capabilityNoteReducer = (state, action) => { + if(action.type === 'ask') + return {asked: action.key, kept: null} + if(action.type === 'reply' && action.key && action.key === state?.asked) + return {...state, kept: {key: action.key, note: action.note}} + return state +} + // The line kept for `key`, never one kept for another owner or language. -export const getKeptCapabilityNote = (kept, key) => key && kept?.key === key ? kept.note : null +export const getKeptCapabilityNote = (state, key) => key && state?.kept?.key === key ? state.kept.note : null diff --git a/src/components/common/useCapabilityNote.js b/src/components/common/useCapabilityNote.js index 990667f..024dc13 100644 --- a/src/components/common/useCapabilityNote.js +++ b/src/components/common/useCapabilityNote.js @@ -3,35 +3,38 @@ import axios from 'axios' import { useTranslation } from 'react-i18next' import { currentUserToken, getAPIURL } from '../../common/utils' -import { getCapabilityNoteRequest, getKeptCapabilityNote, toCapabilityNote, toCapabilityNoteKey } from './capabilityNote' +import { + capabilityNoteReducer, getCapabilityNoteRequest, getKeptCapabilityNote, toCapabilityNote, toCapabilityNoteKey +} from './capabilityNote' // The API's line about `capability` for `owner`, asked for again when the -// owner changes; null while `enabled` is false, and when the API sends none, -// fails or has no such route. axios directly, not APIService, so a missing -// route or a refusal skips its sign-out and throttling handling. +// owner changes; null while `enabled` is false, until the reply arrives, and +// when the API sends none, fails or has no such route. axios directly, not +// APIService, so a missing route or a refusal skips its sign-out and +// throttling handling. const useCapabilityNote = (capability, owner, enabled = true) => { const { i18n } = useTranslation() const key = toCapabilityNoteKey({capability, owner, lang: i18n.language, enabled}) - // each line is kept with what it's for, so a new owner never shows the last one's - const [kept, setKept] = React.useState(null) + const [state, dispatch] = React.useReducer(capabilityNoteReducer, {asked: null, kept: null}) React.useEffect(() => { + dispatch({type: 'ask', key}) const request = key ? getCapabilityNoteRequest({baseURL: getAPIURL(), token: currentUserToken(), capability, owner, lang: i18n.language}) : null if(!request) return undefined - // a reply for an owner no longer chosen is dropped + // only this request's reply, while it's the latest let current = true axios.get(request.url, {params: request.params, headers: request.headers, timeout: 10000}) - .then(response => current && setKept({key, note: toCapabilityNote(response.data)})) + .then(response => current && dispatch({type: 'reply', key, note: toCapabilityNote(response.data)})) .catch(() => {}) return () => { current = false } }, [key]) - return getKeptCapabilityNote(kept, key) + return getKeptCapabilityNote(state, key) } export default useCapabilityNote diff --git a/src/components/map-projects/ConfigurationForm.jsx b/src/components/map-projects/ConfigurationForm.jsx index 190804e..cf556e8 100644 --- a/src/components/map-projects/ConfigurationForm.jsx +++ b/src/components/map-projects/ConfigurationForm.jsx @@ -17,11 +17,13 @@ import SettingsIcon from '@mui/icons-material/Settings'; import SaveIcon from '@mui/icons-material/Save'; import OpenInNewIcon from '@mui/icons-material/OpenInNew'; +import Box from '@mui/material/Box' import Stack from '@mui/material/Stack' import Alert from '@mui/material/Alert' import Tooltip from '@mui/material/Tooltip' import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined' +import { visuallyHidden } from '@mui/utils' import isEmpty from 'lodash/isEmpty' import omit from 'lodash/omit' import filter from 'lodash/filter' @@ -167,6 +169,8 @@ const ConfigurationForm = ({ project, handleFileUpload, file, owner, setOwner, n sx={{marginTop: '12px'}} helperText={projectsNote} /> + {/* announces the line when it arrives: a live region is heard only when it's there before its text */} + {projectsNote || ''} Date: Thu, 19 Nov 2026 07:33:59 -0500 Subject: [PATCH 4/7] OpenConceptLab/ocl_online#700 | Review pass 3: a new owner drops the kept line in the render that brings it F3.1: useKeptCapabilityNote (capabilityNote.js) asks again during the render whose key changed, so no render shows a line kept for another owner, or for this one before it was asked again, whenever the effects run. The fetch stays in useCapabilityNote. A lifecycle test mounts the hook and switches owners away and back. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AaZ4qTJedFKZzhLXoHiTaG --- .../__integration__/capabilityNote.test.js | 59 +++++++++++++++++++ src/components/common/capabilityNote.js | 12 ++++ src/components/common/useCapabilityNote.js | 11 ++-- 3 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 src/components/common/__integration__/capabilityNote.test.js diff --git a/src/components/common/__integration__/capabilityNote.test.js b/src/components/common/__integration__/capabilityNote.test.js new file mode 100644 index 0000000..d51d2c0 --- /dev/null +++ b/src/components/common/__integration__/capabilityNote.test.js @@ -0,0 +1,59 @@ +/** + * The kept line under a form field follows the owner chosen now + * (OpenConceptLab/ocl_online#700): switching away and straight back never + * shows the line kept for the earlier choice, not even for one render. + */ +import test from 'node:test' +import assert from 'node:assert/strict' +import React from 'react' +import { render, act, cleanup } from '@testing-library/react' + +import { toCapabilityNoteKey, useKeptCapabilityNote } from '../capabilityNote.js' + +const keyFor = owner => toCapabilityNoteKey({capability: 'example.capability', owner, lang: 'en'}) +const PERSONAL = keyFor('/users/someone/') +const ORG = keyFor('/orgs/Example/') + +// Records what every render showed. +const renderNotes = () => { + const shown = [] + let keep + const Note = ({noteKey}) => { + const [note, keepNote] = useKeptCapabilityNote(noteKey) + keep = keepNote + shown.push(note) + return React.createElement('span', {'data-testid': 'note'}, note || '') + } + return {Note, shown, keep: (...args) => act(() => keep(...args))} +} + +test('switching away and straight back never shows the earlier line', () => { + const { Note, shown, keep } = renderNotes() + const { rerender, getByTestId } = render(React.createElement(Note, {noteKey: PERSONAL})) + keep(PERSONAL, 'Personal line.') + assert.equal(getByTestId('note').textContent, 'Personal line.') + + shown.length = 0 + rerender(React.createElement(Note, {noteKey: ORG})) + rerender(React.createElement(Note, {noteKey: PERSONAL})) + assert.deepEqual(shown.filter(Boolean), [], 'no render after the switch showed a line') + assert.equal(getByTestId('note').textContent, '') + + // the organization's late reply is dropped; the fresh personal one shows + keep(ORG, 'Org line.') + assert.equal(getByTestId('note').textContent, '') + keep(PERSONAL, 'Personal line again.') + assert.equal(getByTestId('note').textContent, 'Personal line again.') + cleanup() +}) + +test('nothing while there is nothing to ask about', () => { + const { Note, keep } = renderNotes() + const { rerender, getByTestId } = render(React.createElement(Note, {noteKey: ORG})) + keep(ORG, 'Org line.') + rerender(React.createElement(Note, {noteKey: null})) + assert.equal(getByTestId('note').textContent, '') + keep(null, 'Stray line.') + assert.equal(getByTestId('note').textContent, '') + cleanup() +}) diff --git a/src/components/common/capabilityNote.js b/src/components/common/capabilityNote.js index 6bff0f6..a6ed253 100644 --- a/src/components/common/capabilityNote.js +++ b/src/components/common/capabilityNote.js @@ -1,6 +1,7 @@ // A line the API may send to show beside a form, about a capability and the // owner the form is for (OpenConceptLab/ocl_online#700). Open code shows only // the text it's sent: an API without the route sends nothing, and nothing shows. +import React from 'react' export const getCapabilityNoteRequest = ({baseURL, token, capability, owner, lang}) => { if(!baseURL || !token || !capability || !owner) @@ -35,3 +36,14 @@ export const capabilityNoteReducer = (state, action) => { // The line kept for `key`, never one kept for another owner or language. export const getKeptCapabilityNote = (state, key) => key && state?.kept?.key === key ? state.kept.note : null + +// The line kept for `key`, and `keep(key, note)` for a reply. A new key asks +// again during the render that brings it, so not even one render shows a line +// kept for another owner, or for this one before it was asked again. +export const useKeptCapabilityNote = key => { + const [state, dispatch] = React.useReducer(capabilityNoteReducer, {asked: null, kept: null}) + if(state.asked !== key) + dispatch({type: 'ask', key}) + const keep = React.useCallback((replyKey, note) => dispatch({type: 'reply', key: replyKey, note}), []) + return [state.asked === key ? getKeptCapabilityNote(state, key) : null, keep] +} diff --git a/src/components/common/useCapabilityNote.js b/src/components/common/useCapabilityNote.js index 024dc13..d695037 100644 --- a/src/components/common/useCapabilityNote.js +++ b/src/components/common/useCapabilityNote.js @@ -3,9 +3,7 @@ import axios from 'axios' import { useTranslation } from 'react-i18next' import { currentUserToken, getAPIURL } from '../../common/utils' -import { - capabilityNoteReducer, getCapabilityNoteRequest, getKeptCapabilityNote, toCapabilityNote, toCapabilityNoteKey -} from './capabilityNote' +import { getCapabilityNoteRequest, toCapabilityNote, toCapabilityNoteKey, useKeptCapabilityNote } from './capabilityNote' // The API's line about `capability` for `owner`, asked for again when the // owner changes; null while `enabled` is false, until the reply arrives, and @@ -15,10 +13,9 @@ import { const useCapabilityNote = (capability, owner, enabled = true) => { const { i18n } = useTranslation() const key = toCapabilityNoteKey({capability, owner, lang: i18n.language, enabled}) - const [state, dispatch] = React.useReducer(capabilityNoteReducer, {asked: null, kept: null}) + const [note, keep] = useKeptCapabilityNote(key) React.useEffect(() => { - dispatch({type: 'ask', key}) const request = key ? getCapabilityNoteRequest({baseURL: getAPIURL(), token: currentUserToken(), capability, owner, lang: i18n.language}) : null @@ -27,14 +24,14 @@ const useCapabilityNote = (capability, owner, enabled = true) => { // only this request's reply, while it's the latest let current = true axios.get(request.url, {params: request.params, headers: request.headers, timeout: 10000}) - .then(response => current && dispatch({type: 'reply', key, note: toCapabilityNote(response.data)})) + .then(response => current && keep(key, toCapabilityNote(response.data))) .catch(() => {}) return () => { current = false } }, [key]) - return getKeptCapabilityNote(state, key) + return note } export default useCapabilityNote From e3ed6164659952220a4649c6b9642c59c81da971 Mon Sep 17 00:00:00 2001 From: Jonathan Payne Date: Thu, 19 Nov 2026 07:36:44 -0500 Subject: [PATCH 5/7] OpenConceptLab/ocl_online#700 | Simplification: the reducer keeps only the line for the latest ask, and the tests don't repeat each other Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AaZ4qTJedFKZzhLXoHiTaG --- .../__integration__/capabilityNote.test.js | 11 ------- .../common/__tests__/capabilityNote.test.js | 32 +++++++------------ src/components/common/capabilityNote.js | 19 +++++------ 3 files changed, 20 insertions(+), 42 deletions(-) diff --git a/src/components/common/__integration__/capabilityNote.test.js b/src/components/common/__integration__/capabilityNote.test.js index d51d2c0..80ec91b 100644 --- a/src/components/common/__integration__/capabilityNote.test.js +++ b/src/components/common/__integration__/capabilityNote.test.js @@ -46,14 +46,3 @@ test('switching away and straight back never shows the earlier line', () => { assert.equal(getByTestId('note').textContent, 'Personal line again.') cleanup() }) - -test('nothing while there is nothing to ask about', () => { - const { Note, keep } = renderNotes() - const { rerender, getByTestId } = render(React.createElement(Note, {noteKey: ORG})) - keep(ORG, 'Org line.') - rerender(React.createElement(Note, {noteKey: null})) - assert.equal(getByTestId('note').textContent, '') - keep(null, 'Stray line.') - assert.equal(getByTestId('note').textContent, '') - cleanup() -}) diff --git a/src/components/common/__tests__/capabilityNote.test.js b/src/components/common/__tests__/capabilityNote.test.js index 575e132..94805ef 100644 --- a/src/components/common/__tests__/capabilityNote.test.js +++ b/src/components/common/__tests__/capabilityNote.test.js @@ -2,7 +2,7 @@ import test from 'node:test' import assert from 'node:assert/strict' const { - capabilityNoteReducer, getCapabilityNoteRequest, getKeptCapabilityNote, toCapabilityNote, toCapabilityNoteKey, + capabilityNoteReducer, getCapabilityNoteRequest, toCapabilityNote, toCapabilityNoteKey, } = await import('../capabilityNote.js') const REQUEST = {baseURL: 'https://api.example.org/', token: 'personal-token', capability: 'example.capability', owner: '/orgs/Example/', lang: 'pt-BR'} @@ -29,31 +29,23 @@ test('shows only a non-empty string it is sent', () => { const keyFor = (owner, lang = 'en') => toCapabilityNoteKey({capability: 'example.capability', owner, lang}) const ORG = keyFor('/orgs/Example/') const PERSONAL = keyFor('/users/someone/') -const run = actions => actions.reduce(capabilityNoteReducer, {asked: null, kept: null}) - -test('a line shows for the owner and language it was sent for, once it arrives', () => { - assert.equal(getKeptCapabilityNote(run([{type: 'ask', key: ORG}]), ORG), null) - const replied = run([{type: 'ask', key: ORG}, {type: 'reply', key: ORG, note: 'A line from the API.'}]) - assert.equal(getKeptCapabilityNote(replied, ORG), 'A line from the API.') - assert.equal(getKeptCapabilityNote(replied, PERSONAL), null) - assert.equal(getKeptCapabilityNote(replied, keyFor('/orgs/Example/', 'es')), null) +const run = actions => actions.reduce(capabilityNoteReducer, {asked: null, note: null}) + +test('a line is kept once the reply to the latest ask arrives', () => { + assert.deepEqual(run([{type: 'ask', key: ORG}]), {asked: ORG, note: null}) + assert.deepEqual(run([{type: 'ask', key: ORG}, {type: 'reply', key: ORG, note: 'A line.'}]), {asked: ORG, note: 'A line.'}) }) -test('a new owner never shows the last one\'s line, and returning waits for a fresh reply', () => { +test('asking again drops the line, and a reply to an earlier ask is dropped', () => { const asked = [{type: 'ask', key: PERSONAL}, {type: 'reply', key: PERSONAL, note: 'Personal line.'}, {type: 'ask', key: ORG}] - assert.equal(getKeptCapabilityNote(run(asked), ORG), null) - // back to the first owner before the organization replies, and its new request fails (no reply) - const back = run([...asked, {type: 'ask', key: PERSONAL}]) - assert.equal(getKeptCapabilityNote(back, PERSONAL), null) - // the organization's late reply is dropped - assert.equal(getKeptCapabilityNote(run([...asked, {type: 'ask', key: PERSONAL}, {type: 'reply', key: ORG, note: 'Org line.'}]), PERSONAL), null) - assert.equal(getKeptCapabilityNote(run([...asked, {type: 'ask', key: PERSONAL}, {type: 'reply', key: ORG, note: 'Org line.'}]), ORG), null) + assert.deepEqual(run(asked), {asked: ORG, note: null}) + // back to the first owner before the organization replies; its new request fails (no reply), and the organization's + // late reply is dropped + assert.deepEqual(run([...asked, {type: 'ask', key: PERSONAL}, {type: 'reply', key: ORG, note: 'Org line.'}]), {asked: PERSONAL, note: null}) }) test('nothing to ask about while disabled or with no owner', () => { assert.equal(toCapabilityNoteKey({capability: 'example.capability', owner: '/orgs/Example/', lang: 'en', enabled: false}), null) assert.equal(toCapabilityNoteKey({capability: 'example.capability', owner: '', lang: 'en'}), null) - const disabled = run([{type: 'ask', key: ORG}, {type: 'reply', key: ORG, note: 'x'}, {type: 'ask', key: null}, {type: 'reply', key: null, note: 'y'}]) - assert.equal(getKeptCapabilityNote(disabled, null), null) - assert.equal(getKeptCapabilityNote(disabled, ORG), null) + assert.deepEqual(run([{type: 'ask', key: ORG}, {type: 'reply', key: ORG, note: 'x'}, {type: 'ask', key: null}, {type: 'reply', key: null, note: 'y'}]), {asked: null, note: null}) }) diff --git a/src/components/common/capabilityNote.js b/src/components/common/capabilityNote.js index a6ed253..a1b173d 100644 --- a/src/components/common/capabilityNote.js +++ b/src/components/common/capabilityNote.js @@ -23,27 +23,24 @@ export const toCapabilityNoteKey = ({capability, owner, lang, enabled = true}) = enabled && capability && owner ? JSON.stringify([capability, owner, lang]) : null // What the form has asked for (`asked`) and the line kept for it. Asking for -// anything drops the kept line, so a line shows only after a reply to the -// latest ask: never the last owner's, or an earlier one's when its new -// request fails. A reply to anything but the latest ask is dropped. +// anything drops the line, so a line shows only after a reply to the latest +// ask: never the last owner's, or an earlier one's when its new request +// fails. A reply to anything but the latest ask is dropped. export const capabilityNoteReducer = (state, action) => { if(action.type === 'ask') - return {asked: action.key, kept: null} - if(action.type === 'reply' && action.key && action.key === state?.asked) - return {...state, kept: {key: action.key, note: action.note}} + return {asked: action.key, note: null} + if(action.type === 'reply' && action.key && action.key === state.asked) + return {...state, note: action.note} return state } -// The line kept for `key`, never one kept for another owner or language. -export const getKeptCapabilityNote = (state, key) => key && state?.kept?.key === key ? state.kept.note : null - // The line kept for `key`, and `keep(key, note)` for a reply. A new key asks // again during the render that brings it, so not even one render shows a line // kept for another owner, or for this one before it was asked again. export const useKeptCapabilityNote = key => { - const [state, dispatch] = React.useReducer(capabilityNoteReducer, {asked: null, kept: null}) + const [state, dispatch] = React.useReducer(capabilityNoteReducer, {asked: null, note: null}) if(state.asked !== key) dispatch({type: 'ask', key}) const keep = React.useCallback((replyKey, note) => dispatch({type: 'reply', key: replyKey, note}), []) - return [state.asked === key ? getKeptCapabilityNote(state, key) : null, keep] + return [state.asked === key ? state.note : null, keep] } From 4c81aded28c59a410a1446e83e76d958cf5b20b1 Mon Sep 17 00:00:00 2001 From: Jonathan Payne Date: Thu, 19 Nov 2026 07:40:58 -0500 Subject: [PATCH 6/7] OpenConceptLab/ocl_online#700 | Final check: a new owner asks again in an effect, so a queued reply to it is never dropped FC.1: asking during render was a render-phase update, which React leaves out of the state it replays queued updates from; a reply to the new owner could then be dropped and its line never show. The ask goes back to an effect (as in 628e241), and pass 3's F3.1, one render that can still show the same owner's line from just before, is accepted. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AaZ4qTJedFKZzhLXoHiTaG --- .../common/__integration__/capabilityNote.test.js | 5 +++-- src/components/common/capabilityNote.js | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/common/__integration__/capabilityNote.test.js b/src/components/common/__integration__/capabilityNote.test.js index 80ec91b..06d81e1 100644 --- a/src/components/common/__integration__/capabilityNote.test.js +++ b/src/components/common/__integration__/capabilityNote.test.js @@ -1,7 +1,8 @@ /** * The kept line under a form field follows the owner chosen now - * (OpenConceptLab/ocl_online#700): switching away and straight back never - * shows the line kept for the earlier choice, not even for one render. + * (OpenConceptLab/ocl_online#700): switching away and back shows the line + * kept for the earlier choice in no committed render, drops a late reply for + * another owner, and shows the fresh reply. */ import test from 'node:test' import assert from 'node:assert/strict' diff --git a/src/components/common/capabilityNote.js b/src/components/common/capabilityNote.js index a1b173d..37f108c 100644 --- a/src/components/common/capabilityNote.js +++ b/src/components/common/capabilityNote.js @@ -35,12 +35,13 @@ export const capabilityNoteReducer = (state, action) => { } // The line kept for `key`, and `keep(key, note)` for a reply. A new key asks -// again during the render that brings it, so not even one render shows a line -// kept for another owner, or for this one before it was asked again. +// again in an effect, not during render: React can drop a render-phase update +// when it replays queued ones, and then a reply to the new key would be lost. export const useKeptCapabilityNote = key => { const [state, dispatch] = React.useReducer(capabilityNoteReducer, {asked: null, note: null}) - if(state.asked !== key) + React.useEffect(() => { dispatch({type: 'ask', key}) + }, [key]) const keep = React.useCallback((replyKey, note) => dispatch({type: 'reply', key: replyKey, note}), []) return [state.asked === key ? state.note : null, keep] } From c07aa9e7e39a9a104864d4ea2bc99a3d00889269 Mon Sep 17 00:00:00 2001 From: Jonathan Payne Date: Fri, 20 Nov 2026 01:07:21 -0500 Subject: [PATCH 7/7] OpenConceptLab/ocl_online#700 | A new owner asks again in a layout effect, so a quick switch back never shows the earlier line A passive effect's ask can wait behind a quick switch back to the earlier owner: the switch back commits first and shows the line kept for that owner before its fresh reply. An ask from a layout effect is done as the new owner commits. The new test commits two choices before lower-priority work runs, as two quick clicks do, and fails without this change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AaZ4qTBs6TBvnyRdYLAfWG --- .../__integration__/capabilityNote.test.js | 31 +++++++++++++++++++ src/components/common/capabilityNote.js | 5 ++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/components/common/__integration__/capabilityNote.test.js b/src/components/common/__integration__/capabilityNote.test.js index 06d81e1..65ef35d 100644 --- a/src/components/common/__integration__/capabilityNote.test.js +++ b/src/components/common/__integration__/capabilityNote.test.js @@ -7,6 +7,7 @@ import test from 'node:test' import assert from 'node:assert/strict' import React from 'react' +import ReactDOM from 'react-dom' import { render, act, cleanup } from '@testing-library/react' import { toCapabilityNoteKey, useKeptCapabilityNote } from '../capabilityNote.js' @@ -47,3 +48,33 @@ test('switching away and straight back never shows the earlier line', () => { assert.equal(getByTestId('note').textContent, 'Personal line again.') cleanup() }) + +// Two quick choices, as two clicks are: each commits at once, before React gets +// to work it queued at a lower priority, as it does a passive effect's updates. +test('a quick switch away and back commits the earlier line in no render', () => { + const { Note, shown, keep } = renderNotes() + let choose + const Form = () => { + const [noteKey, setNoteKey] = React.useState(PERSONAL) + choose = setNoteKey + return React.createElement(Note, {noteKey}) + } + const { getByTestId } = render(React.createElement(Form)) + keep(PERSONAL, 'Personal line.') + assert.equal(getByTestId('note').textContent, 'Personal line.') + + shown.length = 0 + const committed = [] + act(() => { + for(const noteKey of [ORG, PERSONAL]) { + ReactDOM.flushSync(() => choose(noteKey)) + committed.push(getByTestId('note').textContent) + } + }) + assert.deepEqual(committed, ['', ''], 'no commit after a choice showed the earlier line') + assert.deepEqual(shown.filter(Boolean), [], 'no render after the switch showed a line') + + keep(PERSONAL, 'Personal line again.') + assert.equal(getByTestId('note').textContent, 'Personal line again.') + cleanup() +}) diff --git a/src/components/common/capabilityNote.js b/src/components/common/capabilityNote.js index 37f108c..f33670c 100644 --- a/src/components/common/capabilityNote.js +++ b/src/components/common/capabilityNote.js @@ -37,9 +37,12 @@ export const capabilityNoteReducer = (state, action) => { // The line kept for `key`, and `keep(key, note)` for a reply. A new key asks // again in an effect, not during render: React can drop a render-phase update // when it replays queued ones, and then a reply to the new key would be lost. +// A layout effect, so the ask is done as the new key commits: a passive +// effect's ask can wait behind a quick switch back to the earlier key, which +// would then show the line kept for it before its fresh reply. export const useKeptCapabilityNote = key => { const [state, dispatch] = React.useReducer(capabilityNoteReducer, {asked: null, note: null}) - React.useEffect(() => { + React.useLayoutEffect(() => { dispatch({type: 'ask', key}) }, [key]) const keep = React.useCallback((replyKey, note) => dispatch({type: 'reply', key: replyKey, note}), [])