feat: lepší generování mock dat při vývoji
CI / Generate TypeScript types (push) Successful in 11s
CI / Server unit tests (push) Successful in 25s
CI / Build server (push) Successful in 28s
CI / Build client (push) Successful in 41s
CI / Playwright E2E tests (push) Successful in 1m45s
CI / Build and push Docker image (push) Successful in 46s
CI / Notify (push) Successful in 2s
CI / Generate TypeScript types (push) Successful in 11s
CI / Server unit tests (push) Successful in 25s
CI / Build server (push) Successful in 28s
CI / Build client (push) Successful in 41s
CI / Playwright E2E tests (push) Successful in 1m45s
CI / Build and push Docker image (push) Successful in 46s
CI / Notify (push) Successful in 2s
This commit is contained in:
@@ -184,7 +184,7 @@ export default function Header({ choices, dayIndex }: Props) {
|
||||
<>
|
||||
<NavDropdown.Divider />
|
||||
<NavDropdown.Item onClick={() => setGenerateMockModalOpen(true)}>🔧 Generovat mock data</NavDropdown.Item>
|
||||
<NavDropdown.Item onClick={() => setClearMockModalOpen(true)}>🔧 Smazat data dne</NavDropdown.Item>
|
||||
<NavDropdown.Item onClick={() => setClearMockModalOpen(true)}>🔧 Smazat mock data</NavDropdown.Item>
|
||||
</>
|
||||
)}
|
||||
<NavDropdown.Divider />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import { Modal, Button, Alert } from "react-bootstrap";
|
||||
import { Modal, Button, Form, Alert } from "react-bootstrap";
|
||||
import { clearMockData, DayIndex } from "../../../../types";
|
||||
|
||||
type Props = {
|
||||
@@ -10,20 +10,28 @@ type Props = {
|
||||
|
||||
const DAY_NAMES = ['Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek'];
|
||||
|
||||
/** Hodnota v selectu dne pro smazání dat celého týdne. */
|
||||
const WHOLE_WEEK = 'week';
|
||||
|
||||
/** Modální dialog pro smazání mock dat (pouze DEV). */
|
||||
export default function ClearMockDataModal({ isOpen, onClose, currentDayIndex }: Readonly<Props>) {
|
||||
const [daySelection, setDaySelection] = useState<string>(currentDayIndex !== undefined ? String(currentDayIndex) : '');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [success, setSuccess] = useState(false);
|
||||
|
||||
const wholeWeek = daySelection === WHOLE_WEEK;
|
||||
|
||||
const handleClear = async () => {
|
||||
setError(null);
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const body: any = {};
|
||||
if (currentDayIndex !== undefined) {
|
||||
body.dayIndex = currentDayIndex as DayIndex;
|
||||
if (wholeWeek) {
|
||||
body.wholeWeek = true;
|
||||
} else if (daySelection !== '') {
|
||||
body.dayIndex = parseInt(daySelection, 10) as DayIndex;
|
||||
}
|
||||
|
||||
const response = await clearMockData({ body });
|
||||
@@ -49,12 +57,20 @@ export default function ClearMockDataModal({ isOpen, onClose, currentDayIndex }:
|
||||
onClose();
|
||||
};
|
||||
|
||||
const dayName = currentDayIndex !== undefined ? DAY_NAMES[currentDayIndex] : 'aktuální den';
|
||||
// Popis rozsahu mazání pro potvrzovací otázku
|
||||
let scopeLabel: string;
|
||||
if (wholeWeek) {
|
||||
scopeLabel = 'celý týden (pondělí až pátek)';
|
||||
} else if (daySelection !== '') {
|
||||
scopeLabel = DAY_NAMES[parseInt(daySelection, 10)];
|
||||
} else {
|
||||
scopeLabel = 'aktuální den';
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal show={isOpen} onHide={handleClose}>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title><h2>Smazat data</h2></Modal.Title>
|
||||
<Modal.Title><h2>Smazat mock data</h2></Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
{success ? (
|
||||
@@ -73,8 +89,22 @@ export default function ClearMockDataModal({ isOpen, onClose, currentDayIndex }:
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<Form.Group className="mb-3">
|
||||
<Form.Label>Den</Form.Label>
|
||||
<Form.Select
|
||||
value={daySelection}
|
||||
onChange={e => setDaySelection(e.target.value)}
|
||||
>
|
||||
<option value="">Aktuální den</option>
|
||||
{DAY_NAMES.map((name, index) => (
|
||||
<option key={index} value={index}>{name}</option>
|
||||
))}
|
||||
<option value={WHOLE_WEEK}>Celý týden</option>
|
||||
</Form.Select>
|
||||
</Form.Group>
|
||||
|
||||
<p>
|
||||
Opravdu chcete smazat všechny volby stravování pro <strong>{dayName}</strong>?
|
||||
Opravdu chcete smazat všechny volby stravování pro <strong>{scopeLabel}</strong>?
|
||||
</p>
|
||||
<p className="text-muted">
|
||||
Tato akce je nevratná.
|
||||
|
||||
@@ -10,13 +10,18 @@ type Props = {
|
||||
|
||||
const DAY_NAMES = ['Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek'];
|
||||
|
||||
/** Hodnota v selectu dne pro generování napříč celým týdnem. */
|
||||
const WHOLE_WEEK = 'week';
|
||||
|
||||
/** Modální dialog pro generování mock dat (pouze DEV). */
|
||||
export default function GenerateMockDataModal({ isOpen, onClose, currentDayIndex }: Readonly<Props>) {
|
||||
const [dayIndex, setDayIndex] = useState<number | undefined>(currentDayIndex);
|
||||
const [daySelection, setDaySelection] = useState<string>(currentDayIndex !== undefined ? String(currentDayIndex) : '');
|
||||
const [count, setCount] = useState<string>('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [success, setSuccess] = useState(false);
|
||||
const [success, setSuccess] = useState<string | null>(null);
|
||||
|
||||
const wholeWeek = daySelection === WHOLE_WEEK;
|
||||
|
||||
const handleGenerate = async () => {
|
||||
setError(null);
|
||||
@@ -24,8 +29,10 @@ export default function GenerateMockDataModal({ isOpen, onClose, currentDayIndex
|
||||
|
||||
try {
|
||||
const body: any = {};
|
||||
if (dayIndex !== undefined) {
|
||||
body.dayIndex = dayIndex as DayIndex;
|
||||
if (wholeWeek) {
|
||||
body.wholeWeek = true;
|
||||
} else if (daySelection !== '') {
|
||||
body.dayIndex = parseInt(daySelection, 10) as DayIndex;
|
||||
}
|
||||
if (count && count.trim() !== '') {
|
||||
const countNum = parseInt(count, 10);
|
||||
@@ -41,10 +48,13 @@ export default function GenerateMockDataModal({ isOpen, onClose, currentDayIndex
|
||||
if (response.error) {
|
||||
setError((response.error as any).error || 'Nastala chyba při generování dat');
|
||||
} else {
|
||||
setSuccess(true);
|
||||
const total = (response.data as any)?.count;
|
||||
setSuccess(wholeWeek
|
||||
? `Mock data byla vygenerována pro celý týden (celkem ${total} záznamů).`
|
||||
: 'Mock data byla úspěšně vygenerována!');
|
||||
setTimeout(() => {
|
||||
onClose();
|
||||
setSuccess(false);
|
||||
setSuccess(null);
|
||||
setCount('');
|
||||
}, 1500);
|
||||
}
|
||||
@@ -57,7 +67,7 @@ export default function GenerateMockDataModal({ isOpen, onClose, currentDayIndex
|
||||
|
||||
const handleClose = () => {
|
||||
setError(null);
|
||||
setSuccess(false);
|
||||
setSuccess(null);
|
||||
setCount('');
|
||||
onClose();
|
||||
};
|
||||
@@ -70,7 +80,7 @@ export default function GenerateMockDataModal({ isOpen, onClose, currentDayIndex
|
||||
<Modal.Body>
|
||||
{success ? (
|
||||
<Alert variant="success">
|
||||
Mock data byla úspěšně vygenerována!
|
||||
{success}
|
||||
</Alert>
|
||||
) : (
|
||||
<>
|
||||
@@ -87,13 +97,14 @@ export default function GenerateMockDataModal({ isOpen, onClose, currentDayIndex
|
||||
<Form.Group className="mb-3">
|
||||
<Form.Label>Den</Form.Label>
|
||||
<Form.Select
|
||||
value={dayIndex ?? ''}
|
||||
onChange={e => setDayIndex(e.target.value === '' ? undefined : parseInt(e.target.value, 10))}
|
||||
value={daySelection}
|
||||
onChange={e => setDaySelection(e.target.value)}
|
||||
>
|
||||
<option value="">Aktuální den</option>
|
||||
{DAY_NAMES.map((name, index) => (
|
||||
<option key={index} value={index}>{name}</option>
|
||||
))}
|
||||
<option value={WHOLE_WEEK}>Celý týden</option>
|
||||
</Form.Select>
|
||||
<Form.Text className="text-muted">
|
||||
Pokud není vybráno, použije se aktuální den.
|
||||
@@ -112,7 +123,9 @@ export default function GenerateMockDataModal({ isOpen, onClose, currentDayIndex
|
||||
onKeyDown={e => e.stopPropagation()}
|
||||
/>
|
||||
<Form.Text className="text-muted">
|
||||
Pokud není zadáno, vybere se náhodný počet 5-20.
|
||||
{wholeWeek
|
||||
? 'Zadaný počet se vygeneruje pro každý den týdne. Pokud není zadáno, vybere se pro každý den náhodný počet 5-20.'
|
||||
: 'Pokud není zadáno, vybere se náhodný počet 5-20.'}
|
||||
</Form.Text>
|
||||
</Form.Group>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user