mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-30 17:25:26 +02:00
Merge branch 'visual-console-refactor' of https://brutus.artica.lan:8081/artica/pandorafms into visual-console-refactor
Former-commit-id: 770dec9dd08f8c6cb526c38b35d52a7b825e9b62
This commit is contained in:
commit
2bcc05806a
@ -18,6 +18,7 @@ import SimpleValue, { simpleValuePropsDecoder } from "./items/SimpleValue";
|
|||||||
import EventsHistory, {
|
import EventsHistory, {
|
||||||
eventsHistoryPropsDecoder
|
eventsHistoryPropsDecoder
|
||||||
} from "./items/EventsHistory";
|
} from "./items/EventsHistory";
|
||||||
|
import Percentile, { percentilePropsDecoder } from "./items/Percentile";
|
||||||
|
|
||||||
// Base properties.
|
// Base properties.
|
||||||
export interface VisualConsoleProps extends Size {
|
export interface VisualConsoleProps extends Size {
|
||||||
@ -90,7 +91,9 @@ function itemInstanceFrom(data: UnknownObject) {
|
|||||||
return new SimpleValue(simpleValuePropsDecoder(data));
|
return new SimpleValue(simpleValuePropsDecoder(data));
|
||||||
case ItemType.PERCENTILE_BAR:
|
case ItemType.PERCENTILE_BAR:
|
||||||
case ItemType.PERCENTILE_BUBBLE:
|
case ItemType.PERCENTILE_BUBBLE:
|
||||||
throw new TypeError("item not found");
|
case ItemType.CIRCULAR_PROGRESS_BAR:
|
||||||
|
case ItemType.CIRCULAR_INTERIOR_PROGRESS_BAR:
|
||||||
|
return new Percentile(percentilePropsDecoder(data));
|
||||||
case ItemType.LABEL:
|
case ItemType.LABEL:
|
||||||
return new Label(labelPropsDecoder(data));
|
return new Label(labelPropsDecoder(data));
|
||||||
case ItemType.ICON:
|
case ItemType.ICON:
|
||||||
@ -105,8 +108,6 @@ function itemInstanceFrom(data: UnknownObject) {
|
|||||||
return new Line(linePropsDecoder(data));
|
return new Line(linePropsDecoder(data));
|
||||||
case ItemType.AUTO_SLA_GRAPH:
|
case ItemType.AUTO_SLA_GRAPH:
|
||||||
return new EventsHistory(eventsHistoryPropsDecoder(data));
|
return new EventsHistory(eventsHistoryPropsDecoder(data));
|
||||||
case ItemType.CIRCULAR_PROGRESS_BAR:
|
|
||||||
case ItemType.CIRCULAR_INTERIOR_PROGRESS_BAR:
|
|
||||||
case ItemType.DONUT_GRAPH:
|
case ItemType.DONUT_GRAPH:
|
||||||
case ItemType.BARS_GRAPH:
|
case ItemType.BARS_GRAPH:
|
||||||
throw new TypeError("item not found");
|
throw new TypeError("item not found");
|
||||||
|
@ -25,7 +25,7 @@ export type EventsHistoryProps = {
|
|||||||
* 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 simple value props.
|
* @return An object representing the events history 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.
|
||||||
*/
|
*/
|
||||||
|
109
visual_console/src/items/Percentile.ts
Normal file
109
visual_console/src/items/Percentile.ts
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
import {
|
||||||
|
LinkedVisualConsoleProps,
|
||||||
|
UnknownObject,
|
||||||
|
WithModuleProps
|
||||||
|
} from "../types";
|
||||||
|
import {
|
||||||
|
linkedVCPropsDecoder,
|
||||||
|
modulePropsDecoder,
|
||||||
|
decodeBase64,
|
||||||
|
stringIsEmpty,
|
||||||
|
notEmptyStringOr
|
||||||
|
} from "../lib";
|
||||||
|
import Item, { ItemType, ItemProps, itemBasePropsDecoder } from "../Item";
|
||||||
|
|
||||||
|
export type PercentileProps = {
|
||||||
|
type: ItemType.PERCENTILE_BAR;
|
||||||
|
percentileType:
|
||||||
|
| "progress-bar"
|
||||||
|
| "bubble"
|
||||||
|
| "circular-progress-bar"
|
||||||
|
| "circular-progress-bar-alt";
|
||||||
|
valueType: "percent" | "value";
|
||||||
|
value: string | null;
|
||||||
|
color: string | null;
|
||||||
|
labelColor: string | null;
|
||||||
|
html: string;
|
||||||
|
} & ItemProps &
|
||||||
|
WithModuleProps &
|
||||||
|
LinkedVisualConsoleProps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract a valid enum value from a raw type value.
|
||||||
|
* @param type Raw value.
|
||||||
|
*/
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
function extractPercentileType(type: any): PercentileProps["percentileType"] {
|
||||||
|
switch (type) {
|
||||||
|
case "progress-bar":
|
||||||
|
case "bubble":
|
||||||
|
case "circular-progress-bar":
|
||||||
|
case "circular-progress-bar-alt":
|
||||||
|
return type;
|
||||||
|
default:
|
||||||
|
case ItemType.PERCENTILE_BAR:
|
||||||
|
return "progress-bar";
|
||||||
|
case ItemType.PERCENTILE_BUBBLE:
|
||||||
|
return "bubble";
|
||||||
|
case ItemType.CIRCULAR_PROGRESS_BAR:
|
||||||
|
return "circular-progress-bar";
|
||||||
|
case ItemType.CIRCULAR_INTERIOR_PROGRESS_BAR:
|
||||||
|
return "circular-progress-bar-alt";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract a valid enum value from a raw value type value.
|
||||||
|
* @param type Raw value.
|
||||||
|
*/
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
function extractValueType(valueType: any): PercentileProps["valueType"] {
|
||||||
|
switch (valueType) {
|
||||||
|
case "percent":
|
||||||
|
case "value":
|
||||||
|
return valueType;
|
||||||
|
default:
|
||||||
|
return "percent";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 percentile props.
|
||||||
|
* @throws Will throw a TypeError if some property
|
||||||
|
* is missing from the raw object or have an invalid type.
|
||||||
|
*/
|
||||||
|
export function percentilePropsDecoder(
|
||||||
|
data: UnknownObject
|
||||||
|
): PercentileProps | never {
|
||||||
|
if (stringIsEmpty(data.html) || stringIsEmpty(data.encodedHtml)) {
|
||||||
|
throw new TypeError("missing html content.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...itemBasePropsDecoder(data), // Object spread. It will merge the properties of the two objects.
|
||||||
|
type: ItemType.PERCENTILE_BAR,
|
||||||
|
percentileType: extractPercentileType(data.type),
|
||||||
|
valueType: extractValueType(data.valueType),
|
||||||
|
value: notEmptyStringOr(data.value, null),
|
||||||
|
color: notEmptyStringOr(data.color, null),
|
||||||
|
labelColor: notEmptyStringOr(data.labelColor, null),
|
||||||
|
html: !stringIsEmpty(data.html)
|
||||||
|
? data.html
|
||||||
|
: decodeBase64(data.encodedHtml),
|
||||||
|
...modulePropsDecoder(data), // Object spread. It will merge the properties of the two objects.
|
||||||
|
...linkedVCPropsDecoder(data) // Object spread. It will merge the properties of the two objects.
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Percentile extends Item<PercentileProps> {
|
||||||
|
public createDomElement(): HTMLElement {
|
||||||
|
const element = document.createElement("div");
|
||||||
|
element.innerHTML = this.props.html;
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user