Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/handle invalid folders in edit nav bar #392

Merged
merged 2 commits into from
Apr 5, 2021
Merged
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
2 changes: 1 addition & 1 deletion src/layouts/EditContactUs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const EditContactUs = ({ match }) => {
if (!footerContent) return

// split the markdown into front matter and content
const { frontMatter } = frontMatterParser(Base64.decode(content));
const { frontMatter } = frontMatterParser(content);

// data cleaning for non-comforming data
const { sanitisedFrontMatter, deletedFrontMatter } = sanitiseFrontMatter(frontMatter)
Expand Down
37 changes: 33 additions & 4 deletions src/layouts/EditNavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import useRedirectHook from '../hooks/useRedirectHook';
import Header from '../components/Header';
import LoadingButton from '../components/LoadingButtonReactQuery';
import DeleteWarningModal from '../components/DeleteWarningModal';
import GenericWarningModal from '../components/GenericWarningModal';
import NavSection from '../components/navbar/NavSection'

import TemplateNavBar from '../templates/NavBar'
Expand Down Expand Up @@ -55,6 +56,8 @@ const EditNavBar = ({ match }) => {
links: [],
sublinks: [],
})
const [showDeletedText, setShowDeletedText] = useState(true)
const [deletedLinks, setDeletedLinks] = useState('')

const LinkCollectionSectionConstructor = () => ({
title: 'Link Title',
Expand Down Expand Up @@ -148,18 +151,28 @@ const EditNavBar = ({ match }) => {

let navHasResources = false
// Add booleans for displaying links and sublinks
const initialDisplayLinks = _.fill(Array(initialLinks.length), false)
const initialDisplayLinks = []
const initialDisplaySublinks = []
const initialErrors = {
links: _.fill(Array(initialLinks.length), enumSection('error')),
sublinks: [],
}
initialLinks.forEach(link => {
let deletedDisplayText = ''
const filteredInitialLinks = []
initialLinks.forEach((link, idx) => {
let numSublinks = 0
if ("sublinks" in link) {
numSublinks = link.sublinks.length
}
if ('resource_room' in link) navHasResources = true
if ('collection' in link && !(link.collection in foldersContent)) {
// Invalid collection linked
deletedDisplayText += `<br/>For link <code>${idx+1}</code>: <br/>`
deletedDisplayText += ` <code>${link.collection}</code> has been removed</br>`
return
}
filteredInitialLinks.push(link)
initialDisplayLinks.push(false)
initialDisplaySublinks.push(_.fill(Array(numSublinks), false))
initialErrors.sublinks.push(_.fill(Array(numSublinks), enumSection('error')))
})
Expand All @@ -173,7 +186,7 @@ const EditNavBar = ({ match }) => {
}))

if (_isMounted) {
setLinks(initialLinks)
setLinks(filteredInitialLinks)
setHasLoaded(true)
setDisplayLinks(initialDisplayLinks)
setDisplaySublinks(initialDisplaySublinks)
Expand All @@ -185,6 +198,7 @@ const EditNavBar = ({ match }) => {
setSha(navSha)
setHasResources(navHasResources)
setErrors(initialErrors)
setDeletedLinks(deletedDisplayText)
}
}

Expand Down Expand Up @@ -567,6 +581,15 @@ const EditNavBar = ({ match }) => {

return (
<>
{ showDeletedText && !isEmpty(deletedLinks)
&&
<GenericWarningModal
displayTitle="Removed content"
displayText={`Some of your content has been removed as they attempt to link to invalid folders. No changes are permanent unless you press Save on the next page.<br/>${deletedLinks}`}
onProceed={()=>{setShowDeletedText(false)}}
proceedText="Acknowledge"
/>
}
{
itemPendingForDelete.id
&& (
Expand Down Expand Up @@ -615,7 +638,13 @@ const EditNavBar = ({ match }) => {
/>
</div>
<div className={editorStyles.pageEditorFooter}>
{/* TODO: save button */}
{ !isEmpty(deletedLinks) &&
<LoadingButton
label="See removed content"
className={`ml-auto ${elementStyles.warning}`}
callback={() => {setShowDeletedText(true)}}
/>
}
<LoadingButton
label="Save"
disabled={hasErrors()}
Expand Down