-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1073 enable date/time pattern selection through ColumnSettings (#1087)
* #1073 enable date/time pattern selection through ColumnSettings - converges date and time column types to one unified date/time type, consistent with how some major programming languages handles datetime. - date/time pattern selection is only available for columns with "date/time" type. - changes DateTimePattern to be an object instead of strings to enable simultaneous selection of both date and time patterns. - also moves DateTimeColumnDescriptor to vuu-table-types package for consistency. * #1073 add ability to switch inferred column type for long columns - users can now declare the type of long columns as plain number or date/time. - removed isSimpleColumnType as its no longer needed. - added a timestamps (long) column in showcase's instruments-extended table. * #1073 use unformatted initial value for input-cell renderers * #1073 only show supported cell renderers for boolean columns
- Loading branch information
1 parent
733068a
commit 4e88476
Showing
31 changed files
with
458 additions
and
173 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
118 changes: 118 additions & 0 deletions
118
...i/packages/vuu-table-extras/src/column-formatting-settings/DateTimeFormattingSettings.tsx
This file contains 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,118 @@ | ||
import React, { SyntheticEvent, useCallback, useMemo, useState } from "react"; | ||
import { Dropdown, SingleSelectionHandler } from "@finos/vuu-ui-controls"; | ||
import { | ||
DateTimePattern, | ||
defaultPatternsByType, | ||
fallbackDateTimePattern, | ||
getTypeFormattingFromColumn, | ||
supportedDateTimePatterns, | ||
} from "@finos/vuu-utils"; | ||
import { | ||
FormField, | ||
FormFieldLabel, | ||
ToggleButton, | ||
ToggleButtonGroup, | ||
} from "@salt-ds/core"; | ||
import { DateTimeColumnDescriptor } from "@finos/vuu-table-types"; | ||
import { FormattingSettingsProps } from "./types"; | ||
|
||
export const DateTimeFormattingSettings: React.FC< | ||
FormattingSettingsProps<DateTimeColumnDescriptor> | ||
> = ({ column, onChangeFormatting: onChange }) => { | ||
const formatting = getTypeFormattingFromColumn(column); | ||
const { pattern = fallbackDateTimePattern } = formatting; | ||
const toggleValue = useMemo(() => getToggleValue(pattern), [pattern]); | ||
|
||
const [fallbackState, setFallbackState] = useState<Required<DateTimePattern>>( | ||
{ | ||
time: pattern.time ?? defaultPatternsByType.time, | ||
date: pattern.date ?? defaultPatternsByType.date, | ||
} | ||
); | ||
|
||
const onPatternChange = useCallback( | ||
(pattern: DateTimePattern) => onChange({ ...formatting, pattern }), | ||
[onChange, formatting] | ||
); | ||
|
||
const onDropdownChange = useCallback< | ||
<T extends keyof DateTimePattern>( | ||
key: T | ||
) => SingleSelectionHandler<Required<DateTimePattern>[T]> | ||
>( | ||
(key) => (_, p) => { | ||
const updatedPattern = { ...(pattern ?? {}), [key]: p }; | ||
setFallbackState((s) => ({ | ||
time: updatedPattern.time ?? s.time, | ||
date: updatedPattern.date ?? s.date, | ||
})); | ||
onPatternChange(updatedPattern); | ||
}, | ||
[onPatternChange, pattern] | ||
); | ||
|
||
const onToggleChange = useCallback( | ||
(evnt: SyntheticEvent<HTMLButtonElement, Event>) => { | ||
const value = evnt.currentTarget.value as ToggleValue; | ||
switch (value) { | ||
case "time": | ||
return onPatternChange({ | ||
[value]: pattern[value] ?? fallbackState[value], | ||
}); | ||
case "date": | ||
return onPatternChange({ | ||
[value]: pattern[value] ?? fallbackState[value], | ||
}); | ||
case "both": | ||
return onPatternChange({ | ||
time: pattern.time ?? fallbackState.time, | ||
date: pattern.date ?? fallbackState.date, | ||
}); | ||
} | ||
}, | ||
[onPatternChange, pattern, fallbackState] | ||
); | ||
|
||
return ( | ||
<> | ||
<FormField labelPlacement="left"> | ||
<FormFieldLabel>{"Display"}</FormFieldLabel> | ||
<ToggleButtonGroup | ||
className="vuuToggleButtonGroup" | ||
onChange={onToggleChange} | ||
value={toggleValue} | ||
> | ||
{toggleValues.map((v) => ( | ||
<ToggleButton key={v} value={v}> | ||
{v.toUpperCase()} | ||
</ToggleButton> | ||
))} | ||
</ToggleButtonGroup> | ||
</FormField> | ||
|
||
{(["date", "time"] as const) | ||
.filter((v) => !!pattern[v]) | ||
.map((v) => ( | ||
<FormField labelPlacement="left" key={v}> | ||
<FormFieldLabel>{`${labelByType[v]} pattern`}</FormFieldLabel> | ||
<Dropdown<Required<DateTimePattern>[typeof v]> | ||
onSelectionChange={onDropdownChange(v)} | ||
selected={pattern[v]} | ||
source={supportedDateTimePatterns[v]} | ||
width="100%" | ||
/> | ||
</FormField> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
const labelByType = { date: "Date", time: "Time" } as const; | ||
|
||
const toggleValues = ["date", "time", "both"] as const; | ||
|
||
type ToggleValue = (typeof toggleValues)[number]; | ||
|
||
function getToggleValue(pattern: DateTimePattern): ToggleValue { | ||
return !pattern.time ? "date" : !pattern.date ? "time" : "both"; | ||
} |
6 changes: 6 additions & 0 deletions
6
...i/packages/vuu-table-extras/src/column-formatting-settings/LongTypeFormattingSettings.css
This file contains 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,6 @@ | ||
.vuuLongColumnFormattingSettings { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 4px; | ||
padding-top: 6px; | ||
} |
58 changes: 58 additions & 0 deletions
58
...i/packages/vuu-table-extras/src/column-formatting-settings/LongTypeFormattingSettings.tsx
This file contains 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,58 @@ | ||
import React, { useCallback } from "react"; | ||
import { | ||
FormField, | ||
FormFieldLabel, | ||
ToggleButton, | ||
ToggleButtonGroup, | ||
} from "@salt-ds/core"; | ||
import { isDateTimeColumn, isTypeDescriptor } from "@finos/vuu-utils"; | ||
import { DateTimeFormattingSettings } from "./DateTimeFormattingSettings"; | ||
import { BaseNumericFormattingSettings } from "./BaseNumericFormattingSettings"; | ||
import { FormattingSettingsProps } from "./types"; | ||
|
||
import "./LongTypeFormattingSettings.css"; | ||
|
||
const classBase = "vuuLongColumnFormattingSettings"; | ||
|
||
export const LongTypeFormattingSettings: React.FC<FormattingSettingsProps> = ( | ||
props | ||
) => { | ||
const { column, onChangeType } = props; | ||
const type = isTypeDescriptor(column.type) ? column.type.name : column.type; | ||
|
||
const handleToggleChange = useCallback( | ||
(event: React.SyntheticEvent<HTMLButtonElement, Event>) => { | ||
const value = event.currentTarget.value as ToggleValue; | ||
onChangeType(value); | ||
}, | ||
[onChangeType] | ||
); | ||
|
||
return ( | ||
<div className={classBase}> | ||
<FormField> | ||
<FormFieldLabel>{"Type inferred as"}</FormFieldLabel> | ||
<ToggleButtonGroup | ||
className="vuuToggleButtonGroup" | ||
onChange={handleToggleChange} | ||
value={type ?? "number"} | ||
> | ||
{toggleValues.map((v) => ( | ||
<ToggleButton key={v} value={v}> | ||
{v.toUpperCase()} | ||
</ToggleButton> | ||
))} | ||
</ToggleButtonGroup> | ||
</FormField> | ||
|
||
{isDateTimeColumn(column) ? ( | ||
<DateTimeFormattingSettings {...props} column={column} /> | ||
) : ( | ||
<BaseNumericFormattingSettings {...props} /> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
const toggleValues = ["number", "date/time"] as const; | ||
type ToggleValue = (typeof toggleValues)[number]; |
3 changes: 2 additions & 1 deletion
3
vuu-ui/packages/vuu-table-extras/src/column-formatting-settings/index.ts
This file contains 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./ColumnFormattingPanel"; | ||
export * from "./NumericFormattingSettings"; | ||
export * from "./BaseNumericFormattingSettings"; | ||
export * from "./DateTimeFormattingSettings"; |
Oops, something went wrong.