feat: update color carrier
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { DataGrid, GridColDef, GridRenderCellParams } from "@mui/x-data-grid";
|
||||
import { ruRU } from "@mui/x-data-grid/locales";
|
||||
import { authStore, languageStore, cityStore, countryStore, SearchInput } from "@shared";
|
||||
import { authStore, languageStore, cityStore, countryStore, selectedCityStore, SearchInput } from "@shared";
|
||||
import { useEffect, useState, useMemo } from "react";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { Pencil, Trash2, Minus } from "lucide-react";
|
||||
@@ -59,16 +59,21 @@ export const CityListPage = observer(() => {
|
||||
}, [cities, countryStore.countries, language, isLoading]);
|
||||
|
||||
const filteredRows = useMemo(() => {
|
||||
const { selectedCityId } = selectedCityStore;
|
||||
if (!selectedCityId) return [];
|
||||
|
||||
const query = searchQuery.trim().toLowerCase();
|
||||
if (!query) return rows;
|
||||
return rows.filter((row) => {
|
||||
const result = rows.filter((row) => row.id === selectedCityId);
|
||||
|
||||
if (!query) return result;
|
||||
return result.filter((row) => {
|
||||
const cityName = (row.name ?? "").toLowerCase();
|
||||
const countryName = (
|
||||
countryStore.countries[language]?.data?.find((c) => c.code === row.country)?.name ?? ""
|
||||
).toLowerCase();
|
||||
return cityName.includes(query) || countryName.includes(query);
|
||||
});
|
||||
}, [rows, searchQuery, countryStore.countries, language]);
|
||||
}, [rows, searchQuery, countryStore.countries, language, selectedCityStore.selectedCityId]);
|
||||
|
||||
const columns: GridColDef[] = [
|
||||
{
|
||||
@@ -139,7 +144,11 @@ export const CityListPage = observer(() => {
|
||||
<div className="flex justify-between items-center mb-10">
|
||||
<h1 className="text-2xl">Города</h1>
|
||||
{canWriteCities && (
|
||||
<CreateButton label="Создать город" path="/city/create" />
|
||||
<CreateButton
|
||||
label="Создать город"
|
||||
path="/city/create"
|
||||
disabled={!selectedCityStore.selectedCityId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -195,7 +204,13 @@ export const CityListPage = observer(() => {
|
||||
slots={{
|
||||
noRowsOverlay: () => (
|
||||
<Box sx={{ mt: 5, textAlign: "center", color: "text.secondary" }}>
|
||||
{isLoading ? <CircularProgress size={20} /> : "Нет городов"}
|
||||
{isLoading ? (
|
||||
<CircularProgress size={20} />
|
||||
) : !selectedCityStore.selectedCityId ? (
|
||||
"Выберите город"
|
||||
) : (
|
||||
"Нет городов"
|
||||
)}
|
||||
</Box>
|
||||
),
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user