Skip to content

Commit

Permalink
Refactor Dashboard components for improved code consistency and reada…
Browse files Browse the repository at this point in the history
…bility
  • Loading branch information
simlarsen committed Nov 29, 2024
1 parent b8fc933 commit c4256a0
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 185 deletions.
2 changes: 0 additions & 2 deletions Common/Types/BrandColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,3 @@ export const ChartColors: Color[] = [
Cyan500,
Gray500,
];


53 changes: 26 additions & 27 deletions Common/Types/ColorSwatch.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
enum ColorSwatch {
Zinc = "zinc",
Neutra = "neutra",
Stone = "stone",
Slate = "slate",
Purple = "purple",
Pink = "pink",
Red = "red",
Orange = "orange",
Yellow = "yellow",
Green = "green",
Teal = "teal",
Cyan = "cyan",
Gray = "gray",
Moroon = "moroon",
Blue = "blue",
Indigo = "indigo",
Amber = "amber",
Lime = "lime",
Emerald = "emerald",
Sky = "sky",
Violet = "violet",
Fuchsia = "fuchsia",
Rose = "rose",
}


export default ColorSwatch;
Zinc = "zinc",
Neutra = "neutra",
Stone = "stone",
Slate = "slate",
Purple = "purple",
Pink = "pink",
Red = "red",
Orange = "orange",
Yellow = "yellow",
Green = "green",
Teal = "teal",
Cyan = "cyan",
Gray = "gray",
Moroon = "moroon",
Blue = "blue",
Indigo = "indigo",
Amber = "amber",
Lime = "lime",
Emerald = "emerald",
Sky = "sky",
Violet = "violet",
Fuchsia = "fuchsia",
Rose = "rose",
}

export default ColorSwatch;
4 changes: 2 additions & 2 deletions Dashboard/src/Components/Dashboard/Canvas/ArgumentsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import MetricNameAndUnit from "../../Metrics/Types/MetricNameAndUnit";
import { GetReactElementFunction } from "Common/UI/Types/FunctionTypes";

export interface ComponentProps {
//eslint-disable react/no-unused-prop-types
// eslint-disable-next-line react/no-unused-prop-types
metrics: {
metricNameAndUnits: Array<MetricNameAndUnit>;
telemetryAttributes: string[];
Expand Down Expand Up @@ -75,7 +75,7 @@ const ArgumentsForm: FunctionComponent<ComponentProps> = (
value: FormValues<JSONObject>,
componentProps: CustomElementProps,
) => ReactElement) => {
//eslint-disable react/display-name
// eslint-disable-next-line react/display-name
return (
value: FormValues<JSONObject>,
componentProps: CustomElementProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface DashboardBaseComponentProps {
dashboardCanvasWidthInPx: number;
dashboardCanvasHeightInPx: number;
dashboardViewConfig: DashboardViewConfig;
dashboardStartAndEndDate: DashboardStartAndEndDate;
dashboardStartAndEndDate: DashboardStartAndEndDate;
metricNameAndUnits: Array<MetricNameAndUnit>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ export interface ComponentProps extends DashboardBaseComponentProps {
const DashboardChartComponentElement: FunctionComponent<ComponentProps> = (
props: ComponentProps,
): ReactElement => {

const [metricResults, setMetricResults] = React.useState<Array<AggregatedResult>>([]);
const [metricResults, setMetricResults] = React.useState<
Array<AggregatedResult>
>([]);
const [error, setError] = React.useState<string | null>(null);
const [isLoading, setIsLoading] = React.useState<boolean>(true);

const metricViewData: MetricViewData = {
queryConfigs: props.component.arguments.metricQueryConfig ? [props.component.arguments.metricQueryConfig] : [],
startAndEndDate: DashboardStartAndEndDateUtil.getStartAndEndDate(props.dashboardStartAndEndDate),
formulaConfigs: []
}
queryConfigs: props.component.arguments.metricQueryConfig
? [props.component.arguments.metricQueryConfig]
: [],
startAndEndDate: DashboardStartAndEndDateUtil.getStartAndEndDate(
props.dashboardStartAndEndDate,
),
formulaConfigs: [],
};

const fetchAggregatedResults: PromiseVoidFunction =
async (): Promise<void> => {


setIsLoading(true);

if (
Expand Down Expand Up @@ -66,17 +69,21 @@ const DashboardChartComponentElement: FunctionComponent<ComponentProps> = (

useEffect(() => {
fetchAggregatedResults();
}, [props.dashboardStartAndEndDate, props.component.arguments.metricQueryConfig, props.metricNameAndUnits]);



return <div>
<MetricCharts
metricResults={metricResults}
metricNamesAndUnits={props.metricNameAndUnits}
metricViewData={metricViewData}
/>
</div>;
}, [
props.dashboardStartAndEndDate,
props.component.arguments.metricQueryConfig,
props.metricNameAndUnits,
]);

return (
<div>
<MetricCharts
metricResults={metricResults}
metricNamesAndUnits={props.metricNameAndUnits}
metricViewData={metricViewData}
/>
</div>
);
};

export default DashboardChartComponentElement;
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,47 @@ import DashboardStartAndEndDateRange from "../Types/DashboardStartAndEndDateRang
import OneUptimeDate from "Common/Types/Date";
import IconProp from "Common/Types/Icon/IconProp";
import { GetReactElementFunction } from "Common/UI/Types/FunctionTypes";
import HeaderAlert, { HeaderAlertType } from "Common/UI/Components/HeaderAlert/HeaderAlert";
import HeaderAlert, {
HeaderAlertType,
} from "Common/UI/Components/HeaderAlert/HeaderAlert";
import ColorSwatch from "Common/Types/ColorSwatch";

export interface ComponentProps {
dashboardStartAndEndDate: DashboardStartAndEndDate;
onClick: () => void;
dashboardStartAndEndDate: DashboardStartAndEndDate;
onClick: () => void;
}

const DashboardStartAndEndDateView: FunctionComponent<ComponentProps> = (
props: ComponentProps,
props: ComponentProps,
): ReactElement => {
const isCustomRange: boolean =
props.dashboardStartAndEndDate.range ===
DashboardStartAndEndDateRange.CUSTOM;

const getContent: GetReactElementFunction = (): ReactElement => {

const title: string = isCustomRange ? `${OneUptimeDate.getDateAsLocalFormattedString(
props.dashboardStartAndEndDate.startAndEndDate?.startValue ||
const isCustomRange: boolean =
props.dashboardStartAndEndDate.range ===
DashboardStartAndEndDateRange.CUSTOM;

const getContent: GetReactElementFunction = (): ReactElement => {
const title: string = isCustomRange
? `${OneUptimeDate.getDateAsLocalFormattedString(
props.dashboardStartAndEndDate.startAndEndDate?.startValue ||
OneUptimeDate.getCurrentDate(),
)} - ${OneUptimeDate.getDateAsLocalFormattedString(
props.dashboardStartAndEndDate.startAndEndDate?.endValue ||
props.dashboardStartAndEndDate.startAndEndDate?.endValue ||
OneUptimeDate.getCurrentDate(),
)}` : props.dashboardStartAndEndDate.range

return (
<HeaderAlert
icon={IconProp.Clock}
onClick={props.onClick}
title={title}
alertType={HeaderAlertType.INFO}
colorSwatch={ColorSwatch.Blue}
tooltip="Click to change the date and time range of data on this dashboard."
/>
);

};
)}`
: props.dashboardStartAndEndDate.range;

return (
<div>
{getContent()}
</div>
);
<HeaderAlert
icon={IconProp.Clock}
onClick={props.onClick}
title={title}
alertType={HeaderAlertType.INFO}
colorSwatch={ColorSwatch.Blue}
tooltip="Click to change the date and time range of data on this dashboard."
/>
);
};

return <div>{getContent()}</div>;
};

export default DashboardStartAndEndDateView;
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ const DashboardToolbar: FunctionComponent<ComponentProps> = (
</div>
{!props.isSaving && (
<div className="flex">
<div className="mt-2">
<div className="mt-2">
<DashboardStartAndEndDateView
dashboardStartAndEndDate={props.startAndEndDate}
onClick={() => {
setTempStartAndEndDate(props.startAndEndDate);
setShowTimeSelectModal(true);
}}
/>
</div>

</div>

{isEditMode ? (
<MoreMenu menuIcon={IconProp.Add} text="Add Component">
Expand Down
Loading

0 comments on commit c4256a0

Please sign in to comment.