Skip to content

Commit

Permalink
datetime type fields not respecting empty default value #853
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Sep 23, 2024
1 parent dc23aba commit 8b95468
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- [#842](https://github.com/estruyf/vscode-front-matter/issues/842): Allow to set the `frontMatter.taxonomy.slugTemplate` setting to an empty string
- [#845](https://github.com/estruyf/vscode-front-matter/issues/845): Fix empty values for number fields
- [#849](https://github.com/estruyf/vscode-front-matter/issues/849): Show fields which are not empty in the metadata panel
- [#853](https://github.com/estruyf/vscode-front-matter/issues/853): Allow empty values in date fields

### 🚧 Work in progress

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/ArticleHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export class ArticleHelper {
const dateFields = contentType.fields.filter((field) => field.type === 'datetime');

for (const dateField of dateFields) {
if (typeof article?.data[dateField.name] !== 'undefined') {
if (article?.data[dateField.name]) {
article.data[dateField.name] = Article.formatDate(new Date(), dateField.dateFormat);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/panelWebView/components/Collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const Collapsible: React.FunctionComponent<ICollapsibleProps> = ({
title={title}
onClick={triggerClick}
open={isOpen}>
<div className={`section collapsible__body ${className || ''}`}>
<div className={`section collapsible__body overflow-y-auto ${className || ''}`}>
{children}
</div>
</VSCodePane>
Expand Down
2 changes: 1 addition & 1 deletion src/panelWebView/components/Fields/DateTimeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const DateTimeField: React.FunctionComponent<IDateTimeFieldProps> = ({

<div className={`metadata_field__datetime`}>
<DatePicker
selected={(DateHelper.tryParse(dateValue, format) as Date) || new Date()}
selected={(DateHelper.tryParse(dateValue, format) as Date) || null}
onChange={onDateChange}
timeInputLabel={l10n.t(LocalizationKey.panelFieldsDateTimeFieldTime)}
dateFormat={DateHelper.formatUpdate(format) || DEFAULT_FORMAT}
Expand Down
2 changes: 1 addition & 1 deletion src/panelWebView/components/Fields/WrapperField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const WrapperField: React.FunctionComponent<IWrapperFieldProps> = ({
}

if (field.type === 'datetime') {
value = getDate(value) || undefined;
value = value ? getDate(value) : undefined;
}

if (value === undefined && field.default) {
Expand Down

0 comments on commit 8b95468

Please sign in to comment.