фикс багов
This commit is contained in:
@@ -111,11 +111,13 @@ export const selectDefinition: ElementDefinition<SelectConfig, string> = {
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
{config.options.map((option, index) => (
|
||||
<SelectItem key={index} value={option.value}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
{config.options
|
||||
.filter(option => option.value.trim() !== '')
|
||||
.map((option, index) => (
|
||||
<SelectItem key={index} value={option.value}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
@@ -127,11 +129,13 @@ export const selectDefinition: ElementDefinition<SelectConfig, string> = {
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
{config.options.map((option, index) => (
|
||||
<SelectItem key={index} value={option.value}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
{config.options
|
||||
.filter(option => option.value.trim() !== '')
|
||||
.map((option, index) => (
|
||||
<SelectItem key={index} value={option.value}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Button } from '@/component/ui/button'
|
||||
import { Calendar } from '@/component/ui/calendar'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/component/ui/card'
|
||||
import {
|
||||
Dialog,
|
||||
@@ -10,7 +9,6 @@ import {
|
||||
} from '@/component/ui/dialog'
|
||||
import { Input } from '@/component/ui/input'
|
||||
import { Label } from '@/component/ui/label'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/component/ui/popover'
|
||||
import {
|
||||
AlertCircle,
|
||||
Building2,
|
||||
@@ -47,7 +45,6 @@ export function VerificationConditionsRender({
|
||||
config.selectedDate || new Date().toISOString().split('T')[0]
|
||||
)
|
||||
const [editDialogOpen, setEditDialogOpen] = useState(false)
|
||||
const [calendarOpen, setCalendarOpen] = useState(false)
|
||||
const [editingConditions, setEditingConditions] = useState<
|
||||
Record<string, string>
|
||||
>({})
|
||||
@@ -67,26 +64,23 @@ export function VerificationConditionsRender({
|
||||
const hasConditions =
|
||||
dailyCondition && Object.keys(dailyCondition.conditions).length > 0
|
||||
|
||||
// Автоматическая инициализация onChange при загрузке данных
|
||||
// Инициализация данных при загрузке из БД, только если данные еще не заполнены
|
||||
useEffect(() => {
|
||||
if (dailyCondition && onChange && hasConditions) {
|
||||
if (
|
||||
dailyCondition &&
|
||||
hasConditions &&
|
||||
onChange &&
|
||||
(!value?.conditions || Object.keys(value.conditions).length === 0)
|
||||
) {
|
||||
onChange({
|
||||
date: selectedDate,
|
||||
conditions: dailyCondition.conditions,
|
||||
})
|
||||
}
|
||||
}, [dailyCondition, onChange, selectedDate, hasConditions])
|
||||
}, [dailyCondition, hasConditions, onChange, selectedDate, value?.conditions])
|
||||
|
||||
const handleDateChange = (date: string) => {
|
||||
setSelectedDate(date)
|
||||
}
|
||||
|
||||
const handleCalendarSelect = (date: Date | undefined) => {
|
||||
if (date) {
|
||||
const dateString = date.toISOString().split('T')[0]
|
||||
setSelectedDate(dateString)
|
||||
setCalendarOpen(false)
|
||||
}
|
||||
const handleDateChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setSelectedDate(event.target.value)
|
||||
}
|
||||
|
||||
const handleOpenEditDialog = (isCreating = false) => {
|
||||
@@ -167,25 +161,13 @@ export function VerificationConditionsRender({
|
||||
{/* Выбор даты */}
|
||||
<div className="flex items-center gap-2">
|
||||
<CalendarIcon className="h-3.5 w-3.5 text-muted-foreground" />
|
||||
<Popover open={calendarOpen} onOpenChange={setCalendarOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="h-6 justify-start border-none bg-muted/50 px-2 text-xs font-normal hover:bg-muted/70"
|
||||
>
|
||||
{new Date(selectedDate).toLocaleDateString('ru-RU')}
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-auto p-0" align="start">
|
||||
<Calendar
|
||||
mode="single"
|
||||
selected={new Date(selectedDate)}
|
||||
onSelect={handleCalendarSelect}
|
||||
className="rounded-md border shadow-sm"
|
||||
captionLayout="dropdown"
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<Input
|
||||
type="date"
|
||||
value={selectedDate}
|
||||
onChange={handleDateChange}
|
||||
lang="ru"
|
||||
className="h-6 border-none bg-muted/50 px-2 text-xs font-normal hover:bg-muted/70 focus:bg-background"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Статус и данные */}
|
||||
|
||||
@@ -31,6 +31,14 @@ export const verificationConditionsElementDefinition: ElementDefinition<
|
||||
Preview: VerificationConditionsPreview,
|
||||
Render: VerificationConditionsRender,
|
||||
|
||||
// Получение начальных значений из конфигурации
|
||||
getInitialValue: config => {
|
||||
return {
|
||||
date: config.selectedDate || new Date().toISOString().split('T')[0],
|
||||
conditions: {},
|
||||
}
|
||||
},
|
||||
|
||||
// Получение ячеек для записи данных на основе маппинга условий
|
||||
mapToCells: (config): CellTarget[] => {
|
||||
// Возвращаем только те targetCells, которые замаплены к условиям
|
||||
|
||||
Reference in New Issue
Block a user