- Notifications
You must be signed in to change notification settings - Fork254
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
0d98992
Bump net.snowflake:snowflake-jdbc
dependabot[bot]8b1fe15
Merge branch 'main' into dependabot/maven/server/api-service/lowcoder…
FalkWolskyd756177
Merge pull request #1500 from lowcoder-org/dependabot/maven/server/ap…
FalkWolsky082e574
add time component in dropdown #1549
iamfaran76a3b3e
add suffix/prefix functionality in time #1549
iamfaran8a100b5
[Fix]: Address Issues in Time-Only Column Type Table Component (#1549)
iamfarance21056
[Fix]: Add Prefix/Suffix icons in Time-Only Column Type Table Compone…
iamfaran2888b68
Merge branch 'dev' into staging
raheeliftikhar5File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletionsclient/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComp.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletionsclient/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComps/columnTimeComp.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { default as TimePicker } from "antd/es/time-picker"; | ||
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 dayjs from "dayjs"; | ||
import { useEffect, useRef, useState } from "react"; | ||
import styled from "styled-components"; | ||
import { TIME_FORMAT } from "util/dateTimeUtils"; | ||
import { hasIcon } from "comps/utils"; | ||
import { IconControl } from "comps/controls/iconControl"; | ||
const TimePickerStyled = styled(TimePicker)<{ $open: boolean }>` | ||
width: 100%; | ||
height: 100%; | ||
position: absolute; | ||
top: 0; | ||
padding: 0; | ||
padding-left: 11px; | ||
.ant-picker-input { | ||
height: 100%; | ||
} | ||
input { | ||
padding-right: 18px; | ||
cursor: pointer; | ||
} | ||
&.ant-picker-focused .ant-picker-suffix svg g { | ||
stroke: ${(props) => props.$open && "#315EFB"}; | ||
} | ||
.ant-picker-suffix { | ||
height: calc(100% - 1px); | ||
position: absolute; | ||
right: 0; | ||
top: 0.5px; | ||
display: flex; | ||
align-items: center; | ||
padding: 0 3px; | ||
} | ||
`; | ||
const Wrapper = styled.div` | ||
background: transparent !important; | ||
`; | ||
export function formatTime(time: string, format: string) { | ||
const parsedTime = dayjs(time, TIME_FORMAT); | ||
return parsedTime.isValid() ? parsedTime.format(format) : ""; | ||
} | ||
const childrenMap = { | ||
text: StringControl, | ||
prefixIcon: IconControl, | ||
suffixIcon: IconControl, | ||
format: withDefault(StringControl, TIME_FORMAT), | ||
inputFormat: withDefault(StringControl, TIME_FORMAT), | ||
}; | ||
let inputFormat = TIME_FORMAT; | ||
const getBaseValue: ColumnTypeViewFn<typeof childrenMap, string, string> = (props) => props.text; | ||
type TimeEditProps = { | ||
value: string; | ||
onChange: (value: string) => void; | ||
onChangeEnd: () => void; | ||
inputFormat: string; | ||
}; | ||
export const TimeEdit = (props: TimeEditProps) => { | ||
const pickerRef = useRef<any>(); | ||
const [panelOpen, setPanelOpen] = useState(true); | ||
let value = dayjs(props.value, TIME_FORMAT); | ||
if (!value.isValid()) { | ||
value = dayjs("00:00:00", TIME_FORMAT); | ||
} | ||
const [tempValue, setTempValue] = useState<dayjs.Dayjs | null>(value); | ||
useEffect(() => { | ||
const value = props.value ? dayjs(props.value, TIME_FORMAT) : null; | ||
setTempValue(value); | ||
}, [props.value]); | ||
return ( | ||
<Wrapper | ||
onKeyDown={(e) => { | ||
if (e.key === "Enter" && !panelOpen) { | ||
props.onChangeEnd(); | ||
} | ||
}} | ||
onMouseDown={(e) => { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
}} | ||
> | ||
<TimePickerStyled | ||
ref={pickerRef} | ||
$open={panelOpen} | ||
format={props.inputFormat} | ||
allowClear={true} | ||
autoFocus | ||
value={tempValue} | ||
defaultOpen={true} | ||
onOpenChange={(open) => setPanelOpen(open)} | ||
onChange={(value, timeString) => { | ||
props.onChange(timeString as string); | ||
}} | ||
onBlur={() => props.onChangeEnd()} | ||
/> | ||
</Wrapper> | ||
); | ||
}; | ||
export const TimeComp = (function () { | ||
return new ColumnTypeCompBuilder( | ||
childrenMap, | ||
(props, dispatch) => { | ||
inputFormat = props.inputFormat; | ||
const value = props.changeValue ?? getBaseValue(props, dispatch); | ||
return( | ||
<> | ||
{hasIcon(props.prefixIcon) && ( | ||
<span>{props.prefixIcon}</span> | ||
)} | ||
<span>{value}</span> | ||
{hasIcon(props.suffixIcon) && ( | ||
<span>{props.suffixIcon}</span> | ||
)} | ||
</> | ||
); | ||
}, | ||
(nodeValue) => formatTime(nodeValue.text.value, nodeValue.format.value), | ||
getBaseValue | ||
) | ||
.setEditViewFn((props) => ( | ||
<TimeEdit | ||
value={props.value} | ||
onChange={props.onChange} | ||
onChangeEnd={props.onChangeEnd} | ||
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 deletionsclient/packages/lowcoder/src/i18n/locales/en.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionserver/api-service/lowcoder-plugins/snowflakePlugin/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.