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

Bugfix flag annotations #58

Merged
merged 10 commits into from
Oct 3, 2023
20 changes: 10 additions & 10 deletions src/viewer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export default class App extends React.Component<Props, State> {
currentStructureMatch: [],
lastSelectedRow: undefined,
collapsibleRows: {},
// collapsibleRows: { 1: constructNewSegment(1, 10, 0), 2: constructNewSegment(2, 6, 1), 5: constructNewSegment(5, 15, 0), 7: constructNewSegment(7, 10, 1), 0 : constructNewSegment(0, 20, 2)},
};

this.onMessage = this.onMessage.bind(this);
Expand Down Expand Up @@ -197,12 +196,12 @@ export default class App extends React.Component<Props, State> {
}
}

handleDialogActions(newRules: Rule[], is_close: boolean) {
handleAnnotationDialog(newRules: Rule[], is_close: boolean) {
ckitsanelis marked this conversation as resolved.
Show resolved Hide resolved
this.vscode.postMessage({ type: "saveRules", rules: newRules.map((r) => r.toJSON()) });
if (is_close === true)
this.setState({
rules: newRules,
logFile: this.state.logFile.update(newRules),
logFile: this.state.logFile.updateRules(newRules),
showStatesDialog: false,
showFlagsDialog: false,
});
Expand All @@ -213,13 +212,14 @@ export default class App extends React.Component<Props, State> {
if (is_close === true) {
this.setState({
selectedColumns: selectedCols,
selectedColumnsMini: selectedColsMini,
logFile: this.state.logFile.setSelectedColumns(selectedCols, selectedColsMini),
showSelectDialog: false,
});
}
}

handleStructureDialogActions(isClosing: boolean) {
handleStructureDialog(isClosing: boolean) {
if (isClosing === true) {
logHeaderColumnTypes = [];
this.handleStructureUpdate(isClosing);
Expand Down Expand Up @@ -612,7 +612,7 @@ export default class App extends React.Component<Props, State> {
>
<VSCodeButton
appearance="icon"
onClick={() => this.handleStructureDialogActions(false)}
onClick={() => this.handleStructureDialog(false)}
>
<i className="codicon codicon-three-bars" />
</VSCodeButton>
Expand Down Expand Up @@ -662,16 +662,16 @@ export default class App extends React.Component<Props, State> {
<StatesDialog
logFile={this.state.logFile}
initialRules={this.state.rules}
onClose={(newRules) => this.handleDialogActions(newRules, true)}
onReturn={(newRules) => this.handleDialogActions(newRules, false)}
onClose={(newRules) => this.handleAnnotationDialog(newRules, true)}
onReturn={(newRules) => this.handleAnnotationDialog(newRules, false)}
/>
)}
{this.state.showFlagsDialog && (
<FlagsDialog
logFile={this.state.logFile}
initialRules={this.state.rules}
onClose={(newRules) => this.handleDialogActions(newRules, true)}
onReturn={(newRules) => this.handleDialogActions(newRules, false)}
onClose={(newRules) => this.handleAnnotationDialog(newRules, true)}
onReturn={(newRules) => this.handleAnnotationDialog(newRules, false)}
/>
)}
{this.state.showSelectDialog && (
Expand All @@ -694,7 +694,7 @@ export default class App extends React.Component<Props, State> {
logSelectedRows={this.state.selectedLogRows}
currentStructureMatchIndex={this.state.currentStructureMatchIndex}
numberOfMatches={this.state.structureMatches.length}
onClose={() => this.handleStructureDialogActions(true)}
onClose={() => this.handleStructureDialog(true)}
onStructureUpdate={() => this.handleStructureUpdate(false)}
onMatchStructure={(expression) => this.handleStructureMatching(expression)}
onDefineSegment={(entryExpression, exitExpression) =>
Expand Down
45 changes: 40 additions & 5 deletions src/viewer/LogFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,40 @@ export default class LogFile {
return logFile;
}

update(rules: Rule[]): LogFile {
this.updateHeaders(rules);
this.computeRulesValuesAndColors(rules);
this.setSelectedColumns(this.selectedColumns, this.selectedColumnsMini); //only show the selected columns after updating the rules
return this;
updateRules(rules: Rule[]): LogFile {
// Slower solution
let [updatedSelected, updatedSelectedMini] = this.updateSelectedColumns(rules)
ckitsanelis marked this conversation as resolved.
Show resolved Hide resolved
const headers = LogFile.getHeaders(this.contentHeaders, rules);
let logFile = new LogFile(this.contentHeaders, headers, this.rows);
logFile.copyDefaultColumnColors(this.columnsColors);
logFile.computeRulesValuesAndColors(rules);
logFile = logFile.setSelectedColumns(updatedSelected, updatedSelectedMini);
return logFile;
ckitsanelis marked this conversation as resolved.
Show resolved Hide resolved

// Old solution
// this.updateSelectedColumns(rules);
// this.updateHeaders(rules);
// this.computeRulesValuesAndColors(rules);
// return this;
}

updateSelectedColumns(rules: Rule[]) {
let existingHeaders = this.headers.map(h => h.name);
let updatedSelected = this.selectedColumns.slice(0, this.contentHeaders.length);
let updatedSelectedMini = this.selectedColumnsMini.slice(0, this.contentHeaders.length);
ckitsanelis marked this conversation as resolved.
Show resolved Hide resolved

for (let i = 0; i < rules.length; i++) {
let existingIndex = existingHeaders.indexOf(rules[i].column);
ckitsanelis marked this conversation as resolved.
Show resolved Hide resolved
if (existingIndex > -1) {
updatedSelected.push(this.selectedColumns[existingIndex]);
updatedSelectedMini.push(this.selectedColumnsMini[existingIndex]);
}
else {
updatedSelected.push(true);
updatedSelectedMini.push(true);
}
}
return [updatedSelected, updatedSelectedMini]
}

setSelectedColumns(selected: boolean[], selectedMini: boolean[]) {
Expand Down Expand Up @@ -99,6 +128,12 @@ export default class LogFile {
}
}

private copyDefaultColumnColors(colours: string[][]) {
for (let i = 0; i < this.contentHeaders.length; i++) {
this.columnsColors[i] = colours[i];
}
}

private computeRulesValuesAndColors(rules: Rule[]) {
// Compute rules values
const startIndex = this.headers.length - rules.length;
Expand Down
14 changes: 10 additions & 4 deletions src/viewer/rules/Dialogs/FlagsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export default class FlagsDialog extends React.Component<Props, State> {
const userColumns = this.state.rules
.map((r, i) => r.column)
.filter((name) => name != rule.column);
const defaultRuleColumn = `FlagRule${ruleIndex + 1}`;
const keyWidth = "100px";
const textFieldWidth = "250px";
const rows = [
Expand All @@ -185,8 +184,9 @@ export default class FlagsDialog extends React.Component<Props, State> {
style={{ width: textFieldWidth, marginBottom: "2px" }}
value={rule.column}
key="Name"
placeholder="Required"
onInput={(e) =>
this.updateRule(rule.setColumn(e.target.value || defaultRuleColumn), ruleIndex)
this.updateRule(rule.setColumn(e.target.value), ruleIndex)
}
/>,
],
Expand Down Expand Up @@ -262,14 +262,20 @@ export default class FlagsDialog extends React.Component<Props, State> {
{this.state.showEdit && <div className="title-big">Edit Flag Annotation Column</div>}
{this.state.showEdit && (
<VSCodeButton
style={{ marginLeft: "auto" }}
appearance="icon"
style={{ marginLeft: "auto" }}
disabled={this.state.rules[this.state.selectedRule].column === '' ? true : false}
ckitsanelis marked this conversation as resolved.
Show resolved Hide resolved
onClick={() => this.onDialogClick(false)}
>
<i className="codicon codicon-arrow-left" />
</VSCodeButton>

)}
<VSCodeButton appearance="icon" onClick={() => this.onDialogClick(true)}>
<VSCodeButton
appearance="icon"
disabled={(this.state.selectedRule === -1) || ((this.state.selectedRule !== -1) && (this.state.rules[this.state.selectedRule].column !== '')) ? false : true}
onClick={() => this.onDialogClick(true)}
>
<i className="codicon codicon-close" />
</VSCodeButton>
</div>
Expand Down
13 changes: 9 additions & 4 deletions src/viewer/rules/Dialogs/StatesDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ export default class StatesDialog extends React.Component<Props, State> {
const userColumns = this.state.rules
.map((r, i) => r.column)
.filter((name) => name != rule.column);
const defaultRuleColumn = `StateRule${ruleIndex + 1}`;
const keyWidth = "100px";
const textFieldWidth = "250px";
const rows = [
Expand All @@ -164,8 +163,9 @@ export default class StatesDialog extends React.Component<Props, State> {
style={{ width: textFieldWidth, marginBottom: "2px" }}
value={rule.column}
key="Name"
placeholder="Required"
onInput={(e) =>
this.updateRule(rule.setColumn(e.target.value || defaultRuleColumn), ruleIndex)
this.updateRule(rule.setColumn(e.target.value), ruleIndex)
}
/>,
],
Expand Down Expand Up @@ -219,14 +219,19 @@ export default class StatesDialog extends React.Component<Props, State> {
)}
{this.state.showEdit && (
<VSCodeButton
style={{ marginLeft: "auto" }}
appearance="icon"
style={{ marginLeft: "auto" }}
disabled={this.state.rules[this.state.selectedRule].column === '' ? true : false}
ckitsanelis marked this conversation as resolved.
Show resolved Hide resolved
onClick={() => this.onDialogClick(false)}
>
<i className="codicon codicon-arrow-left" />
</VSCodeButton>
)}
<VSCodeButton appearance="icon" onClick={() => this.onDialogClick(true)}>
<VSCodeButton
appearance="icon"
disabled={(this.state.selectedRule === -1) || ((this.state.selectedRule !== -1) && (this.state.rules[this.state.selectedRule].column !== '')) ? false : true}
onClick={() => this.onDialogClick(true)}
>
<i className="codicon codicon-close" />
</VSCodeButton>
</div>
Expand Down