in src/store/modules/dashboard.ts [81:139]
addControl(type: string) {
const arr = this.layout.map((d: Recordable) => Number(d.i));
let index = String(Math.max(...arr) + 1);
if (!this.layout.length) {
index = "0";
}
const newItem: LayoutConfig = {
...NewControl,
i: index,
id: index,
type,
metricTypes: [""],
metrics: [""],
};
if (type === "Widget") {
newItem.metricMode = MetricModes.Expression;
}
if (type === "Tab") {
newItem.h = 36;
newItem.activedTabIndex = 0;
newItem.children = [
{
name: "Tab1",
children: [],
},
{
name: "Tab2",
children: [],
},
];
}
if (type === "Topology") {
newItem.h = 36;
newItem.graph = {
showDepth: true,
depth: this.entity === EntityType[1].value ? 1 : this.entity === EntityType[0].value ? 2 : 3,
};
}
if (ControlsTypes.includes(type)) {
newItem.h = 36;
}
if (type === "Text") {
newItem.h = 6;
newItem.graph = TextConfig;
}
if (type === "TimeRange") {
newItem.w = 8;
newItem.h = 6;
newItem.graph = TimeRangeConfig;
}
this.activedGridItem = newItem.i;
this.selectedGrid = newItem;
this.layout = this.layout.map((d: LayoutConfig) => {
d.y = d.y + newItem.h;
return d;
});
this.layout.push(newItem);
},