fix: Add more filters by city for station list and sight list
This commit is contained in:
@@ -24,6 +24,7 @@ import {
|
|||||||
Tab,
|
Tab,
|
||||||
Box,
|
Box,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import { observer } from "mobx-react-lite";
|
||||||
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
||||||
import DragIndicatorIcon from "@mui/icons-material/DragIndicator";
|
import DragIndicatorIcon from "@mui/icons-material/DragIndicator";
|
||||||
import {
|
import {
|
||||||
@@ -33,7 +34,12 @@ import {
|
|||||||
DropResult,
|
DropResult,
|
||||||
} from "@hello-pangea/dnd";
|
} from "@hello-pangea/dnd";
|
||||||
|
|
||||||
import { authInstance, languageStore, routeStore } from "@shared";
|
import {
|
||||||
|
authInstance,
|
||||||
|
languageStore,
|
||||||
|
routeStore,
|
||||||
|
selectedCityStore,
|
||||||
|
} from "@shared";
|
||||||
import { EditStationModal } from "../../widgets/modals/EditStationModal";
|
import { EditStationModal } from "../../widgets/modals/EditStationModal";
|
||||||
|
|
||||||
// Helper function to insert an item at a specific position (1-based index)
|
// Helper function to insert an item at a specific position (1-based index)
|
||||||
@@ -73,7 +79,6 @@ type LinkedItemsProps<T> = {
|
|||||||
disableCreation?: boolean;
|
disableCreation?: boolean;
|
||||||
updatedLinkedItems?: T[];
|
updatedLinkedItems?: T[];
|
||||||
refresh?: number;
|
refresh?: number;
|
||||||
cityId?: number;
|
|
||||||
routeDirection?: boolean;
|
routeDirection?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -112,7 +117,7 @@ export const LinkedItems = <
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const LinkedItemsContents = <
|
const LinkedItemsContentsInner = <
|
||||||
T extends { id: number; name: string; [key: string]: any }
|
T extends { id: number; name: string; [key: string]: any }
|
||||||
>({
|
>({
|
||||||
parentId,
|
parentId,
|
||||||
@@ -124,7 +129,6 @@ export const LinkedItemsContents = <
|
|||||||
disableCreation = false,
|
disableCreation = false,
|
||||||
updatedLinkedItems,
|
updatedLinkedItems,
|
||||||
refresh,
|
refresh,
|
||||||
cityId,
|
|
||||||
routeDirection,
|
routeDirection,
|
||||||
}: LinkedItemsProps<T>) => {
|
}: LinkedItemsProps<T>) => {
|
||||||
const { language } = languageStore;
|
const { language } = languageStore;
|
||||||
@@ -153,17 +157,20 @@ export const LinkedItemsContents = <
|
|||||||
// Фильтруем станции по направлению маршрута
|
// Фильтруем станции по направлению маршрута
|
||||||
return item.direction === routeDirection;
|
return item.direction === routeDirection;
|
||||||
})
|
})
|
||||||
|
.filter((item) => {
|
||||||
|
// Фильтруем по городу из навбара
|
||||||
|
const selectedCityId = selectedCityStore.selectedCityId;
|
||||||
|
if (selectedCityId && "city_id" in item) {
|
||||||
|
return item.city_id === selectedCityId;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
.sort((a, b) => a.name.localeCompare(b.name));
|
.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
|
||||||
// Фильтрация по поиску для массового режима
|
// Фильтрация по поиску для массового режима
|
||||||
const filteredAvailableItems = availableItems.filter((item) => {
|
const filteredAvailableItems = availableItems.filter((item) => {
|
||||||
if (!cityId || item.city_id == cityId) {
|
if (!searchQuery.trim()) return true;
|
||||||
if (!searchQuery.trim()) return true;
|
return String(item.name).toLowerCase().includes(searchQuery.toLowerCase());
|
||||||
return String(item.name)
|
|
||||||
.toLowerCase()
|
|
||||||
.includes(searchQuery.toLowerCase());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -460,9 +467,7 @@ export const LinkedItemsContents = <
|
|||||||
onChange={(_, newValue) =>
|
onChange={(_, newValue) =>
|
||||||
setSelectedItemId(newValue?.id || null)
|
setSelectedItemId(newValue?.id || null)
|
||||||
}
|
}
|
||||||
options={availableItems.filter(
|
options={availableItems}
|
||||||
(item) => !cityId || item.city_id == cityId
|
|
||||||
)}
|
|
||||||
getOptionLabel={(item) => String(item.name)}
|
getOptionLabel={(item) => String(item.name)}
|
||||||
renderInput={(params) => (
|
renderInput={(params) => (
|
||||||
<TextField
|
<TextField
|
||||||
@@ -597,3 +602,7 @@ export const LinkedItemsContents = <
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const LinkedItemsContents = observer(
|
||||||
|
LinkedItemsContentsInner
|
||||||
|
) as typeof LinkedItemsContentsInner;
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ import {
|
|||||||
Paper,
|
Paper,
|
||||||
TableBody,
|
TableBody,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import { observer } from "mobx-react-lite";
|
||||||
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
||||||
|
|
||||||
import { authInstance, languageStore } from "@shared";
|
import { authInstance, languageStore, selectedCityStore } from "@shared";
|
||||||
|
|
||||||
type Field<T> = {
|
type Field<T> = {
|
||||||
label: string;
|
label: string;
|
||||||
@@ -73,7 +74,7 @@ export const LinkedSights = <
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const LinkedSightsContents = <
|
const LinkedSightsContentsInner = <
|
||||||
T extends { id: number; name: string; [key: string]: any }
|
T extends { id: number; name: string; [key: string]: any }
|
||||||
>({
|
>({
|
||||||
parentId,
|
parentId,
|
||||||
@@ -100,6 +101,14 @@ export const LinkedSightsContents = <
|
|||||||
|
|
||||||
const availableItems = allItems
|
const availableItems = allItems
|
||||||
.filter((item) => !linkedItems.some((linked) => linked.id === item.id))
|
.filter((item) => !linkedItems.some((linked) => linked.id === item.id))
|
||||||
|
.filter((item) => {
|
||||||
|
// Фильтруем по городу из навбара
|
||||||
|
const selectedCityId = selectedCityStore.selectedCityId;
|
||||||
|
if (selectedCityId && "city_id" in item) {
|
||||||
|
return item.city_id === selectedCityId;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
.sort((a, b) => a.name.localeCompare(b.name));
|
.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -313,3 +322,7 @@ export const LinkedSightsContents = <
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const LinkedSightsContents = observer(
|
||||||
|
LinkedSightsContentsInner
|
||||||
|
) as typeof LinkedSightsContentsInner;
|
||||||
|
|||||||
@@ -68,7 +68,10 @@ export const StationEditPage = observer(() => {
|
|||||||
const handleEdit = async () => {
|
const handleEdit = async () => {
|
||||||
const isCityMissing = !editStationData.common.city_id;
|
const isCityMissing = !editStationData.common.city_id;
|
||||||
// Проверяем названия на всех языках
|
// Проверяем названия на всех языках
|
||||||
const isNameMissing = !editStationData.ru.name || !editStationData.en.name || !editStationData.zh.name;
|
const isNameMissing =
|
||||||
|
!editStationData.ru.name ||
|
||||||
|
!editStationData.en.name ||
|
||||||
|
!editStationData.zh.name;
|
||||||
|
|
||||||
if (isCityMissing || isNameMissing) {
|
if (isCityMissing || isNameMissing) {
|
||||||
setIsSaveWarningOpen(true);
|
setIsSaveWarningOpen(true);
|
||||||
@@ -106,6 +109,7 @@ export const StationEditPage = observer(() => {
|
|||||||
return (
|
return (
|
||||||
<Paper className="w-full h-full p-3 flex flex-col gap-10">
|
<Paper className="w-full h-full p-3 flex flex-col gap-10">
|
||||||
<LanguageSwitcher />
|
<LanguageSwitcher />
|
||||||
|
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
<button
|
<button
|
||||||
className="flex items-center gap-2"
|
className="flex items-center gap-2"
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user