Skip to content

[Feat]: Add Time-Only Column Type to the Table Component #1553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CellProps } from "components/table/EditableCell";
import { DateTimeComp } from "comps/comps/tableComp/column/columnTypeComps/columnDateTimeComp";
import { TimeComp } from "./columnTypeComps/columnTimeComp";
import { ButtonComp } from "comps/comps/tableComp/column/simpleColumnTypeComps";
import { withType } from "comps/generators";
import { trans } from "i18n";
Expand Down Expand Up @@ -67,6 +68,11 @@ const actionOptions = [
label: trans("table.image"),
value: "image",
},
{
label: trans("table.time"),
value: "time",
},

{
label: trans("table.date"),
value: "date",
Expand Down Expand Up @@ -116,6 +122,7 @@ export const ColumnTypeCompMap = {
rating: RatingComp,
progress: ProgressComp,
date: DateComp,
time: TimeComp,
};

type ColumnTypeMapType = typeof ColumnTypeCompMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
ColumnTypeCompBuilder,
ColumnTypeViewFn,
} from "comps/comps/tableComp/column/columnTypeCompBuilder";
import { ColumnValueTooltip } from "comps/comps/tableComp/column/simpleColumnTypeComps";
import { StringControl } from "comps/controls/codeControl";
import { withDefault } from "comps/generators";
import { formatPropertyView } from "comps/utils/propertyUtils";
import { trans } from "i18n";
import {
TIME_FORMAT,
formatTimestamp,
timestampToHumanReadable,
} from "util/dateTimeUtils";
import { DateEdit } from "./columnDateComp";
import { IconControl } from "comps/controls/iconControl";
import { hasIcon } from "comps/utils";

const childrenMap = {
text: StringControl,
format: withDefault(StringControl, TIME_FORMAT),
inputFormat: withDefault(StringControl, TIME_FORMAT),
prefixIcon: IconControl,
suffixIcon: IconControl,
};

let inputFormat = TIME_FORMAT;

const getBaseValue: ColumnTypeViewFn<typeof childrenMap, string, string> = (props) =>
props.text;

export const TimeComp = (function () {
return new ColumnTypeCompBuilder(
childrenMap,
(props, dispatch) => {
inputFormat = props.inputFormat;
const value = props.changeValue ?? getBaseValue(props, dispatch);

// Convert value to a number if it's a valid timestamp
const timestamp = Number(value);
const formattedValue = !isNaN(timestamp)
? formatTimestamp(timestamp)
: timestampToHumanReadable(timestamp) ?? value;

return (
<>
{hasIcon(props.prefixIcon) && <span>{props.prefixIcon}</span>}
<span>{formattedValue}</span>
{hasIcon(props.suffixIcon) && <span>{props.suffixIcon}</span>}
</>
);
},
(nodeValue) => {
const timestamp = Number(nodeValue.text.value);
return !isNaN(timestamp)
? timestampToHumanReadable(timestamp)
: nodeValue.text.value;
},
getBaseValue
)
.setEditViewFn((props) => (
<DateEdit
value={props.value}
onChange={props.onChange}
onChangeEnd={props.onChangeEnd}
showTime={true} // Ensures only time is shown
inputFormat={inputFormat}
/>
))
.setPropertyViewFn((children) => (
<>
{children.text.propertyView({
label: trans("table.columnValue"),
tooltip: ColumnValueTooltip,
})}
{children.prefixIcon.propertyView({
label: trans("button.prefixIcon"),
})}
{children.suffixIcon.propertyView({
label: trans("button.suffixIcon"),
})}
{formatPropertyView({ children, placeholder: TIME_FORMAT })}
</>
))
.build();
})();
1 change: 1 addition & 0 deletions client/packages/lowcoder/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,7 @@ export const en = {
"tag": "Tag",
"select": "Select",
"dropdown": "Dropdown",
"time" : "Time",
"date": "Date",
"dateTime": "Date Time",
"badgeStatus": "Status",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>net.snowflake</groupId>
<artifactId>snowflake-jdbc</artifactId>
<version>3.13.33</version>
<version>3.22.0</version>
</dependency>
<dependency>
<groupId>org.lowcoder</groupId>
Expand Down
Loading