Skip to content

Commit

Permalink
Merge pull request #813 from gisce/66719/feature/widget-human-datetime
Browse files Browse the repository at this point in the history
Support date/datetime/time fields on label widgets to human dates
  • Loading branch information
mguellsegarra authored Jan 17, 2025
2 parents 4f6ff13 + 7b49fa9 commit 0d55642
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/helpers/dayjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import duration from "dayjs/plugin/duration";
import relativeTime from "dayjs/plugin/relativeTime";
import weekday from "dayjs/plugin/weekday";
import localeData from "dayjs/plugin/localeData";
import "dayjs/locale/es";
import "dayjs/locale/en";
import "dayjs/locale/ca";

dayjs.extend(advancedFormat);
dayjs.extend(customParseFormat);
Expand Down
10 changes: 9 additions & 1 deletion src/widgets/base/Label.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useContext } from "react";
import { useContext } from "react";
import { Tooltip, Typography, theme } from "antd";
import { WidgetProps } from "@/types";
import { QuestionCircleOutlined } from "@ant-design/icons";
import { Label as LabelOoui } from "@gisce/ooui";
import { FormContext, FormContextType } from "@/context/FormContext";
import { Interweave } from "interweave";
import dayjs from "@/helpers/dayjs";
const { Text, Title } = Typography;
const { useToken } = theme;

Expand All @@ -28,6 +29,13 @@ const Label = (props: Props) => {
let labelText = addColon && label.length > 1 ? label + " :" : label;
if (!ooui.fieldForLabel && ooui._id) {
labelText = formContext.getFieldValue(ooui._id);
if (
ooui.fieldType === "date" ||
ooui.fieldType === "time" ||
ooui.fieldType === "datetime"
) {
labelText = labelText ? dayjs(labelText).fromNow() : "";
}
}
const responsiveAlign = responsiveBehaviour ? "left" : "right";
const labelAlgin = align || (fieldForLabel ? responsiveAlign : "left");
Expand Down

0 comments on commit 0d55642

Please sign in to comment.