diff --git a/src/viewer/App.tsx b/src/viewer/App.tsx index dc543c0..2afcc13 100644 --- a/src/viewer/App.tsx +++ b/src/viewer/App.tsx @@ -228,7 +228,7 @@ export default class App extends React.Component { if (isClose === true) this.setState({ rules: newRules, - logFile: this.state.logFile.updateRules(newRules), + logFile: this.state.logFile.updateLogFile(newRules, []), showStatesDialog: false, showFlagsDialog: false, }); @@ -352,11 +352,14 @@ export default class App extends React.Component { currentStructureMatch = []; } + console.log(structureMatches) + this.setState({ rowProperties, structureMatches, currentStructureMatch, currentStructureMatchIndex, + logFile: this.state.logFile.updateLogFile(this.state.rules, structureMatches) }); } diff --git a/src/viewer/LogFile.tsx b/src/viewer/LogFile.tsx index 7e391d0..7205c01 100644 --- a/src/viewer/LogFile.tsx +++ b/src/viewer/LogFile.tsx @@ -41,11 +41,39 @@ export default class LogFile { return logFile; } - updateRules(rules: Rule[]): LogFile { - // Slower solution + updateLogFile(rules: Rule[], structureMatches: number[][]): LogFile { const [updatedSelected, updatedSelectedMini] = this.updateSelectedColumns(rules) const headers = LogFile.getHeaders(this.contentHeaders, rules); - const logFile = new LogFile(this.contentHeaders, headers, this.rows); + + let rows = this.rows; + if (this.rows[0].length === headers.length + 1) + rows = this.rows.map(r => r.slice(0,-1)) + + if (structureMatches.length > 0) { + updatedSelected.push(false); + updatedSelectedMini.push(true); + const name = "Structure" + const type = DEFAULT_HEADER_TYPE; + headers.push({name, type}); + let currentStructureIndex = 0; + for (let i = 0; i < rows.length; i++) { + rows[i].push(""); + if (currentStructureIndex < structureMatches.length) { + if (i > structureMatches[currentStructureIndex].at(-1)!) { + currentStructureIndex++; + if (currentStructureIndex === structureMatches.length) + break; + } + + if (structureMatches[currentStructureIndex].includes(i)) { + rows[i].pop(); + rows[i].push((currentStructureIndex + 1).toString()); + } + } + } + } + + const logFile = new LogFile(this.contentHeaders, headers, rows); logFile.copyDefaultColumnColors(this.columnsColors); logFile.computeRulesValuesAndColors(rules); return logFile.setSelectedColumns(updatedSelected, updatedSelectedMini); @@ -138,16 +166,16 @@ export default class LogFile { private computeRulesValuesAndColors(rules: Rule[]) { // Compute rules values - const startIndex = this.headers.length - rules.length; + const firstRuleIndex = this.contentHeaders.length; const rulesValues = rules.map((r) => r.computeValues(this)); for (let row = 0; row < this.rows.length; row++) { for (let column = 0; column < rulesValues.length; column++) { - this.rows[row][column + startIndex] = rulesValues[column][row]; + this.rows[row][column + firstRuleIndex] = rulesValues[column][row]; } } // Compute colors - for (let i = startIndex; i < this.headers.length; i++) { + for (let i = firstRuleIndex; i < this.headers.length; i++) { const values = this.rows.map((r) => r[i]); this.columnsColors[i] = LogFile.computeColors(this.headers[i], values); }