From f07f35acfe563189a3810f743116f6f5ddba8db2 Mon Sep 17 00:00:00 2001
From: maxim <bozzhik@ya.ru>
Date: Wed, 19 Mar 2025 19:30:02 +0300
Subject: [PATCH] enable `search` for `select` modules

---
 src/pages/carrier/create.tsx | 10 ++++++++++
 src/pages/carrier/edit.tsx   | 10 ++++++++++
 src/pages/route/create.tsx   | 12 +++++++++++-
 src/pages/route/edit.tsx     | 12 +++++++++++-
 src/pages/sight/create.tsx   | 10 ++++++++++
 src/pages/sight/edit.tsx     | 11 +++++++++++
 src/pages/vehicle/create.tsx | 10 ++++++++++
 src/pages/vehicle/edit.tsx   | 10 ++++++++++
 8 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/src/pages/carrier/create.tsx b/src/pages/carrier/create.tsx
index 5ff07d5..20b3dd7 100644
--- a/src/pages/carrier/create.tsx
+++ b/src/pages/carrier/create.tsx
@@ -14,6 +14,13 @@ export const CarrierCreate = () => {
 
   const {autocompleteProps: cityAutocompleteProps} = useAutocomplete({
     resource: 'city',
+    onSearch: (value) => [
+      {
+        field: 'name',
+        operator: 'contains',
+        value,
+      },
+    ],
   })
 
   return (
@@ -37,6 +44,9 @@ export const CarrierCreate = () => {
               isOptionEqualToValue={(option, value) => {
                 return option.id === value?.id
               }}
+              filterOptions={(options, {inputValue}) => {
+                return options.filter((option) => option.name.toLowerCase().includes(inputValue.toLowerCase()))
+              }}
               renderInput={(params) => <TextField {...params} label="Выберите город" margin="normal" variant="outlined" error={!!errors.city_id} helperText={(errors as any)?.city_id?.message} required />}
             />
           )}
diff --git a/src/pages/carrier/edit.tsx b/src/pages/carrier/edit.tsx
index 850a7af..c572eb7 100644
--- a/src/pages/carrier/edit.tsx
+++ b/src/pages/carrier/edit.tsx
@@ -13,6 +13,13 @@ export const CarrierEdit = () => {
 
   const {autocompleteProps: cityAutocompleteProps} = useAutocomplete({
     resource: 'city',
+    onSearch: (value) => [
+      {
+        field: 'name',
+        operator: 'contains',
+        value,
+      },
+    ],
   })
 
   return (
@@ -36,6 +43,9 @@ export const CarrierEdit = () => {
               isOptionEqualToValue={(option, value) => {
                 return option.id === value?.id
               }}
+              filterOptions={(options, {inputValue}) => {
+                return options.filter((option) => option.name.toLowerCase().includes(inputValue.toLowerCase()))
+              }}
               renderInput={(params) => <TextField {...params} label="Выберите город" margin="normal" variant="outlined" error={!!errors.city_id} helperText={(errors as any)?.city_id?.message} required />}
             />
           )}
diff --git a/src/pages/route/create.tsx b/src/pages/route/create.tsx
index 67aa7b5..b6f6cb6 100644
--- a/src/pages/route/create.tsx
+++ b/src/pages/route/create.tsx
@@ -18,6 +18,13 @@ export const RouteCreate = () => {
 
   const {autocompleteProps: carrierAutocompleteProps} = useAutocomplete({
     resource: 'carrier',
+    onSearch: (value) => [
+      {
+        field: 'short_name',
+        operator: 'contains',
+        value,
+      },
+    ],
   })
 
   return (
@@ -41,7 +48,10 @@ export const RouteCreate = () => {
               isOptionEqualToValue={(option, value) => {
                 return option.id === value?.id
               }}
-              renderInput={(params) => <TextField {...params} label="Выберите перевозчика" margin="normal" variant="outlined" error={!!errors.city_id} helperText={(errors as any)?.city_id?.message} required />}
+              filterOptions={(options, {inputValue}) => {
+                return options.filter((option) => option.short_name.toLowerCase().includes(inputValue.toLowerCase()))
+              }}
+              renderInput={(params) => <TextField {...params} label="Выберите перевозчика" margin="normal" variant="outlined" error={!!errors.carrier_id} helperText={(errors as any)?.carrier_id?.message} required />}
             />
           )}
         />
diff --git a/src/pages/route/edit.tsx b/src/pages/route/edit.tsx
index a87193e..0e03a62 100644
--- a/src/pages/route/edit.tsx
+++ b/src/pages/route/edit.tsx
@@ -18,6 +18,13 @@ export const RouteEdit = () => {
 
   const {autocompleteProps: carrierAutocompleteProps} = useAutocomplete({
     resource: 'carrier',
+    onSearch: (value) => [
+      {
+        field: 'short_name',
+        operator: 'contains',
+        value,
+      },
+    ],
   })
 
   return (
@@ -41,7 +48,10 @@ export const RouteEdit = () => {
               isOptionEqualToValue={(option, value) => {
                 return option.id === value?.id
               }}
-              renderInput={(params) => <TextField {...params} label="Выберите перевозчика" margin="normal" variant="outlined" error={!!errors.city_id} helperText={(errors as any)?.city_id?.message} required />}
+              filterOptions={(options, {inputValue}) => {
+                return options.filter((option) => option.short_name.toLowerCase().includes(inputValue.toLowerCase()))
+              }}
+              renderInput={(params) => <TextField {...params} label="Выберите перевозчика" margin="normal" variant="outlined" error={!!errors.carrier_id} helperText={(errors as any)?.carrier_id?.message} required />}
             />
           )}
         />
diff --git a/src/pages/sight/create.tsx b/src/pages/sight/create.tsx
index b1bb90c..1412308 100644
--- a/src/pages/sight/create.tsx
+++ b/src/pages/sight/create.tsx
@@ -18,6 +18,13 @@ export const SightCreate = () => {
 
   const {autocompleteProps: cityAutocompleteProps} = useAutocomplete({
     resource: 'city',
+    onSearch: (value) => [
+      {
+        field: 'name',
+        operator: 'contains',
+        value,
+      },
+    ],
   })
 
   return (
@@ -83,6 +90,9 @@ export const SightCreate = () => {
               isOptionEqualToValue={(option, value) => {
                 return option.id === value?.id
               }}
+              filterOptions={(options, {inputValue}) => {
+                return options.filter((option) => option.name.toLowerCase().includes(inputValue.toLowerCase()))
+              }}
               renderInput={(params) => <TextField {...params} label="Выберите город" margin="normal" variant="outlined" error={!!errors.city_id} helperText={(errors as any)?.city_id?.message} required />}
             />
           )}
diff --git a/src/pages/sight/edit.tsx b/src/pages/sight/edit.tsx
index fd8405b..585f5d0 100644
--- a/src/pages/sight/edit.tsx
+++ b/src/pages/sight/edit.tsx
@@ -15,8 +15,16 @@ export const SightEdit = () => {
   } = useForm({})
 
   const {id: sightId} = useParams<{id: string}>()
+
   const {autocompleteProps: cityAutocompleteProps} = useAutocomplete({
     resource: 'city',
+    onSearch: (value) => [
+      {
+        field: 'name',
+        operator: 'contains',
+        value,
+      },
+    ],
   })
 
   return (
@@ -82,6 +90,9 @@ export const SightEdit = () => {
               isOptionEqualToValue={(option, value) => {
                 return option.id === value?.id
               }}
+              filterOptions={(options, {inputValue}) => {
+                return options.filter((option) => option.name.toLowerCase().includes(inputValue.toLowerCase()))
+              }}
               renderInput={(params) => <TextField {...params} label="Выберите город" margin="normal" variant="outlined" error={!!errors.city_id} helperText={(errors as any)?.city_id?.message} required />}
             />
           )}
diff --git a/src/pages/vehicle/create.tsx b/src/pages/vehicle/create.tsx
index 7884dfb..1e95781 100644
--- a/src/pages/vehicle/create.tsx
+++ b/src/pages/vehicle/create.tsx
@@ -16,6 +16,13 @@ export const VehicleCreate = () => {
 
   const {autocompleteProps: cityAutocompleteProps} = useAutocomplete({
     resource: 'city',
+    onSearch: (value) => [
+      {
+        field: 'name',
+        operator: 'contains',
+        value,
+      },
+    ],
   })
 
   return (
@@ -79,6 +86,9 @@ export const VehicleCreate = () => {
               isOptionEqualToValue={(option, value) => {
                 return option.id === value?.id
               }}
+              filterOptions={(options, {inputValue}) => {
+                return options.filter((option) => option.name.toLowerCase().includes(inputValue.toLowerCase()))
+              }}
               renderInput={(params) => <TextField {...params} label="Выберите город" margin="normal" variant="outlined" error={!!errors.city_id} helperText={(errors as any)?.city_id?.message} required />}
             />
           )}
diff --git a/src/pages/vehicle/edit.tsx b/src/pages/vehicle/edit.tsx
index d82905b..9723e2c 100644
--- a/src/pages/vehicle/edit.tsx
+++ b/src/pages/vehicle/edit.tsx
@@ -21,6 +21,13 @@ export const VehicleEdit = () => {
 
   const {autocompleteProps: cityAutocompleteProps} = useAutocomplete({
     resource: 'city',
+    onSearch: (value) => [
+      {
+        field: 'name',
+        operator: 'contains',
+        value,
+      },
+    ],
   })
 
   return (
@@ -84,6 +91,9 @@ export const VehicleEdit = () => {
               isOptionEqualToValue={(option, value) => {
                 return option.id === value?.id
               }}
+              filterOptions={(options, {inputValue}) => {
+                return options.filter((option) => option.name.toLowerCase().includes(inputValue.toLowerCase()))
+              }}
               renderInput={(params) => <TextField {...params} label="Выберите город" margin="normal" variant="outlined" error={!!errors.city_id} helperText={(errors as any)?.city_id?.message} required />}
             />
           )}