Skip to content

Commit 7f65491

Browse files
committed
OpenConceptLab/ocl_issues#2205 | Map Project can be configured with external API/token
1 parent fba39c9 commit 7f65491

2 files changed

Lines changed: 68 additions & 11 deletions

File tree

src/components/map-projects/ConfigurationForm.jsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const VisuallyHiddenInput = styled('input')({
3535
});
3636

3737

38-
const ConfigurationForm = ({ project, handleFileUpload, file, owner, setOwner, name, setName, description, setDescription, repo, onRepoChange, repoVersion, setRepoVersion, versions, mappedSources, targetSourcesFromRows, algo, onAlgoSelect, sx, algos, validColumns, columns, isValidColumnValue, updateColumn, configure, setConfigure, columnVisibilityModel, setColumnVisibilityModel, onSave, isSaving }) => {
38+
const ConfigurationForm = ({ project, handleFileUpload, file, owner, setOwner, name, setName, description, setDescription, repo, onRepoChange, repoVersion, setRepoVersion, versions, mappedSources, targetSourcesFromRows, algo, onAlgoSelect, sx, algos, validColumns, columns, isValidColumnValue, updateColumn, configure, setConfigure, columnVisibilityModel, setColumnVisibilityModel, onSave, isSaving, matchAPI, setMatchAPI, matchAPIToken, setMatchAPIToken }) => {
3939
const [algoMenuAnchorEl, setAlgoMenuAnchorEl] = React.useState(null)
4040

4141
const onAlgoButtonClick = event => setAlgoMenuAnchorEl(algoMenuAnchorEl ? null : event.currentTarget)
@@ -125,6 +125,28 @@ const ConfigurationForm = ({ project, handleFileUpload, file, owner, setOwner, n
125125
<RepoSearchAutocomplete label='Repository' size='small' onChange={(id, item) => onRepoChange(item)} value={repo} sx={{marginTop: '12px'}}/>
126126
<RepoVersionSearchAutocomplete versions={versions} label='Version' size='small' onChange={(id, item) => setRepoVersion(item)} value={repoVersion} sx={{marginTop: '12px'}} />
127127

128+
<Typography component="div" sx={{fontSize: '16px', fontWeight: 'bold', marginTop: '20px'}}>
129+
Match API
130+
</Typography>
131+
<FormHelperText sx={{marginTop: 0}}>
132+
Configure External Match API URL and Token
133+
</FormHelperText>
134+
<TextField
135+
fullWidth
136+
sx={{marginTop: '12px'}}
137+
label='Match API URL'
138+
placeholder='e.g. https://api.openconceptlab.org/concepts/$match/?includeSearchMeta=true'
139+
value={matchAPI}
140+
onChange={event => setMatchAPI(event.target.value || '')}
141+
/>
142+
<TextField
143+
fullWidth
144+
sx={{marginTop: '12px'}}
145+
label='Match API Token'
146+
placeholder='e.g. XXXXXXXXXXX'
147+
value={matchAPIToken}
148+
onChange={event => setMatchAPIToken(event.target.value || '')}
149+
/>
128150
<Typography component="div" sx={{fontSize: '16px', fontWeight: 'bold', marginTop: '20px'}}>
129151
Matching Algorithm
130152
</Typography>

src/components/map-projects/MapProject.jsx

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ const MapProject = () => {
143143
const [searchStr, setSearchStr] = React.useState('') // concept search
144144
const [candidatesOrder, setCandidatesOrder] = React.useState('desc')
145145
const [candidatesOrderBy, setCandidatesOrderBy] = React.useState('search_meta.search_score')
146+
const [matchAPI, setMatchAPI] = React.useState('')
147+
const [matchAPIToken, setMatchAPIToken] = React.useState('')
146148

147149
const abortRef = React.useRef(false);
148150

@@ -260,6 +262,8 @@ const MapProject = () => {
260262
setDescription(response.data?.description || '')
261263
setOwner(response.data?.owner_url)
262264
setRetired(Boolean(response.data?.include_retired))
265+
setMatchAPI(response.data?.match_api_url)
266+
setMatchAPIToken(response.data?.match_api_token)
263267
setProject(response.data)
264268
setConfigure(false)
265269
})
@@ -527,6 +531,10 @@ const MapProject = () => {
527531
formData.append('target_repo_url', repoVersion.version_url)
528532
formData.append('matching_algorithm', algo)
529533
formData.append('include_retired', retired)
534+
if(matchAPI) {
535+
formData.append('match_api_url', matchAPI)
536+
formData.append('match_api_token', matchAPIToken)
537+
}
530538
let service = APIService.new().overrideURL(owner).appendToUrl('map-projects/')
531539
if(project?.id)
532540
service = service.appendToUrl(project.id + '/').put(formData, null, {"Content-Type": "multipart/form-data"})
@@ -583,6 +591,17 @@ const MapProject = () => {
583591
}
584592
}
585593

594+
const getMatchAPIService = () => {
595+
let service;
596+
if(matchAPI) {
597+
service = APIService.new()
598+
service.URL = matchAPI
599+
} else {
600+
service = APIService.concepts().appendToUrl('$match/')
601+
}
602+
return service
603+
}
604+
586605

587606
const getRowsResults = async (rows) => {
588607
abortRef.current = false;
@@ -602,13 +621,17 @@ const MapProject = () => {
602621
const payload = getPayloadForMatching(rowBatch, _repo)
603622

604623
try {
605-
const response = await APIService.concepts()
606-
.appendToUrl('$match/')
607-
.post(payload, null, null, {
608-
includeSearchMeta: true,
609-
semantic: algo === 'llm',
610-
bestMatch: true
611-
});
624+
const service = getMatchAPIService()
625+
const response = await service.post(
626+
payload,
627+
(matchAPI && matchAPIToken) ? matchAPIToken : null,
628+
null,
629+
{
630+
includeSearchMeta: true,
631+
semantic: algo === 'llm',
632+
bestMatch: true
633+
}
634+
);
612635

613636
return response.data || [];
614637
} catch {
@@ -1047,9 +1070,12 @@ const MapProject = () => {
10471070
let __row = isEmpty(_row) ? row : _row
10481071
setIsLoadingInDecisionView(true)
10491072
const payload = getPayloadForMatching([__row], repo)
1050-
APIService.concepts()
1051-
.appendToUrl('$match/')
1052-
.post(payload, null, null, {
1073+
const service = getMatchAPIService()
1074+
service.post(
1075+
payload,
1076+
(matchAPI && matchAPIToken) ? matchAPIToken : null,
1077+
null,
1078+
{
10531079
includeSearchMeta: true,
10541080
includeMappings: true,
10551081
includeRetired: isBoolean(_retired) ? _retired : retired,
@@ -1232,6 +1258,10 @@ const MapProject = () => {
12321258
setColumnVisibilityModel={setColumnVisibilityModel}
12331259
onSave={onSave}
12341260
isSaving={isSaving}
1261+
matchAPI={matchAPI}
1262+
setMatchAPI={setMatchAPI}
1263+
matchAPIToken={matchAPIToken}
1264+
setMatchAPIToken={setMatchAPIToken}
12351265
/>
12361266
</div>
12371267
}
@@ -1562,6 +1592,11 @@ const MapProject = () => {
15621592
setColumnVisibilityModel={setColumnVisibilityModel}
15631593
onSave={onSave}
15641594
isSaving={isSaving}
1595+
matchAPI={matchAPI}
1596+
setMatchAPI={setMatchAPI}
1597+
matchAPIToken={matchAPIToken}
1598+
setMatchAPIToken={setMatchAPIToken}
1599+
15651600
/>
15661601
</div> :
15671602
(

0 commit comments

Comments
 (0)