mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 00:34:46 +02:00
WIP: Visual Console Refactor
Former-commit-id: 7114433022097a8b6b2eb4e1f77c91cf8f8007cf
This commit is contained in:
parent
49aaa91d2e
commit
8a8de49ecc
@ -4,6 +4,8 @@ import {
|
|||||||
UnknownObject
|
UnknownObject
|
||||||
} from "../types";
|
} from "../types";
|
||||||
|
|
||||||
|
import { modulePropsDecoder } from "../lib";
|
||||||
|
|
||||||
import VisualConsoleItem, {
|
import VisualConsoleItem, {
|
||||||
VisualConsoleItemProps,
|
VisualConsoleItemProps,
|
||||||
itemPropsDecoder
|
itemPropsDecoder
|
||||||
@ -49,7 +51,8 @@ export function staticGraphPropsDecoder(
|
|||||||
return {
|
return {
|
||||||
imageSrc: data.imageSrc,
|
imageSrc: data.imageSrc,
|
||||||
showLastValueTooltip: parseShowLastValueTooltip(data.showLastValueTooltip),
|
showLastValueTooltip: parseShowLastValueTooltip(data.showLastValueTooltip),
|
||||||
...itemPropsDecoder(data) // Object spread. It will merge the properties of the two objects.
|
...itemPropsDecoder(data), // Object spread. It will merge the properties of the two objects.
|
||||||
|
...modulePropsDecoder(data) // Object spread. It will merge the properties of the two objects.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
import { Position, Size, UnknownObject } from "./types";
|
import {
|
||||||
|
UnknownObject,
|
||||||
|
Position,
|
||||||
|
Size,
|
||||||
|
WithAgentProps,
|
||||||
|
WithModuleProps,
|
||||||
|
LinkedVisualConsoleProps,
|
||||||
|
LinkedVisualConsolePropsStatus
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a number or a default value from a raw value.
|
* Return a number or a default value from a raw value.
|
||||||
@ -58,3 +66,107 @@ export function sizePropsDecoder(data: UnknownObject): Size | never {
|
|||||||
height: parseInt(data.height)
|
height: parseInt(data.height)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a valid typed object from a raw object.
|
||||||
|
* @param data Raw object.
|
||||||
|
* @return An object representing the agent properties.
|
||||||
|
*/
|
||||||
|
export function agentPropsDecoder(data: UnknownObject): WithAgentProps {
|
||||||
|
// Object destructuring: http://exploringjs.com/es6/ch_destructuring.html
|
||||||
|
const { metaconsoleId, agentId: id, agentName: name } = data;
|
||||||
|
|
||||||
|
const agentProps: WithAgentProps = {
|
||||||
|
agentId: parseIntOr(id, null),
|
||||||
|
agentName: typeof name === "string" && name.length > 0 ? name : null
|
||||||
|
};
|
||||||
|
|
||||||
|
return metaconsoleId != null
|
||||||
|
? {
|
||||||
|
metaconsoleId,
|
||||||
|
...agentProps // Object spread: http://exploringjs.com/es6/ch_parameter-handling.html#sec_spread-operator
|
||||||
|
}
|
||||||
|
: agentProps;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a valid typed object from a raw object.
|
||||||
|
* @param data Raw object.
|
||||||
|
* @return An object representing the module and agent properties.
|
||||||
|
*/
|
||||||
|
export function modulePropsDecoder(data: UnknownObject): WithModuleProps {
|
||||||
|
// Object destructuring: http://exploringjs.com/es6/ch_destructuring.html
|
||||||
|
const { moduleId: id, moduleName: name } = data;
|
||||||
|
|
||||||
|
return {
|
||||||
|
moduleId: parseIntOr(id, null),
|
||||||
|
moduleName: typeof name === "string" && name.length > 0 ? name : null,
|
||||||
|
...agentPropsDecoder(data)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a valid typed object from a raw object.
|
||||||
|
* @param data Raw object.
|
||||||
|
* @return An object representing the linked visual console properties.
|
||||||
|
* @throws Will throw a TypeError if the status calculation properties are invalid.
|
||||||
|
*/
|
||||||
|
export function linkedVCPropsDecoder(
|
||||||
|
data: UnknownObject
|
||||||
|
): LinkedVisualConsoleProps | never {
|
||||||
|
// Object destructuring: http://exploringjs.com/es6/ch_destructuring.html
|
||||||
|
const {
|
||||||
|
metaconsoleId,
|
||||||
|
linkedLayoutId: id,
|
||||||
|
linkedLayoutAgentId: agentId
|
||||||
|
} = data;
|
||||||
|
|
||||||
|
let linkedLayoutStatusProps: LinkedVisualConsolePropsStatus = {
|
||||||
|
linkedLayoutStatusType: "default"
|
||||||
|
};
|
||||||
|
switch (data.linkedLayoutStatusType) {
|
||||||
|
case "weight":
|
||||||
|
const weight = parseIntOr(data.linkedLayoutStatusTypeWeight, null);
|
||||||
|
if (weight == null)
|
||||||
|
throw new TypeError("invalid status calculation properties.");
|
||||||
|
|
||||||
|
if (data.linkedLayoutStatusTypeWeight)
|
||||||
|
linkedLayoutStatusProps = {
|
||||||
|
linkedLayoutStatusType: "weight",
|
||||||
|
linkedLayoutStatusTypeWeight: weight
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case "service":
|
||||||
|
const warningThreshold = parseIntOr(
|
||||||
|
data.linkedLayoutStatusTypeWarningThreshold,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
const criticalThreshold = parseIntOr(
|
||||||
|
data.linkedLayoutStatusTypeCriticalThreshold,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
if (warningThreshold == null || criticalThreshold == null) {
|
||||||
|
throw new TypeError("invalid status calculation properties.");
|
||||||
|
}
|
||||||
|
|
||||||
|
linkedLayoutStatusProps = {
|
||||||
|
linkedLayoutStatusType: "service",
|
||||||
|
linkedLayoutStatusTypeWarningThreshold: warningThreshold,
|
||||||
|
linkedLayoutStatusTypeCriticalThreshold: criticalThreshold
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const linkedLayoutBaseProps = {
|
||||||
|
linkedLayoutId: parseIntOr(id, null),
|
||||||
|
linkedLayoutAgentId: parseIntOr(agentId, null),
|
||||||
|
...linkedLayoutStatusProps // Object spread: http://exploringjs.com/es6/ch_parameter-handling.html#sec_spread-operator
|
||||||
|
};
|
||||||
|
|
||||||
|
return metaconsoleId != null
|
||||||
|
? {
|
||||||
|
metaconsoleId,
|
||||||
|
...linkedLayoutBaseProps // Object spread: http://exploringjs.com/es6/ch_parameter-handling.html#sec_spread-operator
|
||||||
|
}
|
||||||
|
: linkedLayoutBaseProps;
|
||||||
|
}
|
||||||
|
@ -23,11 +23,7 @@ export interface WithModuleProps extends WithAgentProps {
|
|||||||
moduleName: string | null;
|
moduleName: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LinkedVisualConsoleProps = {
|
export type LinkedVisualConsolePropsStatus =
|
||||||
metaconsoleId?: number | null;
|
|
||||||
linkedLayoutId: number | null;
|
|
||||||
linkedLayoutAgentId: number | null;
|
|
||||||
} & (
|
|
||||||
| {
|
| {
|
||||||
linkedLayoutStatusType: "default";
|
linkedLayoutStatusType: "default";
|
||||||
}
|
}
|
||||||
@ -39,4 +35,9 @@ export type LinkedVisualConsoleProps = {
|
|||||||
linkedLayoutStatusType: "service";
|
linkedLayoutStatusType: "service";
|
||||||
linkedLayoutStatusTypeWarningThreshold: number;
|
linkedLayoutStatusTypeWarningThreshold: number;
|
||||||
linkedLayoutStatusTypeCriticalThreshold: number;
|
linkedLayoutStatusTypeCriticalThreshold: number;
|
||||||
});
|
};
|
||||||
|
export type LinkedVisualConsoleProps = {
|
||||||
|
metaconsoleId?: number | null;
|
||||||
|
linkedLayoutId: number | null;
|
||||||
|
linkedLayoutAgentId: number | null;
|
||||||
|
} & LinkedVisualConsolePropsStatus;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user