Skip to content

Commit 87d84a9

Browse files
authored
Merge pull request #94 from CIAT-DAPA/develop
feat: Add showLabel option for DateRangeField in FieldEditor and upda…
2 parents fe2e512 + 65273c9 commit 87d84a9

7 files changed

Lines changed: 43 additions & 4 deletions

File tree

src/src/app/[locale]/templates/create/TemplatePreview.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,11 @@ export function TemplatePreview({
16891689
case "date_range":
16901690
const dateRangeFormat =
16911691
(field.field_config as any)?.date_format || "DD/MM/YYYY";
1692+
const showDateRangeLabel =
1693+
(field.field_config as any)?.showLabel ?? false;
1694+
const displayDateRangeLabel = showDateRangeLabel
1695+
? field.label || field.display_name
1696+
: null;
16921697
const showMoonPhases =
16931698
(field.field_config as any)?.show_moon_phases || false;
16941699

@@ -1747,8 +1752,13 @@ export function TemplatePreview({
17471752
}
17481753

17491754
return (
1750-
<div key={key} style={fieldStyles}>
1751-
{rangeDisplay}
1755+
<div
1756+
key={key}
1757+
style={fieldStyles}
1758+
className={displayDateRangeLabel ? "flex items-center gap-2" : undefined}
1759+
>
1760+
{displayDateRangeLabel && <span>{displayDateRangeLabel}:</span>}
1761+
<span>{rangeDisplay}</span>
17521762
</div>
17531763
);
17541764
}
@@ -1823,8 +1833,13 @@ export function TemplatePreview({
18231833

18241834
// Sin lunas: formato tradicional
18251835
return (
1826-
<div key={key} style={fieldStyles}>
1827-
{`${startDateDisplay} - ${endDateDisplay}`}
1836+
<div
1837+
key={key}
1838+
style={fieldStyles}
1839+
className={displayDateRangeLabel ? "flex items-center gap-2" : undefined}
1840+
>
1841+
{displayDateRangeLabel && <span>{displayDateRangeLabel}:</span>}
1842+
<span>{`${startDateDisplay} - ${endDateDisplay}`}</span>
18281843
</div>
18291844
);
18301845

src/src/app/[locale]/templates/create/components/FieldEditor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export function FieldEditor({
143143
...fieldToSave,
144144
field_config: {
145145
date_format: currentConfig?.date_format || "YYYY-MM-DD",
146+
showLabel: currentConfig?.showLabel,
146147
start_date_label: currentConfig?.start_date_label || "Start Date",
147148
start_date_description: currentConfig?.start_date_description || "",
148149
end_date_label: currentConfig?.end_date_label || "End Date",

src/src/app/[locale]/templates/create/components/fieldTypes/DateRangeFieldTypeConfig.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useTranslations } from "next-intl";
55
import { DateRangeFieldConfig } from "../../../../../../types/template";
66
import { BaseFieldTypeConfigProps } from "./BaseFieldTypeConfig";
77
import {
8+
helpTextClass,
89
labelClass,
910
labelXsClass,
1011
inputClass,
@@ -33,6 +34,7 @@ export const DateRangeFieldTypeConfig: React.FC<BaseFieldTypeConfigProps> = ({
3334
const t = useTranslations("CreateTemplate.fieldEditor.dateRangeConfig");
3435

3536
const config = (currentField.field_config as DateRangeFieldConfig) || {};
37+
const showLabel = config.showLabel ?? false;
3638

3739
return (
3840
<div className="space-y-4">
@@ -52,6 +54,20 @@ export const DateRangeFieldTypeConfig: React.FC<BaseFieldTypeConfigProps> = ({
5254
</select>
5355
</div>
5456

57+
{/* Mostrar etiqueta del rango */}
58+
<div>
59+
<label className="flex items-center gap-2 cursor-pointer">
60+
<input
61+
type="checkbox"
62+
checked={showLabel}
63+
onChange={(e) => updateFieldConfig({ showLabel: e.target.checked })}
64+
className="w-4 h-4 text-[#283618] border-gray-300 rounded focus:ring-[#283618]"
65+
/>
66+
<span className={labelClass}>{t("showLabel")}</span>
67+
</label>
68+
<p className={helpTextClass}>{t("showLabelHelp")}</p>
69+
</div>
70+
5571
{/* Mostrar Fases de Luna */}
5672
<div>
5773
<label className="flex items-center gap-2 cursor-pointer">

src/src/messages/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,8 @@
12451245
},
12461246
"dateRangeConfig": {
12471247
"format": "Date Format",
1248+
"showLabel": "Show range label",
1249+
"showLabelHelp": "If enabled, the field label will be shown next to the date range",
12481250
"showMoonPhases": "Show moon phases with dates",
12491251
"showMoonPhasesHelp": "Display moon phase icons next to each date",
12501252
"moonPhasesConfigTitle": "Moon Phase Configuration",

src/src/messages/es.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,8 @@
12431243
},
12441244
"dateRangeConfig": {
12451245
"format": "Formato de Fecha",
1246+
"showLabel": "Mostrar etiqueta del rango",
1247+
"showLabelHelp": "Si está activado, se mostrará el label del campo junto al rango de fechas",
12461248
"showMoonPhases": "Mostrar fases de luna con fechas",
12471249
"showMoonPhasesHelp": "Muestra íconos de fase lunar junto a cada fecha",
12481250
"moonPhasesConfigTitle": "Configuración de Fases Lunares",

src/src/messages/vi.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,8 @@
13091309
}
13101310
},
13111311
"dateRangeConfig": {
1312+
"showLabel": "Hiển thị nhãn của phạm vi",
1313+
"showLabelHelp": "Nếu bật, nhãn của trường sẽ hiển thị bên cạnh phạm vi ngày",
13121314
"showMoonPhases": "Hiển thị chu kỳ mặt trăng",
13131315
"showMoonPhasesHelp": "Hiển thị biểu tượng chu kỳ mặt trăng bên cạnh mỗi ngày",
13141316
"moonPhasesConfigTitle": "Cấu hình chu kỳ mặt trăng",

src/src/types/template.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export interface DateFieldConfig {
8080

8181
export interface DateRangeFieldConfig {
8282
date_format?: string;
83+
showLabel?: boolean; // Si true, muestra la etiqueta del rango al lado del valor
8384
start_date_label: string;
8485
start_date_description: string;
8586
end_date_label: string;

0 commit comments

Comments
 (0)