From 6f632c99abdb629bec73048d6a387908d51865e2 Mon Sep 17 00:00:00 2001 From: Andreas Katis Date: Tue, 4 Oct 2022 20:23:26 -0400 Subject: [PATCH] Fixed bug with imported reports having multiple entries for requirements under certain conditions. --- .../app/components/AnalysisReportContent.js | 2 + .../components/DiagnosisRequirementsTable.js | 42 +++++++++---------- .../app/components/RealizabilityContent.js | 7 +++- .../app/components/RealizabilityView.js | 3 +- .../app/components/SaveRealizabilityReport.js | 3 +- 5 files changed, 31 insertions(+), 26 deletions(-) diff --git a/fret-electron/app/components/AnalysisReportContent.js b/fret-electron/app/components/AnalysisReportContent.js index b3bfe325..b864d350 100644 --- a/fret-electron/app/components/AnalysisReportContent.js +++ b/fret-electron/app/components/AnalysisReportContent.js @@ -232,6 +232,7 @@ class AnalysisReportContent extends React.Component { existingProjectNames={[selectedProject]} connectedComponent={selected.compositional.connectedComponents[connectedComponentIndex]} importedRequirements={selected.requirements} + selectedRequirements={selected.selectedReqs} /> @@ -256,6 +257,7 @@ class AnalysisReportContent extends React.Component { existingProjectNames={[selectedProject]} connectedComponent={{}} importedRequirements={selected.requirements} + selectedRequirements={selected.selectedReqs} /> diff --git a/fret-electron/app/components/DiagnosisRequirementsTable.js b/fret-electron/app/components/DiagnosisRequirementsTable.js index 7ebf819d..dfad475e 100644 --- a/fret-electron/app/components/DiagnosisRequirementsTable.js +++ b/fret-electron/app/components/DiagnosisRequirementsTable.js @@ -144,7 +144,6 @@ function ccStableSort(array, conflictReqs, selectedReqs, connectedComponent, cmp if (conflictReqs.length === 0) { const ccData = array.filter(el => connectedComponent.requirements.includes(el.reqid)); const notSelectedData = array.filter(el => !selectedReqs.includes(el.reqid)); - const remainingData = array.filter(el => (!connectedComponent.requirements.includes(el.reqid) && !notSelectedData.map(el => el.reqid).includes(el.reqid))); const sortedRemaining = remainingData.map((el, index) => [el, index]); @@ -314,7 +313,7 @@ class DiagnosisRequirementsTableHead extends React.Component { return ( - {(importedRequirements.length === 0) && + {importedRequirements.length === 0 && 0 && numSelected < rowCount} @@ -420,7 +419,7 @@ class DiagnosisRequirementsTable extends React.Component { } componentDidMount() { - const { importedRequirements } = this.props; + const { importedRequirements, selectedRequirements } = this.props; this.mounted = true; if (importedRequirements.length === 0) { this.synchStateWithDB(); @@ -428,7 +427,9 @@ class DiagnosisRequirementsTable extends React.Component { this.setState({ data: importedRequirements.map(r => { return createData(r._id, r._rev, r.reqid, r.fulltext, r.project); - }).sort((a, b) => {return a.reqid > b.reqid}) + }).sort((a, b) => {return a.reqid > b.reqid}), + selected: [].concat(selectedRequirements), + tempSelected: [].concat(selectedRequirements) }); } } @@ -444,13 +445,13 @@ class DiagnosisRequirementsTable extends React.Component { componentDidUpdate(prevProps) { const { connectedComponent, importedRequirements, selectedRequirements } = this.props; - if (connectedComponent !== prevProps.connectedComponent) { + + if (connectedComponent && (connectedComponent !== prevProps.connectedComponent)) { if (importedRequirements.length === 0) { const {setMessage} = this.context; setMessage({reqs : '', color : ''}) - let newSelectedReqs = selectedRequirements; - this.setState({selected: [].concat(newSelectedReqs)}) - } + this.setState({selected: [].concat(selectedRequirements)}) + } } } @@ -602,7 +603,7 @@ class DiagnosisRequirementsTable extends React.Component { const isSelected = this.isSelected(n.reqid); const label = n.reqid ? n.reqid.replace(/-/g,'') : 'NONE' var isInConflict = (reqs.length !== 0 && reqs.includes(label)) ? true : false; - const isInConflictOrCC = (isInConflict || connectedComponent.requirements.includes(n.reqid)); + const isInConflictOrCC = (isInConflict || connectedComponent.requirements.includes(n.reqid)); return ( { this.handleClick(event, n.reqid)}} + onClick={event => { importedRequirements.length === 0 ? this.handleClick(event, n.reqid) : null}} > - {(importedRequirements.length === 0) && + {true && - + } @@ -640,23 +639,22 @@ class DiagnosisRequirementsTable extends React.Component { const isSelected = this.isSelected(n.reqid); const label = n.reqid ? n.reqid.replace(/-/g,'') : 'NONE' var isInConflict = (reqs.length !== 0 && reqs.includes(label)) ? true : false; - var isAssumption = n.reqid.includes('assumption') - const isInConflictOrAssumptions = (isInConflict || reqs.length === 0 || isAssumption); + //var isAssumption = n.reqid.includes('assumption') + //const isInConflictOrAssumptions = (isInConflict || reqs.length === 0 || isAssumption); + const isInConflictOrSelected = (isInConflict || isSelected); return ( this.handleClick(event, n.reqid)} + onClick={event => (importedRequirements.length === 0 ? this.handleClick(event, n.reqid) : null)} > - {(importedRequirements.length === 0) && + {true && - + } diff --git a/fret-electron/app/components/RealizabilityContent.js b/fret-electron/app/components/RealizabilityContent.js index 2f2853a1..1abc0915 100644 --- a/fret-electron/app/components/RealizabilityContent.js +++ b/fret-electron/app/components/RealizabilityContent.js @@ -721,7 +721,12 @@ class RealizabilityContent extends React.Component { projectReport.systemComponents = [].concat(projectReport.systemComponents.map(obj => { if (obj.name === component.component_name) { - return {...obj, comments: '', monolithic: {result: 'UNCHECKED', time: '', diagnosisStatus: '', diagnosisReport: '', error: ''}, compositional: {result: 'UNCHECKED', connectedComponents: ccArray, error: ''}, requirements: fretResult.docs}; + return {...obj, + comments: '', + monolithic: {result: 'UNCHECKED', time: '', diagnosisStatus: '', diagnosisReport: '', error: ''}, + compositional: {result: 'UNCHECKED', connectedComponents: ccArray, error: ''}, + requirements: fretResult.docs, + selectedReqs: (selectedReqs.length === 0 ? fretResult.docs.filter(doc => doc.semantics.component_name === component.component_name).map(doc => doc.reqid) : selectedReqs)}; } return obj; })) diff --git a/fret-electron/app/components/RealizabilityView.js b/fret-electron/app/components/RealizabilityView.js index 52ed3986..329a04a0 100644 --- a/fret-electron/app/components/RealizabilityView.js +++ b/fret-electron/app/components/RealizabilityView.js @@ -110,7 +110,8 @@ class RealizabilityView extends React.Component { } } - handleLoadClick = (event) => { + handleLoadClick = (event) => { + event.stopPropagation(); var homeDir = app.getPath('home'); var filepaths = dialog.showOpenDialogSync({ defaultPath: homeDir, diff --git a/fret-electron/app/components/SaveRealizabilityReport.js b/fret-electron/app/components/SaveRealizabilityReport.js index 4488d82e..fa970700 100644 --- a/fret-electron/app/components/SaveRealizabilityReport.js +++ b/fret-electron/app/components/SaveRealizabilityReport.js @@ -57,11 +57,10 @@ class SaveRealizabilityReport extends React.Component { saveRealizabilityResults = async (event) => { event.stopPropagation(); - const {projectReport} = this.props; + const {projectReport, selectedRequirements} = this.props; const homeDir = app.getPath('home'); projectReport.systemComponents = projectReport.systemComponents.filter(sc => sc.monolithic); - // const self = this; var filePathObject = await dialog.showSaveDialog({ defaultPath : homeDir,