Skip to content

Commit 082e574

Browse files
committedFeb 28, 2025
add time component in dropdown lowcoder-org#1549
1 parent d756177 commit 082e574

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
 

‎client/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComp.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CellProps } from "components/table/EditableCell";
22
import { DateTimeComp } from "comps/comps/tableComp/column/columnTypeComps/columnDateTimeComp";
3+
import { TimeComp } from "./columnTypeComps/columnTimeComp";
34
import { ButtonComp } from "comps/comps/tableComp/column/simpleColumnTypeComps";
45
import { withType } from "comps/generators";
56
import { trans } from "i18n";
@@ -67,6 +68,11 @@ const actionOptions = [
6768
label: trans("table.image"),
6869
value: "image",
6970
},
71+
{
72+
label: trans("table.time"),
73+
value: "time",
74+
},
75+
7076
{
7177
label: trans("table.date"),
7278
value: "date",
@@ -116,6 +122,7 @@ export const ColumnTypeCompMap = {
116122
rating: RatingComp,
117123
progress: ProgressComp,
118124
date: DateComp,
125+
time: TimeComp,
119126
};
120127

121128
type ColumnTypeMapType = typeof ColumnTypeCompMap;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import {
2+
ColumnTypeCompBuilder,
3+
ColumnTypeViewFn,
4+
} from "comps/comps/tableComp/column/columnTypeCompBuilder";
5+
import { ColumnValueTooltip } from "comps/comps/tableComp/column/simpleColumnTypeComps";
6+
import { StringControl } from "comps/controls/codeControl";
7+
import { withDefault } from "comps/generators";
8+
import { formatPropertyView } from "comps/utils/propertyUtils";
9+
import { trans } from "i18n";
10+
import {
11+
TIME_FORMAT,
12+
formatTimestamp,
13+
timestampToHumanReadable,
14+
} from "util/dateTimeUtils";
15+
import { DateEdit } from "./columnDateComp";
16+
17+
const childrenMap = {
18+
text: StringControl,
19+
format: withDefault(StringControl, TIME_FORMAT),
20+
inputFormat: withDefault(StringControl, TIME_FORMAT),
21+
};
22+
23+
let inputFormat = TIME_FORMAT;
24+
25+
const getBaseValue: ColumnTypeViewFn<typeof childrenMap, string, string> = (props) =>
26+
props.text;
27+
28+
export const TimeComp = (function () {
29+
return new ColumnTypeCompBuilder(
30+
childrenMap,
31+
(props, dispatch) => {
32+
inputFormat = props.inputFormat;
33+
const value = props.changeValue ?? getBaseValue(props, dispatch);
34+
35+
// Convert value to a number if it's a valid timestamp
36+
const timestamp = Number(value);
37+
if (!isNaN(timestamp)) {
38+
return formatTimestamp(timestamp);
39+
}
40+
41+
return timestampToHumanReadable(timestamp) ?? value; // Returns readable time
42+
},
43+
(nodeValue) => {
44+
const timestamp = Number(nodeValue.text.value);
45+
return !isNaN(timestamp)
46+
? timestampToHumanReadable(timestamp) // Convert to readable format if valid timestamp
47+
: nodeValue.text.value; // Otherwise, return original value
48+
},
49+
getBaseValue
50+
)
51+
.setEditViewFn((props) => (
52+
<DateEdit
53+
value={props.value}
54+
onChange={props.onChange}
55+
onChangeEnd={props.onChangeEnd}
56+
showTime={true} // Ensures only time is shown
57+
inputFormat={inputFormat}
58+
/>
59+
))
60+
.setPropertyViewFn((children) => (
61+
<>
62+
{children.text.propertyView({
63+
label: trans("table.columnValue"),
64+
tooltip: ColumnValueTooltip,
65+
})}
66+
{formatPropertyView({ children, placeholder: TIME_FORMAT })}
67+
</>
68+
))
69+
.build();
70+
})();
71+

‎client/packages/lowcoder/src/i18n/locales/en.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,7 @@ export const en = {
20292029
"tag": "Tag",
20302030
"select": "Select",
20312031
"dropdown": "Dropdown",
2032+
"time" : "Time",
20322033
"date": "Date",
20332034
"dateTime": "Date Time",
20342035
"badgeStatus": "Status",

0 commit comments

Comments
 (0)
Failed to load comments.