parent
0b673f34e2
commit
c230e6382e
@ -0,0 +1,74 @@
|
|||||||
|
import { useFilters } from "../../stores/useFilters";
|
||||||
|
import { usePointSelection } from "../../stores/usePointSelection";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { api } from "../../api";
|
||||||
|
import { Button } from "antd";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
function download(filename, data) {
|
||||||
|
const downloadLink = window.document.createElement("a");
|
||||||
|
downloadLink.href = window.URL.createObjectURL(
|
||||||
|
new Blob([data], {
|
||||||
|
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||||
|
})
|
||||||
|
);
|
||||||
|
downloadLink.download = filename;
|
||||||
|
document.body.appendChild(downloadLink);
|
||||||
|
downloadLink.click();
|
||||||
|
document.body.removeChild(downloadLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
const useExportData = (enabled, onSuccess, onSettled) => {
|
||||||
|
const { filters } = useFilters();
|
||||||
|
const { prediction, status, categories } = filters;
|
||||||
|
const { selection } = usePointSelection();
|
||||||
|
|
||||||
|
return useQuery(
|
||||||
|
["export", filters, selection],
|
||||||
|
async () => {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
"prediction_current[]": prediction,
|
||||||
|
"status[]": status,
|
||||||
|
"categories[]": categories,
|
||||||
|
"included[]": [...selection.included],
|
||||||
|
"excluded[]": [...selection.excluded],
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data } = await api.get(
|
||||||
|
`/api/placement_points/to_excel?${params.toString()}`,
|
||||||
|
{ responseType: "arraybuffer" }
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
{ enabled, onSuccess, onSettled }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ExportButton = () => {
|
||||||
|
const [startExport, setStartExport] = useState(false);
|
||||||
|
useExportData(
|
||||||
|
startExport,
|
||||||
|
(data) => {
|
||||||
|
download("postamates.xlsx", data);
|
||||||
|
},
|
||||||
|
() => setStartExport(false)
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleExport = () => {
|
||||||
|
setStartExport(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
block
|
||||||
|
className={"mt-2"}
|
||||||
|
onClick={handleExport}
|
||||||
|
loading={startExport}
|
||||||
|
disabled={startExport}
|
||||||
|
>
|
||||||
|
Экспорт данных
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
};
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
import { RegionSelect } from "./RegionSelect";
|
||||||
|
import { CategoriesSelect } from "./CategoriesSelect";
|
||||||
|
import { PredictionSlider } from "./PredictionSlider";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { Tooltip } from "antd";
|
||||||
|
import { DISABLED_FILTER_TEXT } from "../../config";
|
||||||
|
|
||||||
|
export const Filters = ({ disabled }) => {
|
||||||
|
const [hover, setHover] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = setTimeout(() => setHover(false), 1500);
|
||||||
|
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
}, [hover]);
|
||||||
|
|
||||||
|
const handleMouseEnter = () => setHover(true);
|
||||||
|
const handleMouseLeave = () => {
|
||||||
|
setHover(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip
|
||||||
|
title={DISABLED_FILTER_TEXT}
|
||||||
|
placement="right"
|
||||||
|
open={disabled && hover}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="space-y-5"
|
||||||
|
onMouseEnter={handleMouseEnter}
|
||||||
|
onMouseLeave={handleMouseLeave}
|
||||||
|
>
|
||||||
|
<RegionSelect disabled={disabled} />
|
||||||
|
<CategoriesSelect disabled={disabled} />
|
||||||
|
<PredictionSlider disabled={disabled} />
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
};
|
||||||
Loading…
Reference in new issue