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
40 changes: 29 additions & 11 deletions src/components/repos/CollectionVersionsTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import ExpansionDetailsDialog from './ExpansionDetailsDialog';
import ExpansionRowList from './ExpansionRowList';
import ExpansionRowListWithoutMarks from './ExpansionRowListWithoutMarks';
import ExpansionHealthChip from './ExpansionHealthChip';
import { findDefaultExpansion, getDefaultExpansionLabel } from './defaultExpansion';
import { findDefaultExpansion, getDefaultExpansionLabel, getReleaseWait } from './defaultExpansion';
import { getHealthChips, getVersionHealthStatus, isCheckingHealth, pollHealth } from './expansionHealth';
import { getVersionWarning, showsExpansionMarks } from './expansionMarks';
import ExternalExportsDialog from './ExternalExportsDialog';
Expand All @@ -90,7 +90,7 @@ 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 { PROCESSING_QUERY_PARAMS, areSeedStagesComplete, isExportAvailable, isProcessing as isExpansionProcessing, isVersionProcessing, parseProcessingValue } from './processingStages';
import {
REPO_VERSIONS_PAGE_SIZE,
bodyCellSx,
Expand Down Expand Up @@ -156,12 +156,6 @@ const formatExpansions = (version, versionExpansions = []) => {
return expansions;
};

const parseProcessingValue = value => {
if (typeof value === 'boolean') return value;
if (typeof value === 'string') return value.toLowerCase() === 'true';
return Boolean(value);
};

const CollectionVersionsTab = ({
repo,
loading,
Expand Down Expand Up @@ -481,6 +475,13 @@ const CollectionVersionsTab = ({
Object.keys(processedCleanupRef.current).forEach(clearProcessedCleanup);
}, [clearProcessedCleanup, clearProcessingPoll]);

// false once the tab is gone, so an answer that comes back later starts no poll
const mountedRef = React.useRef(true);
React.useEffect(() => {
mountedRef.current = true;
return () => { mountedRef.current = false; };
}, []);

const refreshSelectedExpansions = React.useCallback(version => {
if (version) fetchExpansions(version, true);
}, [fetchExpansions]);
Expand Down Expand Up @@ -675,7 +676,20 @@ const CollectionVersionsTab = ({
});
};

const openRowMenu = (event, version) => setRowMenu({ anchorEl: event.currentTarget, version });
// a rebuild can start elsewhere after the expansions were read (or before they're in), so whether the default the
// version names is being built is asked again when the menu opens; when it is, Release waits at once, its processing
// is polled from there, and the version's expansions are read again
const openRowMenu = (event, version) => {
setRowMenu({ anchorEl: event.currentTarget, version });
const url = version?.expansion_url;
if (!url || processingStatusRef.current[url]?.state === 'processing') return;
APIService.new().overrideURL(url + 'processing/').get(null, null, null, true).then(response => {
if (!mountedRef.current || response?.status !== 200 || !parseProcessingValue(response.data)) return;
markExpansionProcessing(url);
ensureProcessingPoll(version, { url });
fetchExpansions(version, true, true);
});
};
const closeRowMenu = () => setRowMenu({ anchorEl: null, version: null });
const openExpansionMenu = (event, version, expansion) => {
setExpansionMenu({ anchorEl: event.currentTarget, version, expansion });
Expand All @@ -691,6 +705,10 @@ const CollectionVersionsTab = ({
const canDeleteVersion = !isHead && !released && versionExpansions.length === 0;
const processing = isVersionProcessing(version);
const processingReason = t('repo.action_disabled_while_processing');
// by the URL the version names, so a status read before its expansions are in counts
const defaultExpansion = findDefaultExpansion(version, versionExpansions) || { url: version.expansion_url };
// HEAD is never released, so it waits for nothing
const releaseWait = isHead ? null : getReleaseWait(t, version, Boolean(version.expansion_url) && getExpansionProcessingState(defaultExpansion) === 'processing');
const exportPending = processing && !isExportAvailable(version);
// Compare reads the version's content, which isn't there until seeding ends.
const seedPending = processing && !areSeedStagesComplete(version);
Expand All @@ -711,7 +729,7 @@ const CollectionVersionsTab = ({
items.push(
{ divider: true },
{ key: 'edit', label: t('common.edit'), icon: <EditIcon />, disabled: !isHead && processing, tooltip: (!isHead && processing) ? processingReason : undefined, lock: lockFor(isHead ? 'editRepo' : 'editVersion'), onClick: () => editVersion(version) },
{ key: 'release', label: released ? t('repo.unrelease_version') : t('repo.release_version'), icon: <ReleaseIcon />, disabled: isHead || processing, tooltip: processing ? processingReason : undefined, lock: isHead ? null : lockFor('releaseVersion'), onClick: () => onReleaseVersion?.(version) },
{ key: 'release', label: released ? t('repo.unrelease_version') : t('repo.release_version'), icon: <ReleaseIcon />, disabled: isHead || processing || Boolean(releaseWait), tooltip: releaseWait || (processing ? processingReason : undefined), lock: isHead ? null : lockFor('releaseVersion'), onClick: () => onReleaseVersion?.(version) },
{ key: 'recompute-summary', label: t('repo.recompute_summary'), icon: <SummaryIcon />, disabled: processing, tooltip: processing ? processingReason : undefined, onClick: () => computeSummary(version) }
);
}
Expand Down Expand Up @@ -1041,7 +1059,7 @@ const CollectionVersionsTab = ({
anchorEl={rowMenu.anchorEl}
open={Boolean(rowMenu.anchorEl)}
onClose={closeRowMenu}
items={rowMenu.version ? buildRowMenuItems(rowMenu.version) : []}
items={rowMenu.version ? buildRowMenuItems(find(displayVersions, item => getVersionKey(item) === getVersionKey(rowMenu.version)) || rowMenu.version) : []}
/>

<RepoVersionRowMenu
Expand Down
19 changes: 12 additions & 7 deletions src/components/repos/ReleaseVersion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import DialogContent from '@mui/material/DialogContent'
import Button from '../common/Button';
import Dialog from '../common/Dialog'
import DialogTitle from '../common/DialogTitle'
import { LockTooltip } from '../common/NoticeLocks'

const ReleaseVersion = ({ onSubmit, onClose, open, repo }) => {
// releaseWait: why releasing waits on the version (getReleaseWait), or null
const ReleaseVersion = ({ onSubmit, onClose, open, repo, releaseWait }) => {
const { t } = useTranslation()
const repoType = repo.type
const repoId = `${repo.short_code} [${repo.version}]`
Expand All @@ -30,12 +32,15 @@ const ReleaseVersion = ({ onSubmit, onClose, open, repo }) => {
}}
/>
</p>
<Button
sx={{marginTop: '24px'}}
color='primary'
label={t('common.submit')}
onClick={onSubmit}
/>
<LockTooltip title={releaseWait} placement='top-start' display='inline-block'>
<Button
sx={{marginTop: '24px'}}
color='primary'
label={t('common.submit')}
onClick={onSubmit}
disabled={Boolean(releaseWait)}
/>
</LockTooltip>
</DialogContent>
</Dialog>
)
Expand Down
5 changes: 3 additions & 2 deletions src/components/repos/RepoHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import { createSimilarRepoHref } from './utils';
import FollowActionButton from '../common/FollowActionButton'
import { OperationsContext } from '../app/LayoutContext';

const RepoHeader = ({repo, owner, versions, versionsLoading, previewVersions, hasMoreVersions, onLoadMoreVersions, onVersionChange, repoHref, onCreateConceptClick, onCreateMappingClick, onVersionEditClick, onCreateVersionClick, onDeleteRepoClick, isVersion, onReleaseVersionClick, hideActions, squareTop}) => {
const RepoHeader = ({repo, owner, versions, versionsLoading, previewVersions, hasMoreVersions, onLoadMoreVersions, onVersionChange, repoHref, onCreateConceptClick, onCreateMappingClick, onVersionEditClick, onCreateVersionClick, onDeleteRepoClick, isVersion, onReleaseVersionClick, releaseWait, onActionsOpen, hideActions, squareTop}) => {
const { t } = useTranslation()
const { setAlert } = React.useContext(OperationsContext)
const [menu, setMenu] = React.useState(false)
const [menuAnchorEl, setMenuAnchorEl] = React.useState(false)
const onMenuOpen = event => {
setMenuAnchorEl(event.currentTarget)
setMenu(true)
onActionsOpen?.()
}
const onMenuClose = () => {
setMenuAnchorEl(false)
Expand Down Expand Up @@ -87,7 +88,7 @@ const RepoHeader = ({repo, owner, versions, versionsLoading, previewVersions, ha
<Button endIcon={<DownIcon fontSize='inherit' />} variant='text' sx={{textTransform: 'none', color: 'surface.contrastText'}} onClick={onMenuOpen} id='repo-actions'>
{t('common.actions')}
</Button>
<RepoManagementList isVersion={isVersion} hasAccess={hasAccess} createSimilarHref={createSimilarHref} anchorEl={menuAnchorEl} open={menu} onClose={onMenuClose} id='repo-actions' onClick={onManageOptionClick} repo={repo} pin={(canPin && pins !== false) ? {owner: pinOwner.id, pinned} : false} />
<RepoManagementList isVersion={isVersion} hasAccess={hasAccess} createSimilarHref={createSimilarHref} anchorEl={menuAnchorEl} open={menu} onClose={onMenuClose} id='repo-actions' onClick={onManageOptionClick} repo={repo} pin={(canPin && pins !== false) ? {owner: pinOwner.id, pinned} : false} releaseWait={releaseWait} />
</React.Fragment>
}
</span>
Expand Down
25 changes: 23 additions & 2 deletions src/components/repos/RepoHome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import APIService from '../../services/APIService';
import GAService from '../../services/GAService';
import ProcessingBanner from './ProcessingBanner';
import { useProcessingVersions } from '../../hooks/useProcessingState';
import useDefaultExpansionProcessing from '../../hooks/useDefaultExpansionProcessing';
import { PROCESSING_QUERY_PARAMS, isVersionProcessing } from './processingStages';
import { dropVersion, toOwnerURI, currentUserHasAccess } from '../../common/utils';
import { getStoredId } from '../../common/uri';
Expand Down Expand Up @@ -44,6 +45,7 @@ import { isPanelReady } from './panelReady';
import ReferenceHome from '../references/ReferenceHome'
import AddReferencesDialog from '../collections/AddReferencesDialog'
import ExpansionDropDown from './ExpansionDropDown';
import { getReleaseWait } from './defaultExpansion';
import LimitNotice, { refreshNotices, showRefusalNotice } from '../common/LimitNotice';
import { NoticeLocksProvider, LockTooltip, useNoticeLocks } from '../common/NoticeLocks';
import { refreshNoticesWhenTaskEnds, useResourceNotices } from '../common/useNotices';
Expand Down Expand Up @@ -572,7 +574,8 @@ const RepoHome = () => {
else if(response?.status === 202 || response?.detail === 'Already Queued' || response?.__all__ === 'Already Queued') {
setAlert({severity: 'warning', message: t('errors.already_queued')})
} else if(!showRefusalNotice(response)) {
setAlert({severity: 'error', message: response?.data?.detail || t('common.generic_error')})
// a refusal's body is the response here (not raw), as when a release waits for its expansion's build
setAlert({severity: 'error', message: response?.detail || response?.data?.detail || t('common.generic_error')})
}
})
}
Expand All @@ -595,6 +598,21 @@ const RepoHome = () => {
const processingTargets = React.useMemo(() => (repo?.url || repo?.version_url) ? [repo] : [], [repo])
const { versions: [liveRepo] = [] } = useProcessingVersions(processingTargets)
const currentRepo = liveRepo || repo
// Release waits for the version's default expansion to be built (getReleaseWait): on the page's menu, and in the
// edit form, for the version it edits, which a Versions row may open for another version
const canRelease = isCollection && isVersion && currentUserHasAccess()
const { processing: defaultProcessing, refresh: refreshDefaultProcessing } = useDefaultExpansionProcessing(canRelease ? currentRepo : null)
const releaseWait = canRelease ? getReleaseWait(t, currentRepo, defaultProcessing) : null
// the versions an open edit form and release confirmation act on (a Versions row may open either for another
// version, and both can be open), each read when it opens
const toLiveVersion = target => (isCollection && target) ?
(target.version_url === currentRepo?.version_url ? currentRepo : target) : null
const formVersion = toLiveVersion(versionForm?.edit ? versionForm.version : null)
const { processing: formDefaultProcessing } = useDefaultExpansionProcessing(formVersion)
const formReleaseWait = formVersion ? getReleaseWait(t, formVersion, formDefaultProcessing) : null
const confirmVersion = toLiveVersion(releaseTarget || null)
const { processing: confirmDefaultProcessing } = useDefaultExpansionProcessing(confirmVersion)
const confirmReleaseWait = confirmVersion ? getReleaseWait(t, confirmVersion, confirmDefaultProcessing) : null
// The repository's notices (OpenConceptLab/ocl_online#702), HEAD's and, on a version's page, that version's: a strip
// at the top of the panel for the version shown while a state lasts, and locks on the edit actions they name
// (NoticeLocks). The panel's contents are sized from --app-height, so inside it that is the page's height less the
Expand Down Expand Up @@ -662,6 +680,8 @@ const RepoHome = () => {
onDeleteRepoClick={() => setDeleteTarget(repo)}
onVersionEditClick={() => onVersionEditClick()}
onReleaseVersionClick={() => onReleaseVersionClick()}
releaseWait={releaseWait}
onActionsOpen={refreshDefaultProcessing}
/>
<div className='padding-0 col-xs-12' style={{width: isSplitView ? '100%' : (showSummary ? 'calc(100% - 272px)' : 'calc(100% - 12px)')}}>
<CommonTabs TABS={tabs} value={tab} onChange={onTabChange} />
Expand Down Expand Up @@ -816,6 +836,7 @@ const RepoHome = () => {
resourceType={isCollection ? 'collection' : 'source'}
version={versionForm?.version || repo}
expansions={versionForm?.expansions || []}
releaseWait={formReleaseWait}
onClose={(postUpsert) => onVersionFormClose(postUpsert)}
/>
}
Expand Down Expand Up @@ -844,7 +865,7 @@ const RepoHome = () => {
}
{
Boolean(releaseTarget) &&
<ReleaseVersion open={releaseTarget} onClose={() => setReleaseTarget(false)} repo={getTargetVersion(releaseTarget)} onSubmit={onReleaseVersion} />
<ReleaseVersion open={releaseTarget} onClose={() => setReleaseTarget(false)} repo={getTargetVersion(releaseTarget)} onSubmit={onReleaseVersion} releaseWait={confirmReleaseWait} />
}
</div>
</div>
Expand Down
20 changes: 12 additions & 8 deletions src/components/repos/RepoManagementList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import RepeatIcon from '@mui/icons-material/Repeat';
import CopyIcon from '@mui/icons-material/ContentCopy';
import GAService from '../../services/GAService';
import PinIcon from '../common/PinIcon';
import { LockableMenuItem, useNoticeLocks } from '../common/NoticeLocks';
import { LockableMenuItem, LockTooltip, useNoticeLocks } from '../common/NoticeLocks';

const RepoManagementList = ({ anchorEl, open, onClose, onClick, repo, id, isVersion, hasAccess, createSimilarHref, pin }) => {
// releaseWait: why Release waits on the version (getReleaseWait), or null
const RepoManagementList = ({ anchorEl, open, onClose, onClick, repo, id, isVersion, hasAccess, createSimilarHref, pin, releaseWait }) => {
const { t } = useTranslation()
// An edit action the repository's notices lock is shown disabled, with the notice's reason (NoticeLocks)
const lockFor = useNoticeLocks()
const releaseLock = lockFor('releaseVersion')
const url = isVersion ? repo.version_url : repo.url
let editParams = isVersion ? {onClick: () => onClick('editVersion')} : {href: `${url}edit`}
return (
Expand All @@ -38,12 +40,14 @@ const RepoManagementList = ({ anchorEl, open, onClose, onClick, repo, id, isVers
{
hasAccess && (
isVersion ?
<LockableMenuItem lock={lockFor('releaseVersion')} id='addConcept' onClick={() => onClick('release')} sx={{padding: '8px 12px'}}>
<ListItemIcon sx={{minWidth: 'auto', marginRight: '12px'}}>
<ReleaseIcon color={repo.released ? 'gray' : 'primary'} />
</ListItemIcon>
<ListItemText primary={repo.released ? t('repo.unrelease_version') : t('repo.release_version')} />
</LockableMenuItem> :
<LockTooltip title={releaseLock ? null : releaseWait}>
<LockableMenuItem lock={releaseLock} disabled={Boolean(releaseLock || releaseWait)} id='addConcept' onClick={() => onClick('release')} sx={{padding: '8px 12px'}}>
<ListItemIcon sx={{minWidth: 'auto', marginRight: '12px'}}>
<ReleaseIcon color={repo.released ? 'gray' : 'primary'} />
</ListItemIcon>
<ListItemText primary={repo.released ? t('repo.unrelease_version') : t('repo.release_version')} />
</LockableMenuItem>
</LockTooltip> :
<Box>
<LockableMenuItem lock={lockFor('addConcept')} id='addConcept' onClick={() => onClick('addConcept')} sx={{padding: '8px 12px'}}>
<ListItemIcon sx={{minWidth: 'auto', marginRight: '12px'}}>
Expand Down
Loading
Loading