Skip to content

Commit

Permalink
Check broken json saved states cases
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanebouget committed Dec 1, 2023
1 parent e6c3cf2 commit c576fbd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import { TreenodesService } from "@khiops-covisualization/providers/treenodes.se
import { AppConfig } from "src/environments/environment";
import { Subscription } from "rxjs";
import { DimensionsDatasVO } from "@khiops-covisualization/model/dimensions-data-vo";
import {
MatrixModesI
} from '@khiops-library/interfaces/matrix-modes';
import {
MatrixOptionsI
} from '@khiops-library/interfaces/matrix-options';

@Component({
selector: "app-matrix-container",
Expand All @@ -33,16 +39,8 @@ export class MatrixContainerComponent implements OnInit, OnDestroy {

sizes: any;

matrixModes = {
types: [],
selected: undefined,
selectedIndex: undefined,
};

matrixOptions = {
types: ["GLOBAL.STANDARD", "GLOBAL.FREQUENCY"],
selected: undefined,
};
matrixModes: MatrixModesI = new MatrixModesI();
matrixOptions: MatrixOptionsI = new MatrixOptionsI();

isFullscreen = false;
treeSelectedNodeChangedSub: Subscription;
Expand Down Expand Up @@ -164,7 +162,7 @@ export class MatrixContainerComponent implements OnInit, OnDestroy {
}

// Check if saved into json
if (this.dimensionsDatas.matrixMode !== undefined) {
if (this.dimensionsDatas.matrixMode !== undefined && this.dimensionsDatas.matrixMode < this.matrixModes.types.length) {
this.matrixModes.selected = this.matrixModes.types[this.dimensionsDatas.matrixMode];
this.matrixModes.selectedIndex = this.dimensionsDatas.matrixMode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ export class DimensionsDatasService {
const savedSelectedDimensions = this.appService.getSavedDatas('selectedDimensions');
if (savedSelectedDimensions) {
for (let i = 0; i < savedSelectedDimensions.length; i++) {
this.updateSelectedDimension(this.dimensionsDatas.selectedDimensions.find(e => e.name === savedSelectedDimensions[i].name), i);
if (savedSelectedDimensions[i]) {
const dimension = this.dimensionsDatas.selectedDimensions.find(e => e.name === savedSelectedDimensions[i].name);
dimension && this.updateSelectedDimension(dimension, i);
}
}
}

Expand All @@ -205,7 +208,7 @@ export class DimensionsDatasService {
updateSelectedDimension(dimension, position) {
// Find current dim position
const currentIndex: any = this.dimensionsDatas.selectedDimensions.findIndex(e => {
return dimension.name === e.name;
return dimension && dimension.name === e.name;
});

if (currentIndex !== -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/khiops-covisualization/providers/save.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class SaveService {
const nodeDetails: TreeNodeVO = this.dimensionsService.dimensionsDatas.dimensionsClusters[dimIndex].find(e => e.cluster === nodeName);

// Get children list
nodeDetails.getChildrenList();
nodeDetails && nodeDetails.getChildrenList();

if (nodeDetails && nodeDetails.childrenList) {
nodeChildren = nodeDetails.childrenList;
Expand Down
5 changes: 3 additions & 2 deletions src/app/khiops-covisualization/providers/treenodes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ export class TreenodesService {
if (savedNodes) {
for (let index = 0; index < savedNodes.length; index++) {
const nodeName = savedNodes[index];
const node = this.getNodeFromName(this.dimensionsDatas.selectedDimensions[index].name, nodeName);
this.dimensionsDatas.selectedNodes.push(node)
const dimension = this.dimensionsDatas.selectedDimensions[index];
const node = dimension && this.getNodeFromName(dimension.name, nodeName);
node && this.dimensionsDatas.selectedNodes.push(node)
}
}
}
Expand Down

0 comments on commit c576fbd

Please sign in to comment.