Skip to content

Major update to saving. Takes DOM building out of PHP. #1030

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

Open
wants to merge 6 commits into
base: new-main-page-UX
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
106 changes: 28 additions & 78 deletions assets/js/Components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,19 @@ import ReportsPage from './ReportsPage'
import SettingsPage from './SettingsPage'
import Api from '../Services/Api'
import MessageTray from './MessageTray'
import { analyzeReport } from '../Services/Report'


export default function App(initialData) {

// The initialData object that is passed to the App will generally contain:
// {
// messages: [],
// report: { ... The report from the most recent scan ... },
// settings: { ... From src/Controller/DashboardController.php => getSettings() ... },
// settings.user: {
// "id": 3,
// "username": "https://canvas.instructure.com||1129",
// "name": null,
// "lmsUserId": "1129",
// "roles": [
// "ROLE_USER" // or "ROLE_ADVANCED_USER" if they've clicked to skip the welcome page.
// ],
// "lastLogin": "2025-02-03",
// "created": "2025-01-13",
// "hasApiKey": true
// }
// }

const [messages, setMessages] = useState(initialData.messages || [])
const [report, setReport] = useState(initialData.report || null)
const [settings, setSettings] = useState(initialData.settings || null)
const [sections, setSections] = useState([])

const [navigation, setNavigation] = useState('summary')
const [modal, setModal] = useState(null)
const [syncComplete, setSyncComplete] = useState(false)
const [hasNewReport, setHasNewReport] = useState(false)
const [disableReview, setDisableReview] = useState(false)
const [initialSeverity, setInitialSeverity] = useState('')
const [initialSearchTerm, setInitialSearchTerm] = useState('')
const [contentItemCache, setContentItemCache] = useState([])
Expand Down Expand Up @@ -119,23 +99,36 @@ export default function App(initialData) {
setSessionIssues(newSessionIssues)
}

const processNewReport = (rawReport) => {
console.log("Processing a raw report!")
const tempReport = analyzeReport(rawReport)
setReport(tempReport)
console.log(tempReport)

if (tempReport.contentSections) {
setSections(tempReport.contentSections)
}
else {
setSections([])
}

let tempContentItems = {}
for(const key in tempReport.contentItems) {
tempContentItems[key] = tempReport.contentItems[key]
}
setContentItemCache(tempContentItems)
console.log("Setting new content item cache!")
console.log(tempContentItems)
}

const handleNewReport = (data) => {
let newReport = report
let newHasNewReport = hasNewReport
let newDisableReview = disableReview
if (data.messages) {
data.messages.forEach((msg) => {
if (msg.visible) {
addMessage(msg)
}
if ('msg.no_report_created' === msg.message) {
addMessage(msg)
newReport = null
newDisableReview = true
}
if ("msg.sync.course_inactive" === msg.message) {
newDisableReview = true
}
})
}
if (data.data && data.data.id) {
Expand All @@ -144,14 +137,10 @@ export default function App(initialData) {
}
setSyncComplete(true)
setHasNewReport(newHasNewReport)
setReport(newReport)
if (newReport.contentSections) {
setSections(newReport.contentSections)
}
else {
setSections([])

if(newHasNewReport) {
processNewReport(newReport)
}
setDisableReview(newDisableReview)
}

const handleNavigation = (newNavigation) => {
Expand All @@ -165,10 +154,6 @@ export default function App(initialData) {
setNavigation(newNavigation)
}

const handleModal = (modal) => {
setModal(modal)
}

const addMessage = (msg) => {
setMessages(prevMessages => [...prevMessages, msg])
}
Expand Down Expand Up @@ -205,38 +190,6 @@ export default function App(initialData) {
setContentItemCache(newContentItemCache)
}

// When an issue has been saved, the page is rescanned and a new report is generated.
// THIS MEANS THAT ALL OF THE UNRESOLVED ISSUES ON THAT PAGE WILL BE REMOVED and then
// replaced (if necessary) in the new scan. The newIssue will PROBABLY have a valid
// issueId in the new report (unless it was marked as UNresolved).
const updateReportIssue = (newReport) => {
if(!newReport) {
return
}
const updatedReport = { ...newReport }
setReport(updatedReport)
}

const updateReportFile = (newFile) => {
let updatedReport = { ...report }
console.log(updateReport)
console.log(newFile)
if (updatedReport && updatedReport.files) {
updatedReport.files[newFile.id] = newFile
}
setReport(updatedReport)
}

const handleCourseRescan = () => {
if (hasNewReport) {
setHasNewReport(false)
setSyncComplete(false)
scanCourse()
.then((response) => response.json())
.then(handleNewReport)
}
}

const handleFullCourseRescan = () => {
if (hasNewReport) {
setHasNewReport(false)
Expand Down Expand Up @@ -310,14 +263,11 @@ export default function App(initialData) {
addContentItemToCache={addContentItemToCache}
report={report}
sections={sections}
setReport={setReport}
processNewReport={processNewReport}
addMessage={addMessage}
handleNavigation={handleNavigation}
updateReportIssue={updateReportIssue}
updateReportFile={updateReportFile}
sessionIssues={sessionIssues}
updateSessionIssue={updateSessionIssue}
disableReview={syncComplete && !disableReview} />
updateSessionIssue={updateSessionIssue} />
}
{('reports' === navigation) &&
<ReportsPage
Expand Down
62 changes: 29 additions & 33 deletions assets/js/Components/FixIssuesContentPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ export default function FixIssuesContentPreview({
}) {

const [taggedContent, setTaggedContent] = useState(null)
const [altTextPreview, setAltTextPreview] = useState(null)
const [canShowPreview, setCanShowPreview] = useState(false)


const [issueElementDefaultRect, setIssueElementDefaultRect] = useState(null)
const issueElementRef = useRef(null)
const issueElementVisible = useInViewPort(issueElementRef, { threshold: 0.5 })
Expand Down Expand Up @@ -196,30 +194,24 @@ export default function FixIssuesContentPreview({

const getTaggedContent = (activeIssue, activeContentItem) => {

setAltTextPreview(null)
if (!activeIssue || !activeContentItem) {
return null
}

let fullPageHtml = activeContentItem.body
let errorHtml = activeIssue?.issueData?.sourceHtml || undefined
if(activeIssue.status === settings.FILTER.FIXED) {
errorHtml = activeIssue?.issueData?.newHtml || errorHtml
}

if(errorHtml === undefined || errorHtml === '') {
return fullPageHtml
}

const parser = new DOMParser()
const doc = parser.parseFromString(fullPageHtml, 'text/html')

const errorElement = Html.toElement(errorHtml)

let errorElement = Html.findElementWithIssue(doc, activeIssue?.issueData)
if(!errorElement) {
setCanShowPreview(false)
setIsErrorFoundInContent(false)
return fullPageHtml
}
else {
errorElement.replaceWith(convertErrorHtmlElement(errorElement))
setCanShowPreview(true)
setIsErrorFoundInContent(true)
}

// Find all of the <details> elements in the document (if present).
Expand All @@ -231,21 +223,21 @@ export default function FixIssuesContentPreview({
}
})

// Find the first element in the document that matches the error element.
const docElement = Array.from(doc.body.querySelectorAll(errorElement.tagName)).find((matchElement) => {
return matchElement.outerHTML.trim() === errorElement.outerHTML.trim()
})

// If the element is found, update it with the appropriate class.
if(docElement) {
setCanShowPreview(true)
setIsErrorFoundInContent(true)
docElement.replaceWith(convertErrorHtmlElement(docElement))
}
else {
setCanShowPreview(false)
setIsErrorFoundInContent(false)
}
// // Find the first element in the document that matches the error element.
// const docElement = Array.from(doc.body.querySelectorAll(errorElement.tagName)).find((matchElement) => {
// return matchElement.outerHTML.trim() === errorElement.outerHTML.trim()
// })

// // If the element is found, update it with the appropriate class.
// if(docElement) {
// setCanShowPreview(true)
// setIsErrorFoundInContent(true)
// docElement.replaceWith(convertErrorHtmlElement(docElement))
// }
// else {
// setCanShowPreview(false)
// setIsErrorFoundInContent(false)
// }

// Find all of the heading elements and show them when a relevant issues is being edited.
if(SHOW_HEADINGS_RULES.includes(activeIssue.scanRuleId)) {
Expand All @@ -257,8 +249,10 @@ export default function FixIssuesContentPreview({
})
}

const serializer = new XMLSerializer()
return serializer.serializeToString(doc)
return doc.body.innerHTML

// const serializer = new XMLSerializer()
// return serializer.serializeToString(doc)
}

useEffect(() => {
Expand All @@ -267,7 +261,9 @@ export default function FixIssuesContentPreview({
setIsErrorFoundInContent(true)
return
}
setTaggedContent(getTaggedContent(activeIssue, activeContentItem))
if(activeIssue.contentType !== settings.FILTER.FILE_OBJECT) {
setTaggedContent(getTaggedContent(activeIssue, activeContentItem))
}
}, [activeIssue, activeContentItem])

useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions assets/js/Components/FixIssuesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function FixIssuesList({ t, settings, filteredIssues, setActiveIs
const [groupedList, setGroupedList] = useState([])

useEffect(() => {
console.log("FixIssuesList caught a change in filteredIssues")
const tempGroupedList = []

// Get all of the issues' "formLabel" values
Expand All @@ -29,6 +30,7 @@ export default function FixIssuesList({ t, settings, filteredIssues, setActiveIs
})

setGroupedList(tempGroupedList)
console.log("Setting new Grouped List!")

}, [filteredIssues])

Expand Down
Loading