|
|
|
@ -8,42 +8,37 @@ import { usePointSelection } from "../../stores/usePointSelection";
|
|
|
|
import { STATUSES } from "../../config";
|
|
|
|
import { STATUSES } from "../../config";
|
|
|
|
import { useRegionFilterExpression } from "./useRegionFilterExpression";
|
|
|
|
import { useRegionFilterExpression } from "./useRegionFilterExpression";
|
|
|
|
import { LAYER_IDS } from "./constants";
|
|
|
|
import { LAYER_IDS } from "./constants";
|
|
|
|
import { usePendingPointsFilters } from "../../stores/usePendingPointsFilters";
|
|
|
|
import { RANGE_FILTERS_KEYS, usePendingPointsFilters } from "../../stores/usePendingPointsFilters";
|
|
|
|
|
|
|
|
import { usePostamatesAndPvzGroups } from "../../api.js";
|
|
|
|
|
|
|
|
import { useMemo } from "react";
|
|
|
|
|
|
|
|
|
|
|
|
const statusExpression = ["==", ["get", "status"], STATUSES.pending];
|
|
|
|
const statusExpression = ["==", ["get", "status"], STATUSES.pending];
|
|
|
|
|
|
|
|
|
|
|
|
const useFilterExpression = () => {
|
|
|
|
const useFilterExpression = () => {
|
|
|
|
|
|
|
|
const { data: postamatesAndPvzGroups } = usePostamatesAndPvzGroups();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filteredPostamatesCategories = useMemo(() => {
|
|
|
|
|
|
|
|
if (!postamatesAndPvzGroups) return [];
|
|
|
|
|
|
|
|
return postamatesAndPvzGroups
|
|
|
|
|
|
|
|
.filter((category) => category.visible)
|
|
|
|
|
|
|
|
.map((category) => {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
...category,
|
|
|
|
|
|
|
|
groups: [...category.groups.filter((group) => group.visible)],
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}, [postamatesAndPvzGroups]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const postamatesGroups = useMemo(() => {
|
|
|
|
|
|
|
|
if (!filteredPostamatesCategories) return [];
|
|
|
|
|
|
|
|
return filteredPostamatesCategories
|
|
|
|
|
|
|
|
.map((category) => {
|
|
|
|
|
|
|
|
return [...category.groups.filter((group) => group.visible)]
|
|
|
|
|
|
|
|
}).flat();
|
|
|
|
|
|
|
|
}, [postamatesAndPvzGroups]);
|
|
|
|
|
|
|
|
|
|
|
|
const { filters, ranges } = usePendingPointsFilters();
|
|
|
|
const { filters, ranges } = usePendingPointsFilters();
|
|
|
|
const {
|
|
|
|
const { prediction, categories, region } = filters;
|
|
|
|
prediction,
|
|
|
|
|
|
|
|
categories,
|
|
|
|
|
|
|
|
region,
|
|
|
|
|
|
|
|
doors__gt,
|
|
|
|
|
|
|
|
doors__lt,
|
|
|
|
|
|
|
|
flat_cnt__gt,
|
|
|
|
|
|
|
|
flat_cnt__lt,
|
|
|
|
|
|
|
|
rival_post_cnt__gt,
|
|
|
|
|
|
|
|
rival_post_cnt__lt,
|
|
|
|
|
|
|
|
rival_pvz_cnt__gt,
|
|
|
|
|
|
|
|
rival_pvz_cnt__lt,
|
|
|
|
|
|
|
|
target_post_cnt__gt,
|
|
|
|
|
|
|
|
target_post_cnt__lt,
|
|
|
|
|
|
|
|
flats_cnt__gt,
|
|
|
|
|
|
|
|
flats_cnt__lt,
|
|
|
|
|
|
|
|
tc_cnt__gt,
|
|
|
|
|
|
|
|
tc_cnt__lt,
|
|
|
|
|
|
|
|
culture_cnt__gt,
|
|
|
|
|
|
|
|
culture_cnt__lt,
|
|
|
|
|
|
|
|
mfc_cnt__gt,
|
|
|
|
|
|
|
|
mfc_cnt__lt,
|
|
|
|
|
|
|
|
public_stop_cnt__gt,
|
|
|
|
|
|
|
|
public_stop_cnt__lt,
|
|
|
|
|
|
|
|
supermarket_cnt__gt,
|
|
|
|
|
|
|
|
supermarket_cnt__lt,
|
|
|
|
|
|
|
|
target_dist__gt,
|
|
|
|
|
|
|
|
target_dist__lt,
|
|
|
|
|
|
|
|
metro_dist__gt,
|
|
|
|
|
|
|
|
metro_dist__lt, } = filters;
|
|
|
|
|
|
|
|
const { selection } = usePointSelection();
|
|
|
|
const { selection } = usePointSelection();
|
|
|
|
const includedArr = [...selection.included];
|
|
|
|
const includedArr = [...selection.included];
|
|
|
|
const excludedArr = [...selection.excluded];
|
|
|
|
const excludedArr = [...selection.excluded];
|
|
|
|
@ -52,83 +47,39 @@ const useFilterExpression = () => {
|
|
|
|
|
|
|
|
|
|
|
|
const includedExpression = ["in", ["get", "id"], ["literal", includedArr]];
|
|
|
|
const includedExpression = ["in", ["get", "id"], ["literal", includedArr]];
|
|
|
|
const excludedExpression = ["in", ["get", "id"], ["literal", excludedArr]];
|
|
|
|
const excludedExpression = ["in", ["get", "id"], ["literal", excludedArr]];
|
|
|
|
|
|
|
|
|
|
|
|
const predictionExpression = [
|
|
|
|
const predictionExpression = [
|
|
|
|
[">=", ["get", "prediction_current"], prediction[0]],
|
|
|
|
[">=", ["get", "prediction_current"], prediction[0]],
|
|
|
|
["<=", ["get", "prediction_current"], prediction[1]],
|
|
|
|
["<=", ["get", "prediction_current"], prediction[1]],
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const doorsExpression = [
|
|
|
|
const dynamicKeyFiltersExpressions = postamatesGroups.map((group) => {
|
|
|
|
[">=", ["get", "doors"], doors__gt],
|
|
|
|
const key = `d${group.id}`
|
|
|
|
["<=", ["get", "doors"], doors__lt],
|
|
|
|
return [
|
|
|
|
];
|
|
|
|
[">=", ["get", key], filters[`${key}__gt`]],
|
|
|
|
|
|
|
|
["<=", ["get", key], filters[`${key}__lt`]],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const flatExpression = [
|
|
|
|
const staticKeyFiltersExpressions = RANGE_FILTERS_KEYS.map((key) => {
|
|
|
|
[">=", ["get", "flat_cnt"], flat_cnt__gt],
|
|
|
|
return [
|
|
|
|
["<=", ["get", "flat_cnt"], flat_cnt__lt],
|
|
|
|
[">=", ["get", key], filters[`${key}__gt`]],
|
|
|
|
];
|
|
|
|
["<=", ["get", key], filters[`${key}__lt`]],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const rivalPostExpression = [
|
|
|
|
const dynamicKeyExpressions = dynamicKeyFiltersExpressions.filter((expression) => {
|
|
|
|
[">=", ["get", "rival_post_cnt"], rival_post_cnt__gt],
|
|
|
|
const filterKey = expression[0][1][1];
|
|
|
|
["<=", ["get", "rival_post_cnt"], rival_post_cnt__lt],
|
|
|
|
const range = ranges[filterKey];
|
|
|
|
];
|
|
|
|
const gtValue = expression[0][2] || 0;
|
|
|
|
const rivalPvzExpression = [
|
|
|
|
const gtInitial = range ? range[0] : 0;
|
|
|
|
[">=", ["get", "rival_pvz_cnt"], rival_pvz_cnt__gt],
|
|
|
|
const ltValue = expression[1][2] || 0;
|
|
|
|
["<=", ["get", "rival_pvz_cnt"], rival_pvz_cnt__lt],
|
|
|
|
const ltInitial = range ? range[1] : 0;
|
|
|
|
];
|
|
|
|
|
|
|
|
const targetPostExpression = [
|
|
|
|
return !(gtValue === gtInitial && ltValue === ltInitial);
|
|
|
|
[">=", ["get", "target_post_cnt"], target_post_cnt__gt],
|
|
|
|
}).flat();
|
|
|
|
["<=", ["get", "target_post_cnt"], target_post_cnt__lt],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
const flatsExpression = [
|
|
|
|
|
|
|
|
[">=", ["get", "flats_cnt"], flats_cnt__gt],
|
|
|
|
|
|
|
|
["<=", ["get", "flats_cnt"], flats_cnt__lt],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
const tcExpression = [
|
|
|
|
|
|
|
|
[">=", ["get", "tc_cnt"], tc_cnt__gt],
|
|
|
|
|
|
|
|
["<=", ["get", "tc_cnt"], tc_cnt__lt],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
const cultureExpression = [
|
|
|
|
|
|
|
|
[">=", ["get", "culture_cnt"], culture_cnt__gt],
|
|
|
|
|
|
|
|
["<=", ["get", "culture_cnt"], culture_cnt__lt],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
const mfcExpression = [
|
|
|
|
|
|
|
|
[">=", ["get", "mfc_cnt"], mfc_cnt__gt],
|
|
|
|
|
|
|
|
["<=", ["get", "mfc_cnt"], mfc_cnt__lt],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
const publicStopExpression = [
|
|
|
|
|
|
|
|
[">=", ["get", "public_stop_cnt"], public_stop_cnt__gt],
|
|
|
|
|
|
|
|
["<=", ["get", "public_stop_cnt"], public_stop_cnt__lt],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
const supermarketExpression = [
|
|
|
|
|
|
|
|
[">=", ["get", "supermarket_cnt"], supermarket_cnt__gt],
|
|
|
|
|
|
|
|
["<=", ["get", "supermarket_cnt"], supermarket_cnt__lt],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
const targetDistExpression = [
|
|
|
|
|
|
|
|
[">=", ["get", "target_dist"], target_dist__gt],
|
|
|
|
|
|
|
|
["<=", ["get", "target_dist"], target_dist__lt],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
const metroDistExpression = [
|
|
|
|
|
|
|
|
[">=", ["get", "metro_dist"], metro_dist__gt],
|
|
|
|
|
|
|
|
["<=", ["get", "metro_dist"], metro_dist__lt],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filterExpressions = [
|
|
|
|
const staticKeyExpressions = staticKeyFiltersExpressions.filter((expression) => {
|
|
|
|
doorsExpression,
|
|
|
|
|
|
|
|
flatExpression,
|
|
|
|
|
|
|
|
rivalPostExpression,
|
|
|
|
|
|
|
|
rivalPvzExpression,
|
|
|
|
|
|
|
|
targetPostExpression,
|
|
|
|
|
|
|
|
// flatsExpression,
|
|
|
|
|
|
|
|
tcExpression,
|
|
|
|
|
|
|
|
cultureExpression,
|
|
|
|
|
|
|
|
mfcExpression,
|
|
|
|
|
|
|
|
publicStopExpression,
|
|
|
|
|
|
|
|
supermarketExpression,
|
|
|
|
|
|
|
|
targetDistExpression,
|
|
|
|
|
|
|
|
// metroDistExpression
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const activeExpressions = filterExpressions.filter((expression) => {
|
|
|
|
|
|
|
|
const filterKey = expression[0][1][1];
|
|
|
|
const filterKey = expression[0][1][1];
|
|
|
|
const gtValue = expression[0][2];
|
|
|
|
const gtValue = expression[0][2];
|
|
|
|
const gtInitial = ranges[filterKey][0];
|
|
|
|
const gtInitial = ranges[filterKey][0];
|
|
|
|
@ -150,8 +101,8 @@ const useFilterExpression = () => {
|
|
|
|
[
|
|
|
|
[
|
|
|
|
"any",
|
|
|
|
"any",
|
|
|
|
regionExpression
|
|
|
|
regionExpression
|
|
|
|
? ["all", ...predictionExpression, ...activeExpressions, categoryExpression, regionExpression]
|
|
|
|
? ["all", ...predictionExpression, ...staticKeyExpressions, ...dynamicKeyExpressions, categoryExpression, regionExpression]
|
|
|
|
: ["all", ...predictionExpression, ...activeExpressions, categoryExpression],
|
|
|
|
: ["all", ...predictionExpression, ...staticKeyExpressions, ...dynamicKeyExpressions, categoryExpression],
|
|
|
|
includedExpression,
|
|
|
|
includedExpression,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
];
|
|
|
|
@ -191,7 +142,7 @@ export const PendingPoints = () => {
|
|
|
|
{...matchInitialPointLayer}
|
|
|
|
{...matchInitialPointLayer}
|
|
|
|
id={LAYER_IDS["initial-unmatch"]}
|
|
|
|
id={LAYER_IDS["initial-unmatch"]}
|
|
|
|
source={"points"}
|
|
|
|
source={"points"}
|
|
|
|
source-layer={"public.service_placementpoint"}
|
|
|
|
source-layer={"public.points_with_dist"}
|
|
|
|
layout={{
|
|
|
|
layout={{
|
|
|
|
...matchInitialPointLayer.layout,
|
|
|
|
...matchInitialPointLayer.layout,
|
|
|
|
visibility: isVisible[LAYER_IDS.initial] ? "visible" : "none",
|
|
|
|
visibility: isVisible[LAYER_IDS.initial] ? "visible" : "none",
|
|
|
|
@ -203,7 +154,7 @@ export const PendingPoints = () => {
|
|
|
|
{...matchInitialPointLayer}
|
|
|
|
{...matchInitialPointLayer}
|
|
|
|
id={LAYER_IDS["initial-match"]}
|
|
|
|
id={LAYER_IDS["initial-match"]}
|
|
|
|
source={"points"}
|
|
|
|
source={"points"}
|
|
|
|
source-layer={"public.service_placementpoint"}
|
|
|
|
source-layer={"public.points_with_dist"}
|
|
|
|
layout={{
|
|
|
|
layout={{
|
|
|
|
...matchInitialPointLayer.layout,
|
|
|
|
...matchInitialPointLayer.layout,
|
|
|
|
visibility: isVisible[LAYER_IDS.initial] ? "visible" : "none",
|
|
|
|
visibility: isVisible[LAYER_IDS.initial] ? "visible" : "none",
|
|
|
|
|