mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
WIP: Visual Console Refactor
Former-commit-id: c82cb8454f12caa66e2b06668f1d486a379be838
This commit is contained in:
parent
cdd67e3637
commit
49aaa91d2e
@ -27,7 +27,7 @@ export type ItemClickEvent<ItemProps extends VisualConsoleItemProps> = {
|
|||||||
* This will allow us to ensure the type safety.
|
* This will allow us to ensure the type safety.
|
||||||
*
|
*
|
||||||
* @param data Raw object.
|
* @param data Raw object.
|
||||||
* @return An object representing the size.
|
* @return An object representing the item props.
|
||||||
* @throws Will throw a TypeError if some property
|
* @throws Will throw a TypeError if some property
|
||||||
* is missing from the raw object or have an invalid type.
|
* is missing from the raw object or have an invalid type.
|
||||||
*/
|
*/
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { WithModuleProps, LinkedVisualConsoleProps } from "../types";
|
import {
|
||||||
|
WithModuleProps,
|
||||||
|
LinkedVisualConsoleProps,
|
||||||
|
UnknownObject
|
||||||
|
} from "../types";
|
||||||
|
|
||||||
import VisualConsoleItem, {
|
import VisualConsoleItem, {
|
||||||
VisualConsoleItemProps
|
VisualConsoleItemProps,
|
||||||
|
itemPropsDecoder
|
||||||
} from "../VisualConsoleItem";
|
} from "../VisualConsoleItem";
|
||||||
|
|
||||||
export type StaticGraphProps = {
|
export type StaticGraphProps = {
|
||||||
@ -10,6 +15,44 @@ export type StaticGraphProps = {
|
|||||||
} & VisualConsoleItemProps &
|
} & VisualConsoleItemProps &
|
||||||
(WithModuleProps | LinkedVisualConsoleProps);
|
(WithModuleProps | LinkedVisualConsoleProps);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract a valid enum value from a raw unknown value.
|
||||||
|
* @param showLastValueTooltip Raw value.
|
||||||
|
*/
|
||||||
|
const parseShowLastValueTooltip = (showLastValueTooltip: any) => {
|
||||||
|
switch (showLastValueTooltip) {
|
||||||
|
case "default":
|
||||||
|
case "enabled":
|
||||||
|
case "disabled":
|
||||||
|
return showLastValueTooltip;
|
||||||
|
default:
|
||||||
|
return "default";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a valid typed object from a raw object.
|
||||||
|
* This will allow us to ensure the type safety.
|
||||||
|
*
|
||||||
|
* @param data Raw object.
|
||||||
|
* @return An object representing the static graph props.
|
||||||
|
* @throws Will throw a TypeError if some property
|
||||||
|
* is missing from the raw object or have an invalid type.
|
||||||
|
*/
|
||||||
|
export function staticGraphPropsDecoder(
|
||||||
|
data: UnknownObject
|
||||||
|
): StaticGraphProps | never {
|
||||||
|
if (typeof data.imageSrc !== "string" || data.imageSrc.length === 0) {
|
||||||
|
throw new TypeError("invalid image src.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
imageSrc: data.imageSrc,
|
||||||
|
showLastValueTooltip: parseShowLastValueTooltip(data.showLastValueTooltip),
|
||||||
|
...itemPropsDecoder(data) // Object spread. It will merge the properties of the two objects.
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export default class StaticGraph extends VisualConsoleItem<StaticGraphProps> {
|
export default class StaticGraph extends VisualConsoleItem<StaticGraphProps> {
|
||||||
createDomElement(): HTMLElement {
|
createDomElement(): HTMLElement {
|
||||||
const img: HTMLImageElement = document.createElement("img");
|
const img: HTMLImageElement = document.createElement("img");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user