Skip to content

Commit 2c7f47f

Browse files
committed
clean
1 parent 0c53f03 commit 2c7f47f

6 files changed

Lines changed: 24 additions & 41 deletions

File tree

packages/components/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@labkey/components",
3-
"version": "6.45.1-fb-issue53071.1",
3+
"version": "6.45.1-fb-issue53071.2",
44
"description": "Components, models, actions, and utility functions for LabKey applications and pages",
55
"sideEffects": false,
66
"files": [

packages/components/src/internal/components/editable/DateInputCell.tsx

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ import React, { FC, memo, useCallback } from 'react';
33
import { QueryColumn } from '../../../public/QueryColumn';
44

55
import { DatePickerInput } from '../forms/input/DatePickerInput';
6-
import {
7-
formatDate,
8-
formatDateTime,
9-
getJsonTimeFormatString,
10-
getTimeValueFromDatePickerInput,
11-
isDateTimeCol
12-
} from '../../util/Date';
136

147
import { MODIFICATION_TYPES, SELECTION_TYPES } from './constants';
158
import { ValueDescriptor } from './models';
@@ -40,22 +33,11 @@ export const DateInputCell: FC<DateInputCellProps> = memo(props => {
4033
}, [colIdx, rowIdx, select]);
4134

4235
const onDateInputChange = useCallback(
43-
(newDate: Date | string) => {
44-
let display, raw = newDate;
45-
if (newDate && typeof newDate === 'string') display = newDate;
46-
else if (newDate && newDate instanceof Date) {
47-
if (col.isTimeColumn) {
48-
raw = getJsonTimeFormatString(newDate);
49-
display = getTimeValueFromDatePickerInput(newDate, col);
50-
}
51-
else {
52-
display = isDateTimeCol(col)
53-
? formatDateTime(newDate)
54-
: formatDate(newDate);
55-
}
56-
}
57-
58-
modifyCell(colIdx, rowIdx, [{ raw, display }], MODIFICATION_TYPES.REPLACE, col);
36+
(newDate: Date | string, formatted?: string) => {
37+
modifyCell(colIdx, rowIdx, [{
38+
raw: newDate,
39+
display: formatted
40+
}], MODIFICATION_TYPES.REPLACE, col);
5941
},
6042
[col, colIdx, modifyCell, rowIdx]
6143
);

packages/components/src/internal/components/editable/EditableGrid.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { LabelOverlay } from '../forms/LabelOverlay';
4949

5050
import { DropdownMenu } from '../../dropdowns';
5151

52-
import { formatDateTimeDisplayValueForUpdate } from '../../util/Date';
52+
import { getDateTimeDisplayValueFromStr } from '../../util/Date';
5353

5454
import {
5555
addRows,
@@ -879,7 +879,7 @@ export class EditableGrid extends PureComponent<EditableGridProps, EditableGridS
879879
let getDisplayValue = null;
880880
if (qCol.isTimeColumn || qCol.jsonType === 'date') {
881881
getDisplayValue = vd => {
882-
return formatDateTimeDisplayValueForUpdate(vd, qCol);
882+
return getDateTimeDisplayValueFromStr(vd?.raw, qCol);
883883
};
884884
}
885885
gridColumns = gridColumns.push(

packages/components/src/internal/components/forms/input/DatePickerInput.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { FormsyInjectedProps, withFormsy } from '../formsy';
2020
import { FieldLabel } from '../FieldLabel';
2121
import {
2222
getDateFromISO,
23+
getDateTimeDisplayValue,
2324
getJsonDateFormatString,
2425
getJsonDateTimeFormatString,
2526
getJsonTimeFormatString,
@@ -52,7 +53,7 @@ export interface DatePickerInputProps extends DisableableInputProps {
5253
name?: string;
5354
onBlur?: () => void;
5455
onCalendarClose?: () => void;
55-
onChange?: (rawDate?: Date | string) => void;
56+
onChange?: (rawDate?: Date | string, formatted?: string) => void;
5657
onKeyDown?: (event: React.KeyboardEvent<HTMLElement>) => void;
5758
placeholderText?: string;
5859
queryColumn: QueryColumn;
@@ -169,7 +170,8 @@ export class DatePickerInputImpl extends DisableableInput<DatePickerInputImplPro
169170
if (this.state.relativeInputValue) {
170171
onChange?.(this.state.relativeInputValue);
171172
} else {
172-
onChange?.(date);
173+
const formatted = getDateTimeDisplayValue(date, queryColumn);
174+
onChange?.(queryColumn.isTimeColumn ? formatted : date, formatted);
173175

174176
if (formsy) {
175177
this.props.setValue?.(this.getFormsyValue(date));

packages/components/src/internal/util/Date.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { QueryColumn } from '../../public/QueryColumn';
2121

2222
import { TIME_RANGE_URI } from '../components/domainproperties/constants';
2323
import { SelectInputOption } from '../components/forms/input/SelectInput';
24-
import { ValueDescriptor } from '../components/editable/models';
2524

2625
// These constants align with the formats declared in DateUtil.java
2726
export const ISO_DATE_FORMAT_STRING = 'yyyy-MM-dd';
@@ -197,18 +196,17 @@ export function getDateFromISO(
197196
return parseDate(value, undefined, minDate, false, queryColumn.isDateOnlyColumn);
198197
}
199198

200-
export function formatDateTimeDisplayValueForUpdate(vd: ValueDescriptor, queryColumn: QueryColumn): string {
201-
const isoValue = vd?.raw;
202-
if (!isoValue || typeof isoValue !== 'string') return null;
203-
const date = getDateFromISO(isoValue, queryColumn);
199+
export function getDateTimeDisplayValue(date: Date, queryColumn: QueryColumn): string {
204200
const { dateFormat, timeFormat } = getPickerDateAndTimeFormat(queryColumn, false, date);
205-
if (queryColumn.isTimeColumn) return formatTime(isoValue, timeFormat);
206-
return formatDate(date, null, dateFormat);
201+
if (queryColumn.isTimeColumn) return formatTime(date, timeFormat);
202+
if (queryColumn.isDateOnlyColumn) formatDate(date, null, dateFormat);
203+
return formatDateTime(date, null, dateFormat);
207204
}
208205

209-
export function getTimeValueFromDatePickerInput(date: Date, queryColumn: QueryColumn): string {
210-
const { timeFormat } = getPickerDateAndTimeFormat(queryColumn, false, date);
211-
return formatTime(date, timeFormat);
206+
export function getDateTimeDisplayValueFromStr(isoValue: string, queryColumn: QueryColumn): string {
207+
if (!isoValue || typeof isoValue !== 'string') return null;
208+
const date = getDateFromISO(isoValue, queryColumn);
209+
return getDateTimeDisplayValue(date, queryColumn);
212210
}
213211

214212
export function getColDateFormat(column: QueryColumn, dateFormat?: string, dateOnly?: boolean): string {
@@ -739,7 +737,8 @@ export function formatDateTime(date: Date | string | number, timezone?: string,
739737
export function formatTime(timeValue: Date | string, timeFormat?: string): string {
740738
const timeObj = parseTime(timeValue);
741739
if (!timeObj) return undefined;
742-
return format(timeObj, timeFormat ?? getDateFNSTimeFormat());
740+
const _timeFormat = toDateFNSFormatString(timeFormat ?? getDateFNSTimeFormat());
741+
return format(timeObj, _timeFormat);
743742
}
744743

745744
// Issue 44398: see DateUtil.java getJsonDateTimeFormatString(), this function is to match the format, which is

0 commit comments

Comments
 (0)