Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/repos/CollectionVersionsTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import VersionExportDialog from './VersionExportDialog';
import VersionStatusIndicator from './VersionStatusIndicator';
import GAService from '../../services/GAService';
import { PROCESSING_POLL_INTERVAL_MS, useProcessingVersions } from '../../hooks/useProcessingState';
import useQueuedTasks from '../../hooks/useQueuedTasks';
import { PROCESSING_QUERY_PARAMS, areSeedStagesComplete, isExportAvailable, isProcessing as isExpansionProcessing, isVersionProcessing } from './processingStages';
import {
REPO_VERSIONS_PAGE_SIZE,
Expand Down Expand Up @@ -186,7 +187,7 @@ const CollectionVersionsTab = ({
const [rebuildExpansion, setRebuildExpansion] = React.useState(null);
const [reindexTarget, setReindexTarget] = React.useState(null);
const [clearProcessingVersion, setClearProcessingVersion] = React.useState(null);
const [reindexWip, setReindexWip] = React.useState({});
const { tasks: reindexWip, add: addReindexWip, check: checkReindexWip } = useQueuedTasks();
const [expandedVersionKeys, setExpandedVersionKeys] = React.useState(new Set());
const [rowMenu, setRowMenu] = React.useState({ anchorEl: null, version: null });
const [expansionMenu, setExpansionMenu] = React.useState({ anchorEl: null, version: null, expansion: null });
Expand Down Expand Up @@ -559,7 +560,7 @@ const CollectionVersionsTab = ({
setReindexTarget(null);
if (!target || !result) return;
if (result.taskId || result.status === 409)
setReindexWip(prev => ({ ...prev, [getReindexKey(target.targetUrl, target.contentType)]: { taskId: result.taskId } }));
addReindexWip(getReindexKey(target.targetUrl, target.contentType), result.taskId);
};

const toggleVersionExpand = version => {
Expand All @@ -574,7 +575,10 @@ const CollectionVersionsTab = ({

const openRowMenu = (event, version) => setRowMenu({ anchorEl: event.currentTarget, version });
const closeRowMenu = () => setRowMenu({ anchorEl: null, version: null });
const openExpansionMenu = (event, version, expansion) => setExpansionMenu({ anchorEl: event.currentTarget, version, expansion });
const openExpansionMenu = (event, version, expansion) => {
setExpansionMenu({ anchorEl: event.currentTarget, version, expansion });
checkReindexWip(['concepts', 'mappings'].map(contentType => getReindexKey(expansion.url, contentType)));
};
const closeExpansionMenu = () => setExpansionMenu({ anchorEl: null, version: null, expansion: null });

const buildRowMenuItems = version => {
Expand Down
15 changes: 10 additions & 5 deletions src/components/repos/ReindexVersionDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import { formatError } from './versionsTab.styles';

// `targetUrl` is the base resource URL to POST `${contentType}/${indexPath}/` onto —
// a source/collection version URL (indexPath 'indexes'), or a collection expansion
// URL (indexPath 'index').
const ReindexVersionDialog = ({ open, targetUrl, repoId, contentType, indexPath = 'indexes', label, onClose }) => {
// URL (indexPath 'index'). With `syncVectors`, a source version's concepts get only their
// vectors synced, without changing whether OCL Semantic Search is on (ocl_online#46).
const ReindexVersionDialog = ({ open, targetUrl, repoId, contentType, indexPath = 'indexes', label, syncVectors, onClose }) => {
const { t } = useTranslation();
const [submitting, setSubmitting] = React.useState(false);
const [result, setResult] = React.useState(null);
Expand All @@ -37,15 +38,15 @@ const ReindexVersionDialog = ({ open, targetUrl, repoId, contentType, indexPath
};

const handleSubmit = () => {
GAService.recordActionEvent('Version Index', `reindex_${contentType}`, repoId, {
GAService.recordActionEvent('Version Index', syncVectors ? 'sync_vectors' : `reindex_${contentType}`, repoId, {
target: targetUrl,
content_type: contentType
});
setSubmitting(true);
APIService.new()
.overrideURL(targetUrl)
.appendToUrl(`${contentType}/${indexPath}/`)
.post(null, null, null, null, true)
.post(syncVectors ? { sync_vectors: true } : null, null, null, null, true)
.then(response => {
const status = response?.status || response?.response?.status;
const data = response?.data || response?.response?.data;
Expand All @@ -65,7 +66,11 @@ const ReindexVersionDialog = ({ open, targetUrl, repoId, contentType, indexPath
<DialogContent sx={{ padding: '16px 0 0 0 !important', minWidth: 360 }}>
{!result && (
<>
<p style={{ fontSize: '1rem' }}>{t('repo.reindex_confirm_message', { contentType: contentTypeLabel, repoId })}</p>
<p style={{ fontSize: '1rem' }}>
{syncVectors
? t('repo.version.semantic_search.sync_vectors_message', { repoId })
: t('repo.reindex_confirm_message', { contentType: contentTypeLabel, repoId })}
</p>
{submitting ? (
<Box sx={{ display: 'flex', justifyContent: 'center', mt: 3 }}>
<CircularProgress size={28} />
Expand Down
86 changes: 86 additions & 0 deletions src/components/repos/SemanticSearchDialog.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import Alert from '@mui/material/Alert';
import Box from '@mui/material/Box';
import CircularProgress from '@mui/material/CircularProgress';
import DialogContent from '@mui/material/DialogContent';
import isNumber from 'lodash/isNumber';

import APIService from '../../services/APIService';
import GAService from '../../services/GAService';
import Button from '../common/Button';
import Dialog from '../common/Dialog';
import DialogTitle from '../common/DialogTitle';
import { isSemanticVersion, withSemanticSearch } from './semanticSearch';
import { formatError, getVersionURL } from './versionsTab.styles';

// Turns OCL Semantic Search on or off for a source version (staff only, in the API too). The API queues the vector
// sync when the version's match algorithms change. onClose(true) once they have.
const SemanticSearchDialog = ({ version, repoId, onClose }) => {
const { t } = useTranslation();
const [submitting, setSubmitting] = React.useState(false);
const [result, setResult] = React.useState(null);
const turningOn = !isSemanticVersion(version);
const label = t(turningOn ? 'repo.version.semantic_search.turn_on' : 'repo.version.semantic_search.turn_off');
const conceptCount = version?.summary?.active_concepts;

const handleClose = () => {
if(submitting) return;
onClose(Boolean(result?.ok));
};

const handleSubmit = () => {
const url = getVersionURL(version);
GAService.recordActionEvent('Version Semantic Search', turningOn ? 'turn_on' : 'turn_off', repoId, { version: url });
setSubmitting(true);
APIService.new()
.overrideURL(url)
.put({ match_algorithms: withSemanticSearch(version?.match_algorithms, turningOn) }, null, null, null, true)
.then(response => {
const status = response?.status || response?.response?.status;
const data = response?.data || response?.response?.data;
setSubmitting(false);
if(status === 200)
setResult({ ok: true });
else
setResult({ ok: false, error: formatError(data, t('common.generic_error')) });
});
};

return (
<Dialog open onClose={handleClose}>
<DialogTitle>{t('repo.reindex_dialog_title', { label, repoId })}</DialogTitle>
<DialogContent sx={{ padding: '16px 0 0 0 !important', minWidth: 360 }}>
{!result && (
<>
<p style={{ fontSize: '1rem' }}>
{t(turningOn ? 'repo.version.semantic_search.turn_on_message' : 'repo.version.semantic_search.turn_off_message', { repoId })}
</p>
{isNumber(conceptCount) && (
<p style={{ fontSize: '1rem' }}>{t('repo.version.semantic_search.concept_count', { count: conceptCount.toLocaleString() })}</p>
)}
{submitting ? (
<Box sx={{ display: 'flex', justifyContent: 'center', mt: 3 }}>
<CircularProgress size={28} />
</Box>
) : (
<Button sx={{ marginTop: '24px' }} color="primary" label={label} onClick={handleSubmit} />
)}
</>
)}
{result && (
<>
{result.ok ? (
<Alert severity="success">
{t(turningOn ? 'repo.version.semantic_search.turned_on' : 'repo.version.semantic_search.turned_off', { repoId })}
</Alert>
) : <Alert severity="error">{result.error}</Alert>}
<Button sx={{ marginTop: '24px' }} label={t('common.close')} onClick={handleClose} />
</>
)}
</DialogContent>
</Dialog>
);
};

export default SemanticSearchDialog;
57 changes: 45 additions & 12 deletions src/components/repos/SourceVersionsTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ import {
Newspaper as ChangelogIcon,
OpenInNew as OpenInNewIcon,
LayersClear as ClearProcessingIcon,
ManageSearch as SemanticSearchIcon,
QueryStats as ReindexIcon,
Summarize as SummaryIcon,
Sync as SyncVectorsIcon,
Visibility as VisibilityIcon
} from '@mui/icons-material';
import get from 'lodash/get';
Expand All @@ -69,10 +71,13 @@ import ProcessingFlag from './ProcessingFlag';
import RepoContentSummary, { VERSION_STATS } from './RepoContentSummary';
import ProcessingProgress from './ProcessingProgress';
import ReindexVersionDialog from './ReindexVersionDialog';
import SemanticSearchDialog from './SemanticSearchDialog';
import { isSemanticVersion } from './semanticSearch';
import VersionExportDialog from './VersionExportDialog';
import VersionStatusIndicator from './VersionStatusIndicator';
import GAService from '../../services/GAService';
import { useProcessingVersions } from '../../hooks/useProcessingState';
import useQueuedTasks from '../../hooks/useQueuedTasks';
import { PROCESSING_QUERY_PARAMS, areSeedStagesComplete, isChangelogAvailable, isExportAvailable, isVersionProcessing } from './processingStages';
import {
REPO_VERSIONS_PAGE_SIZE,
Expand Down Expand Up @@ -173,8 +178,9 @@ const SourceVersionsTab = ({
const [attributesVersion, setAttributesVersion] = React.useState(null);
const [changelogVersion, setChangelogVersion] = React.useState(null);
const [reindexTarget, setReindexTarget] = React.useState(null);
const [semanticSearchVersion, setSemanticSearchVersion] = React.useState(null);
const [clearProcessingVersion, setClearProcessingVersion] = React.useState(null);
const [reindexWip, setReindexWip] = React.useState({});
const { tasks: reindexWip, add: addReindexWip, check: checkReindexWip } = useQueuedTasks();
const [headVersion, setHeadVersion] = React.useState(isHeadVersion(repo) ? repo : null);
const [versions, setVersions] = React.useState([]);
const [totalCount, setTotalCount] = React.useState(0);
Expand Down Expand Up @@ -279,13 +285,21 @@ const SourceVersionsTab = ({
const onExternalExportsChange = updatedVersion => {
if(onDataChange) onDataChange(updatedVersion);
};
const getReindexKey = (version, contentType) => `${getVersionKey(version)}:${contentType}`;
const getReindexKey = (version, key) => `${getVersionKey(version)}:${key}`;
const closeReindexDialog = result => {
const target = reindexTarget;
setReindexTarget(null);
if(!target || !result) return;
if(result.taskId || result.status === 409)
setReindexWip(prev => ({ ...prev, [getReindexKey(target.version, target.contentType)]: { taskId: result.taskId } }));
addReindexWip(getReindexKey(target.version, target.key), result.taskId);
};
const openMenu = (event, version) => {
setMenuState({ anchorEl: event.currentTarget, version });
checkReindexWip(['concepts', 'mappings', 'vectors'].map(key => getReindexKey(version, key)));
};
const closeSemanticSearchDialog = changed => {
setSemanticSearchVersion(null);
if(changed && onDataChange) onDataChange();
};
const menuVersion = menuState.version
? sortedVersions.find(version => getVersionKey(version) === getVersionKey(menuState.version)) || menuState.version
Expand Down Expand Up @@ -409,7 +423,7 @@ const SourceVersionsTab = ({
</TableCell>
<TableCell align="right" sx={bodyCellSx}>
<Tooltip title={t('common.actions')}>
<IconButton size="small" onClick={event => setMenuState({ anchorEl: event.currentTarget, version })}>
<IconButton size="small" onClick={event => openMenu(event, version)}>
<MoreVertIcon fontSize="small" />
</IconButton>
</Tooltip>
Expand Down Expand Up @@ -471,26 +485,37 @@ const SourceVersionsTab = ({
{hasAccess && <GatedMenuItem onClick={() => withClose(onReleaseVersion)} disabled={isHeadVersion(menuState.version) || menuVersionProcessing} reason={processingReason}><ReleaseIcon fontSize="small" sx={{ mr: 1 }} />{menuState.version?.released ? t('repo.unrelease_version') : t('repo.release_version')}</GatedMenuItem>}
{hasAccess && <GatedMenuItem onClick={() => withClose(computeSummary)} disabled={menuVersionProcessing} reason={processingReason}><SummaryIcon fontSize="small" sx={{ mr: 1 }} />{t('repo.recompute_summary')}</GatedMenuItem>}
{hasAccess && isStaffUser() && [
{ contentType: 'concepts', label: t('repo.reindex_concepts') },
{ contentType: 'mappings', label: t('repo.reindex_mappings') }
].map(({ contentType, label }) => {
const wip = menuState.version ? reindexWip[getReindexKey(menuState.version, contentType)] : null;
{ key: 'concepts', contentType: 'concepts', label: t('repo.reindex_concepts') },
{ key: 'mappings', contentType: 'mappings', label: t('repo.reindex_mappings') },
...(isSemanticVersion(menuVersion) ? [
{ key: 'vectors', contentType: 'concepts', syncVectors: true, label: t('repo.version.semantic_search.sync_vectors') }
] : [])
].map(({ key, contentType, syncVectors, label }) => {
const wip = menuState.version ? reindexWip[getReindexKey(menuState.version, key)] : null;
const tooltip = wip
? (wip.taskId ? t('repo.reindex_in_progress_tooltip_with_id', { id: wip.taskId }) : t('repo.reindex_in_progress_tooltip'))
: (menuVersionProcessing ? processingReason : '');
const Icon = syncVectors ? SyncVectorsIcon : ReindexIcon;
return (
<Tooltip key={contentType} title={tooltip} placement="left">
<Tooltip key={key} title={tooltip} placement="left">
<span style={{ display: 'block' }}>
<MenuItem
disabled={Boolean(wip) || menuVersionProcessing}
onClick={() => withClose(version => setReindexTarget({ version, contentType }))}
onClick={() => withClose(version => setReindexTarget({ version, key, contentType, syncVectors, label }))}
>
<ReindexIcon fontSize="small" sx={{ mr: 1 }} />{label}
<Icon fontSize="small" sx={{ mr: 1 }} />{label}
</MenuItem>
</span>
</Tooltip>
);
})}
{
hasAccess && isStaffUser() && !isHeadVersion(menuState.version) &&
<GatedMenuItem onClick={() => withClose(() => setSemanticSearchVersion(menuVersion))} disabled={menuVersionProcessing} reason={processingReason}>
<SemanticSearchIcon fontSize="small" sx={{ mr: 1 }} />
{t(isSemanticVersion(menuVersion) ? 'repo.version.semantic_search.turn_off' : 'repo.version.semantic_search.turn_on')}
</GatedMenuItem>
}
{
isStaffUser() && menuVersionProcessing && [
<Divider key="clear-processing-divider" sx={{margin: '8px 0'}} />,
Expand Down Expand Up @@ -540,10 +565,18 @@ const SourceVersionsTab = ({
targetUrl={getVersionURL(reindexTarget.version)}
repoId={`${reindexTarget.version.short_code || reindexTarget.version.id} [${getVersionLabel(reindexTarget.version)}]`}
contentType={reindexTarget.contentType}
label={reindexTarget.contentType === 'mappings' ? t('repo.reindex_mappings') : t('repo.reindex_concepts')}
label={reindexTarget.label}
syncVectors={reindexTarget.syncVectors}
onClose={closeReindexDialog}
/>
)}
{Boolean(semanticSearchVersion) && (
<SemanticSearchDialog
version={semanticSearchVersion}
repoId={`${semanticSearchVersion.short_code || semanticSearchVersion.id} [${getVersionLabel(semanticSearchVersion)}]`}
onClose={closeSemanticSearchDialog}
/>
)}
</Box>
);
};
Expand Down
19 changes: 19 additions & 0 deletions src/components/repos/VersionForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import CloseIconButton from '../common/CloseIconButton';
import Dialog from '../common/Dialog'
import DialogTitle from '../common/DialogTitle'
import { ID_REGEX } from '../../common/constants'
import { isStaffUser } from '../../common/utils'
import {
shouldAskForExpansion, shouldShowAutoexpand, getExpansionChoices, getDefaultExpansion, getExpansionPayload
} from './versionExpansion'
import { isSemanticVersion, withSemanticSearch } from './semanticSearch'


class VersionForm extends FormComponent {
Expand All @@ -39,6 +41,7 @@ class VersionForm extends FormComponent {
autoexpand: {...fieldStruct, value: true},
expansion_url: {...fieldStruct},
revision_date: {...fieldStruct},
semantic: {...fieldStruct, value: isSemanticVersion(props.version)},
},
expansionDialog: false,
expansion: null,
Expand Down Expand Up @@ -66,6 +69,9 @@ class VersionForm extends FormComponent {

isCollectionVersion = () => (this.props.resource || this.props.resourceType) === 'collection'

// A new source version's OCL Semantic Search, which staff choose and which starts as HEAD's (`version` is HEAD here).
canChooseSemanticSearch = () => !this.props.edit && !this.isCollectionVersion() && isStaffUser()

getExpansionArgs = () => ({
edit: Boolean(this.props.edit),
isCollection: this.isCollectionVersion(),
Expand Down Expand Up @@ -111,6 +117,10 @@ class VersionForm extends FormComponent {
delete payload.expansion_url
}

delete payload.semantic
if(this.canChooseSemanticSearch())
payload.match_algorithms = withSemanticSearch(version.match_algorithms, Boolean(this.state.fields.semantic.value))

const url = edit ? version.version_url : version.url
GAService.recordUpsertEvent(isCollectionVersion ? 'Collection Version' : 'Source Version', edit)
let service = APIService.new().overrideURL(url)
Expand Down Expand Up @@ -233,6 +243,15 @@ class VersionForm extends FormComponent {
label={t('common.release')}
/>
</div>
{
this.canChooseSemanticSearch() &&
<div className='col-xs-12' style={{width: '100%', marginTop: '15px'}}>
<FormControlLabel
control={<Checkbox checked={Boolean(fields.semantic.value)} onChange={this.onCheckboxChange} name="semantic" />}
label={t('repo.version.form.semantic_search')}
/>
</div>
}
{
resource === 'collection' && shouldShowAutoexpand(this.getExpansionArgs()) &&
<div className='col-xs-12' style={{width: '100%', marginTop: '15px'}}>
Expand Down
Loading
Loading