|
|
|
|
@ -1,14 +1,11 @@
|
|
|
|
|
import axios from "axios";
|
|
|
|
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
|
|
|
import axios from "axios";
|
|
|
|
|
import { STATUSES } from "./config";
|
|
|
|
|
import { usePointSelection } from "./stores/usePointSelection";
|
|
|
|
|
import { RANGE_FILTERS_KEYS, usePendingPointsFilters } from "./stores/usePendingPointsFilters";
|
|
|
|
|
import { appendFiltersInUse } from "./utils.js";
|
|
|
|
|
import { useMode } from "./stores/useMode.js";
|
|
|
|
|
import { useMemo } from "react";
|
|
|
|
|
import { RANGE_FILTERS_KEYS, usePendingPointsFilters } from "./stores/usePendingPointsFilters";
|
|
|
|
|
import { usePointSelection } from "./stores/usePointSelection";
|
|
|
|
|
import { useUpdateLayerCounter } from "./stores/useUpdateLayerCounter.js";
|
|
|
|
|
import { keycloak } from "./keycloak.js";
|
|
|
|
|
import { useKeycloak } from "@react-keycloak/web";
|
|
|
|
|
import { appendFiltersInUse } from "./utils.js";
|
|
|
|
|
|
|
|
|
|
export const BASE_URL = import.meta.env.VITE_API_URL;
|
|
|
|
|
|
|
|
|
|
@ -19,23 +16,14 @@ export const api = axios.create({
|
|
|
|
|
: BASE_URL,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
api.interceptors.request.use(async function (config) {
|
|
|
|
|
const token = keycloak.token;
|
|
|
|
|
if (token) {
|
|
|
|
|
config.headers.Authorization = `Bearer ${ token }`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return config;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const useDbTableName = () => {
|
|
|
|
|
const {isImportMode} = useMode();
|
|
|
|
|
const { isImportMode } = useMode();
|
|
|
|
|
if (isImportMode) return "pre_placement_points";
|
|
|
|
|
return "placement_points";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const useSourceLayerName = () => {
|
|
|
|
|
const {isImportMode} = useMode();
|
|
|
|
|
const { isImportMode } = useMode();
|
|
|
|
|
if (isImportMode) return "public.prepoints_with_dist";
|
|
|
|
|
return "public.points_with_dist";
|
|
|
|
|
}
|
|
|
|
|
@ -60,7 +48,7 @@ export const getPoints = async (params, region, dbTable = "placement_points", si
|
|
|
|
|
const resultParams = enrichParamsWithRegionFilter(params, region);
|
|
|
|
|
|
|
|
|
|
const { data } = await api.get(
|
|
|
|
|
`/api/${dbTable}/?${resultParams.toString()}`, {signal}
|
|
|
|
|
`/api/${dbTable}/?${resultParams.toString()}`, { signal }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
@ -122,7 +110,7 @@ export const useGetTotalInitialPointsCount = () => {
|
|
|
|
|
const { updateCounter } = useUpdateLayerCounter();
|
|
|
|
|
return useQuery(
|
|
|
|
|
["all-initial-count", dbTable, updateCounter],
|
|
|
|
|
async ({signal}) => {
|
|
|
|
|
async ({ signal }) => {
|
|
|
|
|
const params = new URLSearchParams({
|
|
|
|
|
page: 1,
|
|
|
|
|
page_size: 1,
|
|
|
|
|
@ -174,7 +162,7 @@ export const useGetFilteredPendingPointsCount = (isMerge) => {
|
|
|
|
|
|
|
|
|
|
return useQuery(
|
|
|
|
|
["filtered-points", filters, dbTable, includedIds, updateCounter],
|
|
|
|
|
async ({signal}) => {
|
|
|
|
|
async ({ signal }) => {
|
|
|
|
|
const params = isMerge ? getMergeParams() : getParams();
|
|
|
|
|
|
|
|
|
|
return await getPoints(params, region, dbTable, signal);
|
|
|
|
|
@ -218,32 +206,23 @@ export const useMergePointsToDb = () => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const useGetPermissions = () => {
|
|
|
|
|
const {setImportMode} = useMode();
|
|
|
|
|
return useQuery(["permissions"], async () => {
|
|
|
|
|
const { data } = await api.get("/api/me/");
|
|
|
|
|
|
|
|
|
|
if (data?.groups?.includes("postnet_editor")) {
|
|
|
|
|
return "editor";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setImportMode(false);
|
|
|
|
|
return "viewer";
|
|
|
|
|
});
|
|
|
|
|
return "editor"
|
|
|
|
|
// const { setImportMode } = useMode();
|
|
|
|
|
// return useQuery(["permissions"], async () => {
|
|
|
|
|
// const { data } = await api.get("/api/me/");
|
|
|
|
|
|
|
|
|
|
// if (data?.groups?.includes("postnet_editor")) {
|
|
|
|
|
// return "editor";
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// setImportMode(false);
|
|
|
|
|
// return "viewer";
|
|
|
|
|
// });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const TASK_STATUSES = {
|
|
|
|
|
finished: "Перерасчет ML завершен"
|
|
|
|
|
}
|
|
|
|
|
export const useCanEdit = () => {
|
|
|
|
|
const { keycloak } = useKeycloak();
|
|
|
|
|
const { data: statusData } = useLastMLRun();
|
|
|
|
|
|
|
|
|
|
const hasFinishedUpdate = useMemo(() => {
|
|
|
|
|
return statusData?.task_status === TASK_STATUSES.finished
|
|
|
|
|
}, [statusData]);
|
|
|
|
|
|
|
|
|
|
return keycloak.hasResourceRole("postnet_editor", "postnet") && hasFinishedUpdate;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const useUpdatePostamatId = () => {
|
|
|
|
|
return useMutation({
|
|
|
|
|
@ -327,10 +306,10 @@ export const useGetPendingPointsRange = (dbTable) => {
|
|
|
|
|
const { data, isInitialLoading, isFetching } = await api.get(
|
|
|
|
|
`/api/${dbTable}/filters/${statusFilter}`
|
|
|
|
|
);
|
|
|
|
|
return {data, isLoading: isInitialLoading || isFetching};
|
|
|
|
|
return { data, isLoading: isInitialLoading || isFetching };
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
select: ({data, isLoading}) => {
|
|
|
|
|
select: ({ data, isLoading }) => {
|
|
|
|
|
const distToGroupsArr = data.dist_to_groups.map((groupRange) => {
|
|
|
|
|
return {
|
|
|
|
|
[`d${groupRange.group_id}`]: [Math.floor(groupRange.dist[0]), Math.min(Math.ceil(groupRange.dist[1]), 4000)],
|
|
|
|
|
|