@deenruv/dashboard-widgets-plugin 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +58 -0
- package/dist/plugin-server/constants.d.ts +4 -0
- package/dist/plugin-server/constants.js +12 -0
- package/dist/plugin-server/controllers/admin-ui-controller.d.ts +4 -0
- package/dist/plugin-server/controllers/admin-ui-controller.js +46 -0
- package/dist/plugin-server/controllers/refresh-view-controller.d.ts +8 -0
- package/dist/plugin-server/controllers/refresh-view-controller.js +41 -0
- package/dist/plugin-server/index.d.ts +1 -0
- package/dist/plugin-server/index.js +17 -0
- package/dist/plugin-server/materialisedViewEntities/order_summary.d.ts +9 -0
- package/dist/plugin-server/materialisedViewEntities/order_summary.js +79 -0
- package/dist/plugin-server/materialisedViewEntities/orders_summary_with_state.d.ts +10 -0
- package/dist/plugin-server/materialisedViewEntities/orders_summary_with_state.js +79 -0
- package/dist/plugin-server/materialisedViewEntities/total_products.d.ts +7 -0
- package/dist/plugin-server/materialisedViewEntities/total_products.js +62 -0
- package/dist/plugin-server/materialisedViewEntities/total_products_with_state.d.ts +9 -0
- package/dist/plugin-server/materialisedViewEntities/total_products_with_state.js +62 -0
- package/dist/plugin-server/plugin.d.ts +6 -0
- package/dist/plugin-server/plugin.js +149 -0
- package/dist/plugin-server/raw-sql.d.ts +8 -0
- package/dist/plugin-server/raw-sql.js +48 -0
- package/dist/plugin-server/resolvers/admin.resolver.d.ts +47 -0
- package/dist/plugin-server/resolvers/admin.resolver.js +63 -0
- package/dist/plugin-server/services/metrics.service.d.ts +30 -0
- package/dist/plugin-server/services/metrics.service.js +272 -0
- package/dist/plugin-server/types.d.ts +20 -0
- package/dist/plugin-server/types.js +2 -0
- package/dist/plugin-server/utils.d.ts +1 -0
- package/dist/plugin-server/utils.js +12 -0
- package/dist/plugin-server/zeus/const.d.ts +6 -0
- package/dist/plugin-server/zeus/const.js +3675 -0
- package/dist/plugin-server/zeus/index.d.ts +18709 -0
- package/dist/plugin-server/zeus/index.js +1122 -0
- package/dist/plugin-server/zeus/typedDocumentNode.d.ts +3 -0
- package/dist/plugin-server/zeus/typedDocumentNode.js +16 -0
- package/dist/plugin-ui/components/CategoriesChartWidget/dashCaseToSpaces.d.ts +1 -0
- package/dist/plugin-ui/components/CategoriesChartWidget/dashCaseToSpaces.js +6 -0
- package/dist/plugin-ui/components/CategoriesChartWidget/index.d.ts +2 -0
- package/dist/plugin-ui/components/CategoriesChartWidget/index.js +100 -0
- package/dist/plugin-ui/components/LatestOrdersWidget/index.d.ts +4 -0
- package/dist/plugin-ui/components/LatestOrdersWidget/index.js +96 -0
- package/dist/plugin-ui/components/LatestOrdersWidget/paymentMethod.d.ts +6 -0
- package/dist/plugin-ui/components/LatestOrdersWidget/paymentMethod.js +7 -0
- package/dist/plugin-ui/components/OrdersWidget/CustomTooltip.d.ts +18 -0
- package/dist/plugin-ui/components/OrdersWidget/CustomTooltip.js +92 -0
- package/dist/plugin-ui/components/OrdersWidget/GroupBySelect.d.ts +8 -0
- package/dist/plugin-ui/components/OrdersWidget/GroupBySelect.js +17 -0
- package/dist/plugin-ui/components/OrdersWidget/MetricCustomDates.d.ts +9 -0
- package/dist/plugin-ui/components/OrdersWidget/MetricCustomDates.js +27 -0
- package/dist/plugin-ui/components/OrdersWidget/MetricTypeSelect.d.ts +9 -0
- package/dist/plugin-ui/components/OrdersWidget/MetricTypeSelect.js +17 -0
- package/dist/plugin-ui/components/OrdersWidget/OrdersChart.d.ts +24 -0
- package/dist/plugin-ui/components/OrdersWidget/OrdersChart.js +46 -0
- package/dist/plugin-ui/components/OrdersWidget/OrdersSummaryTile.d.ts +13 -0
- package/dist/plugin-ui/components/OrdersWidget/OrdersSummaryTile.js +115 -0
- package/dist/plugin-ui/components/OrdersWidget/ProductSelector.d.ts +17 -0
- package/dist/plugin-ui/components/OrdersWidget/ProductSelector.js +37 -0
- package/dist/plugin-ui/components/OrdersWidget/RatioBadge.d.ts +6 -0
- package/dist/plugin-ui/components/OrdersWidget/RatioBadge.js +12 -0
- package/dist/plugin-ui/components/OrdersWidget/index.d.ts +2 -0
- package/dist/plugin-ui/components/OrdersWidget/index.js +229 -0
- package/dist/plugin-ui/components/ProductsChartWidget/CustomBarChartTooltip.d.ts +9 -0
- package/dist/plugin-ui/components/ProductsChartWidget/CustomBarChartTooltip.js +14 -0
- package/dist/plugin-ui/components/ProductsChartWidget/index.d.ts +2 -0
- package/dist/plugin-ui/components/ProductsChartWidget/index.js +116 -0
- package/dist/plugin-ui/components/index.d.ts +4 -0
- package/dist/plugin-ui/components/index.js +4 -0
- package/dist/plugin-ui/components/shared/EmptyData.d.ts +6 -0
- package/dist/plugin-ui/components/shared/EmptyData.js +8 -0
- package/dist/plugin-ui/components/shared/MetricsRangeSelect.d.ts +10 -0
- package/dist/plugin-ui/components/shared/MetricsRangeSelect.js +26 -0
- package/dist/plugin-ui/components/shared/OrderStatesSelect.d.ts +8 -0
- package/dist/plugin-ui/components/shared/OrderStatesSelect.js +28 -0
- package/dist/plugin-ui/components/shared/PeriodSelect.d.ts +20 -0
- package/dist/plugin-ui/components/shared/PeriodSelect.js +56 -0
- package/dist/plugin-ui/components/shared/colors.d.ts +1 -0
- package/dist/plugin-ui/components/shared/colors.js +1 -0
- package/dist/plugin-ui/components/shared/index.d.ts +3 -0
- package/dist/plugin-ui/components/shared/index.js +3 -0
- package/dist/plugin-ui/graphql/index.d.ts +2 -0
- package/dist/plugin-ui/graphql/index.js +2 -0
- package/dist/plugin-ui/graphql/queries.d.ts +425 -0
- package/dist/plugin-ui/graphql/queries.js +182 -0
- package/dist/plugin-ui/graphql/selectors.d.ts +19 -0
- package/dist/plugin-ui/graphql/selectors.js +21 -0
- package/dist/plugin-ui/index.d.ts +9 -0
- package/dist/plugin-ui/index.js +21 -0
- package/dist/plugin-ui/locales/en/index.d.ts +72 -0
- package/dist/plugin-ui/locales/en/index.js +2 -0
- package/dist/plugin-ui/locales/en/test.json +71 -0
- package/dist/plugin-ui/locales/pl/index.d.ts +71 -0
- package/dist/plugin-ui/locales/pl/index.js +2 -0
- package/dist/plugin-ui/locales/pl/test.json +70 -0
- package/dist/plugin-ui/tsconfig.json +18 -0
- package/dist/plugin-ui/types.d.ts +64 -0
- package/dist/plugin-ui/types.js +14 -0
- package/dist/plugin-ui/utils.d.ts +70 -0
- package/dist/plugin-ui/utils.js +366 -0
- package/dist/plugin-ui/widgets.d.ts +15 -0
- package/dist/plugin-ui/widgets.js +36 -0
- package/dist/plugin-ui/zeus/const.d.ts +6 -0
- package/dist/plugin-ui/zeus/const.js +3672 -0
- package/dist/plugin-ui/zeus/index.d.ts +18709 -0
- package/dist/plugin-ui/zeus/index.js +1114 -0
- package/dist/plugin-ui/zeus/typedDocumentNode.d.ts +3 -0
- package/dist/plugin-ui/zeus/typedDocumentNode.js +9 -0
- package/package.json +52 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Label, priceFormatter, Switch, useLazyQuery, useTranslation, } from "@deenruv/react-ui-devkit";
|
|
2
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { OrderSummaryMetricsQuery } from "../../graphql";
|
|
4
|
+
import { CurrencyCode } from "../../zeus";
|
|
5
|
+
import { giveSummaryMetricsRatio } from "../../utils";
|
|
6
|
+
import { RatioBadge } from "./RatioBadge";
|
|
7
|
+
export const OrdersSummaryTile = ({ dateRange, orderStates, net, setNet, }) => {
|
|
8
|
+
const { t } = useTranslation("dashboard-widgets-plugin");
|
|
9
|
+
const [getOrdersSummaryMetric] = useLazyQuery(OrderSummaryMetricsQuery);
|
|
10
|
+
const [metricLoading, setMetricLoading] = useState(false);
|
|
11
|
+
const [ordersSummaryMetric, setOrdersSummaryMetrics] = useState();
|
|
12
|
+
const getOrders = async ({ prevRange, range, refresh = false, _orderStates, }) => {
|
|
13
|
+
try {
|
|
14
|
+
setMetricLoading(true);
|
|
15
|
+
const response = await getOrdersSummaryMetric({
|
|
16
|
+
prevInput: {
|
|
17
|
+
range: prevRange,
|
|
18
|
+
orderStates: _orderStates,
|
|
19
|
+
},
|
|
20
|
+
input: {
|
|
21
|
+
range,
|
|
22
|
+
orderStates: _orderStates,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
const metric = response.orderSummaryMetric.data;
|
|
26
|
+
const prevMetric = response.prevOrderSummaryMetric.data;
|
|
27
|
+
const prevRatio = giveSummaryMetricsRatio(metric, prevMetric);
|
|
28
|
+
setOrdersSummaryMetrics({
|
|
29
|
+
metric,
|
|
30
|
+
prevRatio,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
console.log(e);
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
setMetricLoading(false);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
getOrders({ ...dateRange, _orderStates: orderStates });
|
|
42
|
+
}, [dateRange, orderStates]);
|
|
43
|
+
const total = useMemo(() => {
|
|
44
|
+
if (ordersSummaryMetric && net) {
|
|
45
|
+
return ordersSummaryMetric.metric.total;
|
|
46
|
+
}
|
|
47
|
+
else if (ordersSummaryMetric) {
|
|
48
|
+
return ordersSummaryMetric.metric.totalWithTax;
|
|
49
|
+
}
|
|
50
|
+
return 0;
|
|
51
|
+
}, [net, ordersSummaryMetric]);
|
|
52
|
+
const totalRatio = useMemo(() => {
|
|
53
|
+
if (ordersSummaryMetric && net) {
|
|
54
|
+
return ordersSummaryMetric.prevRatio.total;
|
|
55
|
+
}
|
|
56
|
+
else if (ordersSummaryMetric) {
|
|
57
|
+
return ordersSummaryMetric.prevRatio.totalWithTax;
|
|
58
|
+
}
|
|
59
|
+
return 0;
|
|
60
|
+
}, [net, ordersSummaryMetric]);
|
|
61
|
+
const average = useMemo(() => {
|
|
62
|
+
if (ordersSummaryMetric && net) {
|
|
63
|
+
return ordersSummaryMetric.metric.averageOrderValue;
|
|
64
|
+
}
|
|
65
|
+
else if (ordersSummaryMetric) {
|
|
66
|
+
return ordersSummaryMetric.metric.averageOrderValueWithTax;
|
|
67
|
+
}
|
|
68
|
+
return 0;
|
|
69
|
+
}, [net, ordersSummaryMetric]);
|
|
70
|
+
const averageRatio = useMemo(() => {
|
|
71
|
+
if (ordersSummaryMetric && net) {
|
|
72
|
+
return ordersSummaryMetric.prevRatio.averageOrderValue;
|
|
73
|
+
}
|
|
74
|
+
else if (ordersSummaryMetric) {
|
|
75
|
+
return ordersSummaryMetric.prevRatio.averageOrderValueWithTax;
|
|
76
|
+
}
|
|
77
|
+
return 0;
|
|
78
|
+
}, [net, ordersSummaryMetric]);
|
|
79
|
+
return (React.createElement("div", { className: "px-6" },
|
|
80
|
+
React.createElement("div", { className: "flex items-center justify-between py-4" },
|
|
81
|
+
React.createElement("h2", null, t("summary")),
|
|
82
|
+
React.createElement("div", { className: "flex items-center gap-2" },
|
|
83
|
+
React.createElement(Label, { htmlFor: "net" }, net ? t("netSold") : t("grossSold")),
|
|
84
|
+
React.createElement(Switch, { id: "net", checked: net, onCheckedChange: (checked) => {
|
|
85
|
+
setNet(checked);
|
|
86
|
+
getOrders({
|
|
87
|
+
...dateRange,
|
|
88
|
+
refresh: true,
|
|
89
|
+
_orderStates: orderStates,
|
|
90
|
+
prevRange: dateRange.prevRange,
|
|
91
|
+
});
|
|
92
|
+
} }))),
|
|
93
|
+
React.createElement("div", { className: "bg-muted/20 grid grid-cols-2 rounded-md border lg:grid-cols-4" },
|
|
94
|
+
React.createElement("div", null,
|
|
95
|
+
React.createElement("div", { className: "border-r p-6 pb-1" },
|
|
96
|
+
React.createElement("div", { className: "flex flex-col-reverse justify-between gap-1 2xl:flex-row 2xl:items-center" },
|
|
97
|
+
React.createElement("h4", { className: "text-foreground/70 text-sm" }, net ? t("netSold") : t("grossSold")),
|
|
98
|
+
React.createElement(RatioBadge, { ratio: totalRatio })),
|
|
99
|
+
React.createElement("h3", { className: "flex items-end" }, priceFormatter(total || 0, ordersSummaryMetric?.metric?.currencyCode || CurrencyCode.PLN)))),
|
|
100
|
+
React.createElement("div", { className: "border-r p-6 " },
|
|
101
|
+
React.createElement("div", { className: "flex flex-col-reverse justify-between gap-1 2xl:flex-row 2xl:items-center" },
|
|
102
|
+
React.createElement("h4", { className: "text-foreground/70 text-sm" }, net ? t("averageNetSold") : t("averageGrossSold")),
|
|
103
|
+
React.createElement(RatioBadge, { ratio: averageRatio })),
|
|
104
|
+
React.createElement("h3", { className: "flex items-end" }, priceFormatter(average || 0, ordersSummaryMetric?.metric?.currencyCode || CurrencyCode.PLN))),
|
|
105
|
+
React.createElement("div", { className: "border-r border-t p-6 xl:border-t-0" },
|
|
106
|
+
React.createElement("div", { className: "flex flex-col-reverse justify-between gap-1 2xl:flex-row 2xl:items-center" },
|
|
107
|
+
React.createElement("h4", { className: "text-foreground/70 text-sm" }, t("orders")),
|
|
108
|
+
React.createElement(RatioBadge, { ratio: ordersSummaryMetric?.prevRatio.orderCount })),
|
|
109
|
+
React.createElement("h3", null, ordersSummaryMetric?.metric?.orderCount || 0)),
|
|
110
|
+
React.createElement("div", { className: "border-t p-6 xl:border-t-0" },
|
|
111
|
+
React.createElement("div", { className: "flex flex-col-reverse justify-between gap-1 2xl:flex-row 2xl:items-center" },
|
|
112
|
+
React.createElement("h4", { className: "text-foreground/70 text-sm" }, t("soldProducts")),
|
|
113
|
+
React.createElement(RatioBadge, { ratio: ordersSummaryMetric?.prevRatio.productCount })),
|
|
114
|
+
React.createElement("h3", null, ordersSummaryMetric?.metric?.productCount || 0)))));
|
|
115
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ChartMetricType } from "../../zeus";
|
|
3
|
+
interface ProductSelectProps {
|
|
4
|
+
metricType: ChartMetricType;
|
|
5
|
+
selectedAvailableProducts: {
|
|
6
|
+
id: string;
|
|
7
|
+
color: string;
|
|
8
|
+
}[];
|
|
9
|
+
allAvailableProducts: {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}[];
|
|
13
|
+
onSelectedAvailableProductsChange: (id: string) => void;
|
|
14
|
+
clearSelectedProducts: () => void;
|
|
15
|
+
}
|
|
16
|
+
export declare const ProductSelector: React.FC<ProductSelectProps>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Button, cn, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Popover, PopoverContent, PopoverTrigger, useTranslation, } from "@deenruv/react-ui-devkit";
|
|
3
|
+
import { Check, ChevronsUpDown } from "lucide-react";
|
|
4
|
+
import { sortBySelected } from "../../utils";
|
|
5
|
+
export const ProductSelector = ({ metricType, allAvailableProducts, selectedAvailableProducts, onSelectedAvailableProductsChange, clearSelectedProducts, }) => {
|
|
6
|
+
const [popoverOpen, setPopoverOpen] = useState(false);
|
|
7
|
+
const { t } = useTranslation("dashboard-widgets-plugin");
|
|
8
|
+
return (React.createElement(Popover, { open: popoverOpen, onOpenChange: setPopoverOpen },
|
|
9
|
+
React.createElement(PopoverTrigger, { asChild: true },
|
|
10
|
+
React.createElement(Button, { variant: "outline", role: "combobox", className: "h-[30px] w-full max-w-[240px] justify-between py-0" },
|
|
11
|
+
selectedAvailableProducts.length
|
|
12
|
+
? `${t("selectedProducts")} (${selectedAvailableProducts.length})`
|
|
13
|
+
: t("selectProducts"),
|
|
14
|
+
React.createElement(ChevronsUpDown, { size: 16, className: "opacity-50" }))),
|
|
15
|
+
React.createElement(PopoverContent, { className: "w-max p-0" },
|
|
16
|
+
React.createElement(Command, null,
|
|
17
|
+
React.createElement("div", { className: "relative" },
|
|
18
|
+
React.createElement(CommandInput, { className: "border-none", placeholder: t("searchProducts") }),
|
|
19
|
+
selectedAvailableProducts.length ? (React.createElement(Button, { onClick: clearSelectedProducts, variant: "ghost", size: "sm", className: "text-primary absolute right-1 top-1/2 -translate-y-1/2" }, t("clearSelected"))) : null),
|
|
20
|
+
React.createElement(CommandList, null,
|
|
21
|
+
React.createElement(CommandEmpty, null,
|
|
22
|
+
" ",
|
|
23
|
+
t("noProductsFound")),
|
|
24
|
+
React.createElement(CommandGroup, null, allAvailableProducts
|
|
25
|
+
.sort(sortBySelected(selectedAvailableProducts.map((p) => p.id)))
|
|
26
|
+
.map((product) => (React.createElement(CommandItem, { key: product.id, value: `${product.name} ${product.id}`, onSelect: () => onSelectedAvailableProductsChange(product.id) },
|
|
27
|
+
React.createElement("div", { className: "flex w-full cursor-pointer justify-between gap-2" },
|
|
28
|
+
React.createElement("span", { className: "shrink-0" }, product.name),
|
|
29
|
+
React.createElement("div", { className: "flex" },
|
|
30
|
+
React.createElement("span", { className: "shrink-0 pr-1 opacity-50" }, `(variant ID: ${product.id})`),
|
|
31
|
+
" ",
|
|
32
|
+
React.createElement(Check, { style: {
|
|
33
|
+
color: selectedAvailableProducts.find((p) => p.id === product.id)?.color ?? "",
|
|
34
|
+
}, className: cn("ml-auto", selectedAvailableProducts.some((p) => p.id === product.id)
|
|
35
|
+
? "opacity-100"
|
|
36
|
+
: "opacity-0") }))))))))))));
|
|
37
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { cn } from "@deenruv/react-ui-devkit";
|
|
2
|
+
import { TrendingDown, TrendingUp } from "lucide-react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
export const RatioBadge = ({ ratio: _ratio }) => {
|
|
5
|
+
const ratio = _ratio && _ratio > 0 ? _ratio : 0;
|
|
6
|
+
return (React.createElement("div", { className: cn("text-[0.75rem] w-max flex gap-1 items-center p-1 rounded-sm text-white dark:text-foreground", {
|
|
7
|
+
"bg-[#006600] dark:bg-[#032513]": ratio > 0,
|
|
8
|
+
"bg-[#990000] dark:bg-[#250303]": ratio < 0,
|
|
9
|
+
}) },
|
|
10
|
+
React.createElement("span", null, `${ratio}%`),
|
|
11
|
+
ratio > 0 ? React.createElement(TrendingUp, { size: 16 }) : React.createElement(TrendingDown, { size: 16 })));
|
|
12
|
+
};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { differenceInDays, endOfWeek, startOfWeek, subWeeks } from "date-fns";
|
|
3
|
+
import { Card, CardHeader, CardContent, usePluginStore, useLazyQuery, ORDER_STATE, Checkbox, cn, useTranslation, useSettings, useQuery, useLocalStorage, DraggableSelect, Button, } from "@deenruv/react-ui-devkit";
|
|
4
|
+
import { MetricsCustomDates } from "./MetricCustomDates";
|
|
5
|
+
import { MetricTypeSelect } from "./MetricTypeSelect";
|
|
6
|
+
import { OrdersChart } from "./OrdersChart";
|
|
7
|
+
import { MetricRangeType, ChartMetricType, MetricIntervalType, } from "../../zeus";
|
|
8
|
+
import { AdditionalOrderStatesQuery, ChartMetricQuery } from "../../graphql";
|
|
9
|
+
import { convertBackedDataToChartData, generateBrightRandomColor, getCustomIntervalDates, groupByPeriods, parseNameToCurrentLanguage, } from "../../utils";
|
|
10
|
+
import { MetricsRangeSelect } from "../shared/MetricsRangeSelect";
|
|
11
|
+
import { OrdersSummaryTile } from "./OrdersSummaryTile";
|
|
12
|
+
import { ProductSelector } from "./ProductSelector";
|
|
13
|
+
import { GroupBySelect } from "./GroupBySelect";
|
|
14
|
+
import { PanelsTopLeft } from "lucide-react";
|
|
15
|
+
export const OrdersWidget = () => {
|
|
16
|
+
const { t } = useTranslation("dashboard-widgets-plugin");
|
|
17
|
+
const [net, setNet] = useState(false);
|
|
18
|
+
const { data } = useQuery(AdditionalOrderStatesQuery);
|
|
19
|
+
const [fetchChartMetrics] = useLazyQuery(ChartMetricQuery);
|
|
20
|
+
const { language } = usePluginStore();
|
|
21
|
+
const channel = useSettings((state) => state.selectedChannel);
|
|
22
|
+
const [metricLoading, setMetricLoading] = useState(false);
|
|
23
|
+
const [shouldShowCompare, setShouldShowCompare] = useState(false);
|
|
24
|
+
const [groupBy, setGroupBy] = useState("day");
|
|
25
|
+
const [dateRange, setDateRange] = useState({
|
|
26
|
+
range: {
|
|
27
|
+
start: startOfWeek(new Date(), { weekStartsOn: 1 }),
|
|
28
|
+
end: endOfWeek(new Date(), { weekStartsOn: 1 }),
|
|
29
|
+
},
|
|
30
|
+
prevRange: {
|
|
31
|
+
start: startOfWeek(subWeeks(new Date(), 1), { weekStartsOn: 1 }),
|
|
32
|
+
end: endOfWeek(subWeeks(new Date(), 1), { weekStartsOn: 1 }),
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
const [metricRangeTypeSelectValue, setMetricRangeTypeSelectValue] = useLocalStorage("orders-metric-range", MetricRangeType.Today);
|
|
36
|
+
const [metricType, setMetricType] = useState(ChartMetricType.OrderTotal);
|
|
37
|
+
const [betterMetrics, setBetterMetrics] = useState({ data: [] });
|
|
38
|
+
const [allAvailableProducts, setAllAvailableProducts] = useState([]);
|
|
39
|
+
const [selectedAvailableProducts, setSelectedAvailableProducts] = useState([]);
|
|
40
|
+
const [selectedOrderStates, setSelectedOrderStates] = useState([
|
|
41
|
+
"PaymentSettled",
|
|
42
|
+
"PartiallyShipped",
|
|
43
|
+
"Shipped",
|
|
44
|
+
"PartiallyDelivered",
|
|
45
|
+
"Delivered",
|
|
46
|
+
]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!data)
|
|
49
|
+
return;
|
|
50
|
+
const selectedAdditionalOrderStates = data.additionalOrderStates.filter((state) => state.selectedByDefault);
|
|
51
|
+
setSelectedOrderStates((prev) => [
|
|
52
|
+
...prev,
|
|
53
|
+
...selectedAdditionalOrderStates
|
|
54
|
+
.map((state) => state.state)
|
|
55
|
+
.filter((state) => !prev.includes(state)),
|
|
56
|
+
]);
|
|
57
|
+
}, [data]);
|
|
58
|
+
const fetchData = useCallback(async () => {
|
|
59
|
+
try {
|
|
60
|
+
setMetricLoading(true);
|
|
61
|
+
let interval = MetricIntervalType.Day;
|
|
62
|
+
const { range, prevRange } = dateRange;
|
|
63
|
+
if (range.end) {
|
|
64
|
+
const diffrenceInDays = differenceInDays(range.end, range.start);
|
|
65
|
+
interval =
|
|
66
|
+
diffrenceInDays > 0
|
|
67
|
+
? MetricIntervalType.Day
|
|
68
|
+
: MetricIntervalType.Hour;
|
|
69
|
+
}
|
|
70
|
+
const { chartMetric, prevChartMetric } = await fetchChartMetrics({
|
|
71
|
+
prevInput: {
|
|
72
|
+
types: [metricType],
|
|
73
|
+
range: { ...prevRange },
|
|
74
|
+
orderStates: selectedOrderStates,
|
|
75
|
+
interval,
|
|
76
|
+
net,
|
|
77
|
+
},
|
|
78
|
+
input: {
|
|
79
|
+
types: [metricType],
|
|
80
|
+
range,
|
|
81
|
+
orderStates: selectedOrderStates,
|
|
82
|
+
interval,
|
|
83
|
+
net,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
if (chartMetric?.data?.length) {
|
|
87
|
+
const dataWithMappedEntries = chartMetric.data.map((data, i) => {
|
|
88
|
+
const prevEntries = prevChartMetric.data[i]?.entries ?? [];
|
|
89
|
+
return {
|
|
90
|
+
...data,
|
|
91
|
+
entries: convertBackedDataToChartData({
|
|
92
|
+
type: data.type,
|
|
93
|
+
entries: data.entries,
|
|
94
|
+
prevEntries,
|
|
95
|
+
interval,
|
|
96
|
+
language,
|
|
97
|
+
start: range.start,
|
|
98
|
+
end: range.end,
|
|
99
|
+
}),
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
if (metricType === ChartMetricType.OrderTotalProductsCount) {
|
|
103
|
+
const flatted = dataWithMappedEntries.map((d) => d.entries).flat();
|
|
104
|
+
const allAvailableProducts = flatted.reduce((acc, curr) => {
|
|
105
|
+
curr.additionalData?.forEach((product) => {
|
|
106
|
+
if (!acc.some((p) => p.id === product.id)) {
|
|
107
|
+
acc.push({ id: product.id, name: product.name });
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return acc;
|
|
111
|
+
}, []);
|
|
112
|
+
setAllAvailableProducts(allAvailableProducts);
|
|
113
|
+
}
|
|
114
|
+
setBetterMetrics({
|
|
115
|
+
data: dataWithMappedEntries,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
console.log(e);
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
setMetricLoading(false);
|
|
124
|
+
}
|
|
125
|
+
}, [dateRange, metricType, selectedOrderStates, net]);
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (metricRangeTypeSelectValue !== MetricRangeType.Custom)
|
|
128
|
+
setDateRange(getCustomIntervalDates(metricRangeTypeSelectValue));
|
|
129
|
+
if (metricType === ChartMetricType.OrderTotalProductsCount ||
|
|
130
|
+
metricRangeTypeSelectValue === MetricRangeType.Custom)
|
|
131
|
+
setShouldShowCompare(false);
|
|
132
|
+
if (metricType === ChartMetricType.OrderTotalProductsCount)
|
|
133
|
+
return;
|
|
134
|
+
setSelectedAvailableProducts([]);
|
|
135
|
+
}, [metricRangeTypeSelectValue, metricType]);
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
fetchData();
|
|
138
|
+
}, [
|
|
139
|
+
net,
|
|
140
|
+
channel,
|
|
141
|
+
dateRange,
|
|
142
|
+
metricType,
|
|
143
|
+
selectedOrderStates,
|
|
144
|
+
data?.additionalOrderStates,
|
|
145
|
+
]);
|
|
146
|
+
const changeCustomMetricRange = (date, key) => {
|
|
147
|
+
if (!date)
|
|
148
|
+
return;
|
|
149
|
+
setDateRange((p) => ({
|
|
150
|
+
...p,
|
|
151
|
+
range: { ...p.range, [key]: date },
|
|
152
|
+
}));
|
|
153
|
+
};
|
|
154
|
+
const betterData = useMemo(() => {
|
|
155
|
+
const allData = betterMetrics.data
|
|
156
|
+
.map((metric) => metric.entries.map((entry) => {
|
|
157
|
+
const name = parseNameToCurrentLanguage(entry.name, language);
|
|
158
|
+
const reduced = selectedAvailableProducts.reduce((acc, selectedProduct) => {
|
|
159
|
+
const product = entry.additionalData?.find((data) => data.id === selectedProduct.id);
|
|
160
|
+
acc[selectedProduct.id] = product?.quantity ?? 0;
|
|
161
|
+
return acc;
|
|
162
|
+
}, {});
|
|
163
|
+
return { ...entry, name, ...reduced };
|
|
164
|
+
}))
|
|
165
|
+
.flat();
|
|
166
|
+
return { allData };
|
|
167
|
+
}, [betterMetrics, net, language, selectedAvailableProducts]);
|
|
168
|
+
const onSelectedAvailableProductsChange = (id) => {
|
|
169
|
+
setSelectedAvailableProducts((prev) => prev.some((product) => product.id === id)
|
|
170
|
+
? prev.filter((p) => p.id !== id)
|
|
171
|
+
: [
|
|
172
|
+
...prev,
|
|
173
|
+
{
|
|
174
|
+
id,
|
|
175
|
+
color: generateBrightRandomColor(),
|
|
176
|
+
},
|
|
177
|
+
]);
|
|
178
|
+
};
|
|
179
|
+
const shouldShowGroupBy = useMemo(() => {
|
|
180
|
+
const { start, end } = dateRange.range;
|
|
181
|
+
return end && differenceInDays(end, start) > 28;
|
|
182
|
+
}, [dateRange.range.start, dateRange.range.end]);
|
|
183
|
+
const groupedData = useMemo(() => {
|
|
184
|
+
const { start, end } = dateRange.range;
|
|
185
|
+
const shouldShowGroupBy = end && differenceInDays(end, start) > 28;
|
|
186
|
+
if (!shouldShowGroupBy)
|
|
187
|
+
return betterData.allData;
|
|
188
|
+
return Object.values(groupByPeriods({ data: betterData.allData, language, groupBy }));
|
|
189
|
+
}, [betterData.allData, groupBy, dateRange.range.start, dateRange.range.end]);
|
|
190
|
+
const options = useMemo(() => [
|
|
191
|
+
...Object.values(ORDER_STATE),
|
|
192
|
+
...(data?.additionalOrderStates.map(({ state }) => state) || []),
|
|
193
|
+
]
|
|
194
|
+
.filter((i, index, arr) => arr.indexOf(i) === index)
|
|
195
|
+
.sort((a, b) => a.localeCompare(b))
|
|
196
|
+
.map((state) => ({
|
|
197
|
+
value: state,
|
|
198
|
+
label: parseNameToCurrentLanguage(state, language),
|
|
199
|
+
})), [data?.additionalOrderStates]);
|
|
200
|
+
return (React.createElement(Card, { className: "border-0 py-6 pr-6 shadow-none " },
|
|
201
|
+
React.createElement(CardHeader, { className: "flex-col items-start justify-between gap-2 pt-0 xl:flex-row" },
|
|
202
|
+
React.createElement("div", { className: "flex flex-col gap-2" },
|
|
203
|
+
React.createElement("div", { className: "flex flex-col gap-2 xl:flex-row" },
|
|
204
|
+
React.createElement("div", { className: "flex gap-2" },
|
|
205
|
+
React.createElement(MetricsRangeSelect, { value: metricRangeTypeSelectValue, changeMetricInterval: setMetricRangeTypeSelectValue, loading: metricLoading }),
|
|
206
|
+
shouldShowGroupBy ? (React.createElement(GroupBySelect, { value: groupBy, changeGroupBy: (value) => setGroupBy(value) })) : null),
|
|
207
|
+
React.createElement(MetricsCustomDates, { isVisible: metricRangeTypeSelectValue === MetricRangeType.Custom, endDate: dateRange.range.end, startDate: dateRange.range.start, setDate: changeCustomMetricRange })),
|
|
208
|
+
React.createElement("div", { className: cn("flex cursor-pointer items-center gap-2 text-sm opacity-0 select-none", metricRangeTypeSelectValue !== MetricRangeType.Custom &&
|
|
209
|
+
metricType !== ChartMetricType.OrderTotalProductsCount &&
|
|
210
|
+
"opacity-100 select-auto") },
|
|
211
|
+
React.createElement(Checkbox, { id: "compare", checked: shouldShowCompare, onCheckedChange: (e) => setShouldShowCompare(e) }),
|
|
212
|
+
React.createElement("label", { htmlFor: "compare", className: "text-foreground/70 shrink-0 cursor-pointer select-none text-[0.75rem] font-medium leading-none" }, t("compare")))),
|
|
213
|
+
React.createElement("div", { className: "!mt-0 flex items-center gap-2" },
|
|
214
|
+
React.createElement(DraggableSelect, { localStorageKey: "orders-widget-order-states", align: "end", title: t("selectOrderStates"), button: React.createElement(Button, { variant: "outline", size: "sm", className: "h-8 gap-2 py-0" },
|
|
215
|
+
selectedOrderStates.length
|
|
216
|
+
? `${t("selectedOrderStates")} (${selectedOrderStates.length})`
|
|
217
|
+
: t("selectOrderStates"),
|
|
218
|
+
React.createElement(PanelsTopLeft, { className: "size-4", "aria-hidden": "true" })), value: selectedOrderStates, onChange: setSelectedOrderStates, options: options }),
|
|
219
|
+
React.createElement(MetricTypeSelect, { metricType: metricType, changeMetricType: setMetricType, loading: metricLoading }))),
|
|
220
|
+
React.createElement(OrdersSummaryTile, { net: net, setNet: setNet, orderStates: selectedOrderStates, dateRange: dateRange }),
|
|
221
|
+
React.createElement("div", { className: "mb-6" }),
|
|
222
|
+
React.createElement(CardContent, { className: "mb-6 mr-6 p-0" },
|
|
223
|
+
React.createElement("div", { className: cn("pl-6 flex justify-start pb-6 opacity-0 select-none", metricType === ChartMetricType.OrderTotalProductsCount &&
|
|
224
|
+
"opacity-100 select-auto") },
|
|
225
|
+
React.createElement(ProductSelector, { onSelectedAvailableProductsChange: onSelectedAvailableProductsChange, clearSelectedProducts: () => setSelectedAvailableProducts([]), metricType: metricType, allAvailableProducts: allAvailableProducts, selectedAvailableProducts: selectedAvailableProducts })),
|
|
226
|
+
React.createElement(OrdersChart, { shouldShowCompare: metricRangeTypeSelectValue === MetricRangeType.Custom
|
|
227
|
+
? false
|
|
228
|
+
: shouldShowCompare, selectedAvailableProducts: selectedAvailableProducts, data: groupedData, language: language, metricType: metricType }))));
|
|
229
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TooltipProps } from "recharts";
|
|
2
|
+
import { NameType, ValueType } from "recharts/types/component/DefaultTooltipContent";
|
|
3
|
+
import React from "react";
|
|
4
|
+
interface CustomBarChartTooltipProps {
|
|
5
|
+
chartProps: TooltipProps<ValueType, NameType>;
|
|
6
|
+
currencyCode: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const CustomBarChartTooltip: React.FC<CustomBarChartTooltipProps>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Card, CardContent } from "@deenruv/react-ui-devkit";
|
|
2
|
+
import { useTranslation } from "react-i18next";
|
|
3
|
+
import React from "react";
|
|
4
|
+
export const CustomBarChartTooltip = ({ chartProps, currencyCode, }) => {
|
|
5
|
+
const { t } = useTranslation("dashboard-widgets-plugin", {
|
|
6
|
+
i18n: window.__DEENRUV_SETTINGS__.i18n,
|
|
7
|
+
});
|
|
8
|
+
const payload = chartProps.payload?.[0]?.payload;
|
|
9
|
+
return (React.createElement(Card, { className: "bg-muted flex p-2" },
|
|
10
|
+
React.createElement(CardContent, { className: "flex flex-col gap-1 p-0" },
|
|
11
|
+
React.createElement("span", null,
|
|
12
|
+
t("sold"),
|
|
13
|
+
payload?.value))));
|
|
14
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Bar, BarChart, Cell, ResponsiveContainer, XAxis, YAxis, } from "recharts";
|
|
2
|
+
import { Card, CardContent, CardHeader, CardTitle, Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue, useLazyQuery, useSettings, useWidgetItem, useTranslation, } from "@deenruv/react-ui-devkit";
|
|
3
|
+
import { ChartTooltip, Separator } from "@deenruv/react-ui-devkit";
|
|
4
|
+
import React, { useCallback, useEffect, useState } from "react";
|
|
5
|
+
import { MetricRangeType, ChartMetricType, MetricIntervalType, } from "../../zeus";
|
|
6
|
+
import { endOfWeek, startOfWeek } from "date-fns";
|
|
7
|
+
import { colors, EmptyData } from "../shared";
|
|
8
|
+
import { BarChartMetricQuery } from "../../graphql";
|
|
9
|
+
import { CurrencyCode } from "@deenruv/admin-types";
|
|
10
|
+
import { CustomBarChartTooltip } from "./CustomBarChartTooltip";
|
|
11
|
+
import { getCustomIntervalDates, getRandomColor } from "../../utils";
|
|
12
|
+
import { MetricsRangeSelect } from "../shared/MetricsRangeSelect";
|
|
13
|
+
export const ProductsChartWidget = () => {
|
|
14
|
+
const { t } = useTranslation("dashboard-widgets-plugin");
|
|
15
|
+
const [fetchChartMetrics] = useLazyQuery(BarChartMetricQuery);
|
|
16
|
+
const channel = useSettings((state) => state.selectedChannel);
|
|
17
|
+
const currencyCode = useSettings((p) => p.selectedChannel?.currencyCode);
|
|
18
|
+
const [showData, setShowData] = useState("FIRST_FIVE");
|
|
19
|
+
const [dateRange, setDateRange] = useState({
|
|
20
|
+
start: startOfWeek(new Date(), { weekStartsOn: 1 }),
|
|
21
|
+
end: endOfWeek(new Date(), { weekStartsOn: 1 }),
|
|
22
|
+
});
|
|
23
|
+
const [metricLoading, setMetricLoading] = useState(false);
|
|
24
|
+
const [metricRangeTypeSelectValue, setMetricRangeTypeSelectValue] = useState(MetricRangeType.ThisWeek);
|
|
25
|
+
const [chartData, setChartData] = useState([]);
|
|
26
|
+
const [selectedOrderStates, setSelectedOrderStates] = useState([
|
|
27
|
+
"PaymentSettled",
|
|
28
|
+
"PartiallyShipped",
|
|
29
|
+
"Shipped",
|
|
30
|
+
"PartiallyDelivered",
|
|
31
|
+
"Delivered",
|
|
32
|
+
]);
|
|
33
|
+
const { plugin } = useWidgetItem();
|
|
34
|
+
const barColors =
|
|
35
|
+
// @ts-expect-error: for now we dont have information about these types, but we know that this exists
|
|
36
|
+
plugin?.config?.options?.barChartColors || colors;
|
|
37
|
+
const fetchData = useCallback(async (refresh = false) => {
|
|
38
|
+
try {
|
|
39
|
+
setMetricLoading(true);
|
|
40
|
+
fetchChartMetrics({
|
|
41
|
+
input: {
|
|
42
|
+
orderStates: selectedOrderStates,
|
|
43
|
+
range: dateRange,
|
|
44
|
+
types: [ChartMetricType.OrderTotalProductsCount],
|
|
45
|
+
interval: MetricIntervalType.Day,
|
|
46
|
+
},
|
|
47
|
+
}).then(({ chartMetric }) => {
|
|
48
|
+
const entries = chartMetric.data[0].entries;
|
|
49
|
+
const salesTotals = {};
|
|
50
|
+
entries.forEach((entry) => {
|
|
51
|
+
entry.additionalData?.forEach((product) => {
|
|
52
|
+
if (salesTotals[product.id]) {
|
|
53
|
+
salesTotals[product.id].quantity += product.quantity;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
salesTotals[product.id] = {
|
|
57
|
+
name: product.name,
|
|
58
|
+
quantity: product.quantity,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
const _chartData = Object.values(salesTotals)
|
|
64
|
+
.map((product) => ({
|
|
65
|
+
product: product.name,
|
|
66
|
+
value: product.quantity,
|
|
67
|
+
}))
|
|
68
|
+
.sort((a, b) => b.value - a.value);
|
|
69
|
+
setChartData(_chartData);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
console.log(e);
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
setMetricLoading(false);
|
|
77
|
+
}
|
|
78
|
+
}, [dateRange]);
|
|
79
|
+
const chartConfig = chartData.reduce((config, item, index) => {
|
|
80
|
+
config[item.product] = {
|
|
81
|
+
label: item.product,
|
|
82
|
+
color: getRandomColor(barColors),
|
|
83
|
+
};
|
|
84
|
+
return config;
|
|
85
|
+
}, {});
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
setDateRange(getCustomIntervalDates(metricRangeTypeSelectValue).range);
|
|
88
|
+
}, [metricRangeTypeSelectValue]);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
fetchData();
|
|
91
|
+
}, [channel, dateRange, selectedOrderStates]);
|
|
92
|
+
return (React.createElement(Card, { className: "flex h-full flex-col border-0 shadow-none" },
|
|
93
|
+
React.createElement(CardHeader, { className: "flex justify-between" },
|
|
94
|
+
React.createElement("div", { className: "flex flex-wrap items-start justify-between gap-2" },
|
|
95
|
+
React.createElement(CardTitle, { className: "text-lg" }, t("bestsellers")),
|
|
96
|
+
" ",
|
|
97
|
+
React.createElement("div", { className: "flex w-[240px] flex-col gap-2" },
|
|
98
|
+
React.createElement(MetricsRangeSelect, { value: metricRangeTypeSelectValue, changeMetricInterval: setMetricRangeTypeSelectValue, loading: metricLoading, withoutCustom: true }),
|
|
99
|
+
React.createElement(Select, { onValueChange: (value) => setShowData(value), value: showData, defaultValue: "BY_COUNT" },
|
|
100
|
+
React.createElement(SelectTrigger, { className: "h-[30px] w-[240px] text-[13px]" },
|
|
101
|
+
React.createElement(SelectValue, { placeholder: t("sortBy") })),
|
|
102
|
+
React.createElement(SelectContent, null,
|
|
103
|
+
React.createElement(SelectGroup, null,
|
|
104
|
+
React.createElement(SelectItem, { value: "FIRST_FIVE" }, t("showFirstFive")),
|
|
105
|
+
React.createElement(SelectItem, { value: "ALL" }, t("showAll")))))))),
|
|
106
|
+
React.createElement(Separator, { className: "mb-3" }),
|
|
107
|
+
React.createElement(CardContent, { className: "flex flex-1 items-center justify-center text-xs " }, !chartData.length ? (React.createElement("div", { className: "flex flex-col items-center text-center" },
|
|
108
|
+
React.createElement(EmptyData, { text: t("emptyData") }))) : (React.createElement(ResponsiveContainer, { className: "transition-all", width: "100%", height: (showData === "FIRST_FIVE"
|
|
109
|
+
? chartData.slice(0, 5).length
|
|
110
|
+
: chartData.length) * 50 },
|
|
111
|
+
React.createElement(BarChart, { data: showData === "FIRST_FIVE" ? chartData.slice(0, 5) : chartData, layout: "vertical" },
|
|
112
|
+
React.createElement(YAxis, { dataKey: "product", type: "category", tickLine: false, tickMargin: 10, axisLine: false, width: 180, tick: { fontSize: 12, fontSizeAdjust: 0.5 } }),
|
|
113
|
+
React.createElement(XAxis, { type: "number", hide: true }),
|
|
114
|
+
React.createElement(ChartTooltip, { wrapperStyle: { zIndex: 1000 }, cursor: false, content: (p) => (React.createElement(CustomBarChartTooltip, { currencyCode: currencyCode ?? CurrencyCode.PLN, chartProps: p })) }),
|
|
115
|
+
React.createElement(Bar, { minPointSize: 5, dataKey: "value", radius: 5, barSize: 40 }, chartData.map((entry, index) => (React.createElement(Cell, { key: `cell-${index}`, fill: chartConfig[entry.product].color }))))))))));
|
|
116
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { BarChart3 } from "lucide-react";
|
|
3
|
+
export const EmptyData = ({ text }) => {
|
|
4
|
+
return (React.createElement("div", { className: "flex h-full flex-col items-center justify-center p-6" },
|
|
5
|
+
React.createElement("div", { className: "flex flex-col items-center" },
|
|
6
|
+
React.createElement(BarChart3, { size: 48, className: "mb-4" })),
|
|
7
|
+
React.createElement("div", { className: "text-lg" }, text)));
|
|
8
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MetricRangeType } from "../../zeus";
|
|
2
|
+
import React from "react";
|
|
3
|
+
interface MetricTypeSelectProps {
|
|
4
|
+
value?: MetricRangeType;
|
|
5
|
+
changeMetricInterval: (interval: MetricRangeType) => void;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
withoutCustom?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const MetricsRangeSelect: React.FC<MetricTypeSelectProps>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue, Skeleton, useTranslation, } from "@deenruv/react-ui-devkit";
|
|
2
|
+
import { MetricRangeType } from "../../zeus";
|
|
3
|
+
import React from "react";
|
|
4
|
+
export const MetricsRangeSelect = ({ changeMetricInterval, value, loading, withoutCustom = false, }) => {
|
|
5
|
+
const { t } = useTranslation("dashboard-widgets-plugin");
|
|
6
|
+
return (React.createElement("div", { className: "relative w-full max-w-[240px] xl:w-[240px]" },
|
|
7
|
+
loading ? (React.createElement(Skeleton, { className: "absolute left-0 top-0 size-full" })) : null,
|
|
8
|
+
React.createElement(Select, { value: value, onValueChange: (value) => changeMetricInterval(value), defaultValue: MetricRangeType.ThisWeek },
|
|
9
|
+
React.createElement(SelectTrigger, { className: "h-[30px] w-full text-[13px]" },
|
|
10
|
+
React.createElement(SelectValue, { placeholder: t("selectDataType") })),
|
|
11
|
+
React.createElement(SelectContent, { className: "max-h-none w-full" },
|
|
12
|
+
React.createElement(SelectGroup, null,
|
|
13
|
+
React.createElement(SelectItem, { value: MetricRangeType.Today }, t("today")),
|
|
14
|
+
React.createElement(SelectItem, { value: MetricRangeType.Yesterday }, t("yesterday")),
|
|
15
|
+
React.createElement(SelectItem, { value: MetricRangeType.ThisWeek }, t("thisWeek")),
|
|
16
|
+
React.createElement(SelectItem, { value: MetricRangeType.LastWeek }, t("lastWeek")),
|
|
17
|
+
React.createElement(SelectItem, { value: MetricRangeType.ThisMonth }, t("thisMonth")),
|
|
18
|
+
React.createElement(SelectItem, { value: MetricRangeType.LastMonth }, t("lastMonth")),
|
|
19
|
+
React.createElement(SelectItem, { value: MetricRangeType.ThisYear }, t("thisYear")),
|
|
20
|
+
React.createElement(SelectItem, { value: MetricRangeType.LastYear }, t("lastYear")),
|
|
21
|
+
React.createElement(SelectItem, { value: MetricRangeType.FirstQuarter }, t("firstYearQuarterInterval")),
|
|
22
|
+
React.createElement(SelectItem, { value: MetricRangeType.SecondQuarter }, t("secondYearQuarterInterval")),
|
|
23
|
+
React.createElement(SelectItem, { value: MetricRangeType.ThirdQuarter }, t("thirdYearQuarterInterval")),
|
|
24
|
+
React.createElement(SelectItem, { value: MetricRangeType.FourthQuarter }, t("fourthYearQuarterInterval")),
|
|
25
|
+
!withoutCustom ? (React.createElement(SelectItem, { value: MetricRangeType.Custom }, t("customInterval"))) : null)))));
|
|
26
|
+
};
|