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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ src/stories/
dist/
.idea/
.DS_Store
.env
29 changes: 27 additions & 2 deletions src/components/common/ConceptContainerVersionList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const updateVersion = (version, data, verb, successCallback) => getService(versi
const getVersionURI = version => get(version, 'uri') || get(version, 'version_url') || get(version, 'url');
const getPreviousVersionURI = version => get(version, 'previous_version_url');
const isHeadVersion = version => (get(version, 'id') || get(version, 'version') || '').toLowerCase() === 'head';
const normalizeURI = uri => (uri || '').replace(/\/+$/, '/');
const getVersionLabelFromURL = url => {
const parts = (url || '').split('/').filter(Boolean)
return parts[parts.length - 1] || url
Expand All @@ -118,8 +119,10 @@ const ConceptContainerVersionList = ({ versions, resource, canEdit, onUpdate, fh
const [isChangelogFullScreen, setIsChangelogFullScreen] = React.useState(false);
const [showChangelogLoadingMessage, setShowChangelogLoadingMessage] = React.useState(false);
const changelogLoadingTimer = React.useRef(null);
const changelogRequestId = React.useRef(0);

React.useEffect(() => () => {
changelogRequestId.current += 1
if(changelogLoadingTimer.current)
clearTimeout(changelogLoadingTimer.current)
}, [])
Expand Down Expand Up @@ -169,7 +172,12 @@ const ConceptContainerVersionList = ({ versions, resource, canEdit, onUpdate, fh
if(resource !== 'source' || fhir || isHeadVersion(version))
return null

return getPreviousVersionURI(version)
const previousVersionURL = getPreviousVersionURI(version)
const unversionedSourceURL = get(version, 'url')
if(!previousVersionURL || normalizeURI(previousVersionURL) === normalizeURI(unversionedSourceURL))
return null

return previousVersionURL
}

const onChangelogClick = version => {
Expand All @@ -180,6 +188,10 @@ const ConceptContainerVersionList = ({ versions, resource, canEdit, onUpdate, fh
if(changelogLoadingTimer.current)
clearTimeout(changelogLoadingTimer.current)

const requestId = changelogRequestId.current + 1
changelogRequestId.current = requestId
const isActiveChangelogRequest = () => requestId === changelogRequestId.current

setChangelogDialog(true)
setChangelogVersion(version)
setPreviousChangelogVersionURL(previousVersionURL)
Expand All @@ -202,6 +214,9 @@ const ConceptContainerVersionList = ({ versions, resource, canEdit, onUpdate, fh
{inline: true, output: 'markdown', verbosity: 4}
)
.then(response => {
if(!isActiveChangelogRequest())
return

const markdown = get(response, 'data.markdown') || get(response, 'markdown')

if(markdown) {
Expand All @@ -211,20 +226,30 @@ const ConceptContainerVersionList = ({ versions, resource, canEdit, onUpdate, fh
setChangelogError(get(response, 'detail') || get(response, 'error') || 'Could not load changelog.')
}
})
.catch(() => setChangelogError('Could not load changelog.'))
.catch(() => {
if(isActiveChangelogRequest())
setChangelogError('Could not load changelog.')
})
.finally(() => {
if(!isActiveChangelogRequest())
return

if(changelogLoadingTimer.current)
clearTimeout(changelogLoadingTimer.current)
setIsChangelogLoading(false)
})
}

const onChangelogClose = () => {
changelogRequestId.current += 1
if(changelogLoadingTimer.current)
clearTimeout(changelogLoadingTimer.current)
setChangelogDialog(false)
setIsChangelogFullScreen(false)
setIsChangelogLoading(false)
setShowChangelogLoadingMessage(false)
setChangelogMarkdown('')
setChangelogError('')
}


Expand Down