ui: Replace moment with date-fns. (#460)

This commit is contained in:
Bernd Storath
2024-07-22 11:16:08 +02:00
committed by GitHub
parent 262f51da3f
commit 2a8e49bf8d
17 changed files with 65 additions and 65 deletions

View File

@ -1,6 +1,6 @@
import { useState } from "react";
import moment from "moment";
import { format } from "date-fns";
import { JSONTree as JSONTreeOriginal } from "react-json-tree";
import fileDownload from "js-file-download";
@ -25,7 +25,7 @@ function LogTable(props: IProps) {
const onDrawerOpen = (time: { seconds: number } | undefined, body: string) => {
const ts = new Date(0);
ts.setUTCSeconds(time!.seconds);
const drawerTitle = moment(ts).format("YYYY-MM-DD HH:mm:ss");
const drawerTitle = format(ts, "YYYY-MM-DD HH:mm:ss");
return () => {
setBody(body);
@ -106,7 +106,7 @@ function LogTable(props: IProps) {
render: (text, obj) => {
const ts = new Date(0);
ts.setUTCSeconds(obj.time!.seconds);
return moment(ts).format("YYYY-MM-DD HH:mm:ss");
return format(ts, "YYYY-MM-DD HH:mm:ss");
},
},
{

View File

@ -2,7 +2,6 @@ import { Card } from "antd";
import type { TimeUnit } from "chart.js";
import { Bar } from "react-chartjs-2";
import moment from "moment";
import palette from "google-palette";
import type { Metric } from "@chirpstack/chirpstack-api-grpc-web/common/common_pb";
@ -52,7 +51,7 @@ function MetricBar(props: IProps) {
backgroundColor: string;
}[];
} = {
labels: props.metric.getTimestampsList().map(v => moment(v.toDate()).valueOf()),
labels: props.metric.getTimestampsList().map(v => v.toDate().getTime()),
datasets: [],
};

View File

@ -2,7 +2,6 @@ import { Card } from "antd";
import type { TimeUnit } from "chart.js";
import { Line } from "react-chartjs-2";
import moment from "moment";
import palette from "google-palette";
import type { Metric } from "@chirpstack/chirpstack-api-grpc-web/common/common_pb";
@ -54,7 +53,7 @@ function MetricChart(props: IProps) {
let prevValue = 0;
const data = {
labels: props.metric.getTimestampsList().map(v => moment(v.toDate()).valueOf()),
labels: props.metric.getTimestampsList().map(v => v.toDate().getTime()),
datasets: props.metric
.getDatasetsList()
.sort((a, b) => a.getLabel().localeCompare(b.getLabel()))

View File

@ -5,7 +5,6 @@ import { Card } from "antd";
import { color } from "chart.js/helpers";
import type { TimeUnit } from "chart.js";
import { Chart } from "react-chartjs-2";
import moment from "moment";
import type { Metric } from "@chirpstack/chirpstack-api-grpc-web/common/common_pb";
import { Aggregation } from "@chirpstack/chirpstack-api-grpc-web/common/common_pb";
@ -44,7 +43,7 @@ function MetricHeatmap(props: IProps) {
unit: unit,
},
offset: true,
labels: props.metric.getTimestampsList().map(v => moment(v.toDate().valueOf())),
labels: props.metric.getTimestampsList().map(v => v.toDate().getTime()),
grid: {
display: false,
},
@ -127,7 +126,7 @@ function MetricHeatmap(props: IProps) {
}
data.datasets[0].data.push({
x: moment(tsList[i].toDate()).valueOf(),
x: tsList[i].toDate().getTime(),
y: ds.getLabel(),
v: v,
});