mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-30 09:15:15 +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.
|
||||
*
|
||||
* @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
|
||||
* 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, {
|
||||
VisualConsoleItemProps
|
||||
VisualConsoleItemProps,
|
||||
itemPropsDecoder
|
||||
} from "../VisualConsoleItem";
|
||||
|
||||
export type StaticGraphProps = {
|
||||
@ -10,6 +15,44 @@ export type StaticGraphProps = {
|
||||
} & VisualConsoleItemProps &
|
||||
(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> {
|
||||
createDomElement(): HTMLElement {
|
||||
const img: HTMLImageElement = document.createElement("img");
|
||||
|
Loading…
x
Reference in New Issue
Block a user