Skip to content

Commit a14c409

Browse files
committed
fix(tables): default a date conversion to date-only, like a create
Converting a column to Date silently opted it into times while creating one gave date-only. The seed read `existingColumn?.includeTime !== false`, and on a column that is not yet a date that key is simply absent — so the expression answered `true`, and the save sent `includeTime: true` alongside the type change. Only an existing date column now answers from its own value (absent there means a column predating the key, which does hold instants). Every other starting point takes the date-only default a new date column gets. The seed and the dirty-check read one `baselineIncludeTime` so they cannot answer differently.
1 parent 66ab0a9 commit a14c409

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/column-config-sidebar/column-config-sidebar.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ function ColumnConfigBody({
117117
const [typeInput, setTypeInput] = useState<ColumnDefinition['type']>(() =>
118118
config.mode === 'edit' ? (existingColumn?.type ?? 'string') : config.type
119119
)
120+
// What "include time" means for the column as it stands today.
121+
//
122+
// Only an EXISTING date column answers from its own value, where absent means
123+
// a column predating the key and therefore holding instants. Every other
124+
// starting point — creating a column, or converting one that is not yet a
125+
// date — takes the same date-only default a newly created date column gets.
126+
//
127+
// Read off a non-date column, `includeTime !== false` answers `true` (the key
128+
// is simply absent there), which made converting a text column to Date
129+
// silently opt it into times while creating one gave date-only. The seed and
130+
// the dirty-check both read this so they cannot answer differently.
131+
const baselineIncludeTime =
132+
config.mode === 'edit' && existingColumn?.type === 'date'
133+
? existingColumn.includeTime !== false
134+
: false
135+
120136
const [uniqueInput, setUniqueInput] = useState<boolean>(() =>
121137
config.mode === 'edit' ? !!existingColumn?.unique : false
122138
)
@@ -142,11 +158,7 @@ function ColumnConfigBody({
142158
? String(existingColumn.precision)
143159
: ''
144160
)
145-
const [includeTimeInput, setIncludeTimeInput] = useState<boolean>(() =>
146-
// Absent means a column created before the key existed, and those hold
147-
// instants — so the toggle reflects what the column actually stores.
148-
config.mode === 'edit' ? existingColumn?.includeTime !== false : false
149-
)
161+
const [includeTimeInput, setIncludeTimeInput] = useState<boolean>(() => baselineIncludeTime)
150162
const [showValidation, setShowValidation] = useState(false)
151163
const [nameError, setNameError] = useState<string | null>(null)
152164
const [optionsError, setOptionsError] = useState<string | null>(null)
@@ -228,8 +240,7 @@ function ColumnConfigBody({
228240
const currencyChanged =
229241
wantsCurrency && resolveCurrencyCode(existingColumn?.currencyCode) !== currencyInput
230242
const precisionChanged = wantsPrecision && existingColumn?.precision !== parsedPrecision
231-
const includeTimeChanged =
232-
wantsIncludeTime && (existingColumn?.includeTime !== false) !== includeTimeInput
243+
const includeTimeChanged = wantsIncludeTime && baselineIncludeTime !== includeTimeInput
233244

234245
const updates: {
235246
name?: string

0 commit comments

Comments
 (0)