Skip to content

Commit

Permalink
Restore placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Jan 25, 2024
1 parent 1ebffce commit c28f1d1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
import { DateDisplayField } from 'core-app/shared/components/fields/display/field-types/date-display-field.module';

export class CombinedDateDisplayField extends DateDisplayField {
text = {
placeholder: {
startDate: this.I18n.t('js.label_no_start_date'),
dueDate: this.I18n.t('js.label_no_due_date'),
date: this.I18n.t('js.label_no_date'),
},
};

public render(element:HTMLElement):void {
if (this.name === 'date') {
this.renderSingleDate('date', element);
Expand All @@ -41,7 +49,7 @@ export class CombinedDateDisplayField extends DateDisplayField {
}

if (!this.startDate && !this.dueDate) {
element.innerHTML = this.placeholder;
element.innerHTML = this.customPlaceholder(`${this.text.placeholder.startDate} - ${this.text.placeholder.dueDate}`);
return;
}

Expand All @@ -52,11 +60,12 @@ export class CombinedDateDisplayField extends DateDisplayField {
return false;
}

get placeholder():string {
customPlaceholder(fallback:string):string {
if (typeof this.context.options.placeholder === 'string') {
return this.context.options.placeholder;
}
return super.placeholder;

return fallback;
}

private get startDate():string|null {
Expand Down Expand Up @@ -95,7 +104,12 @@ export class CombinedDateDisplayField extends DateDisplayField {
const dateElement = document.createElement('span');
const dateDisplayField = new DateDisplayField(date, this.context);
dateDisplayField.apply(this.resource, this.schema);
dateDisplayField.render(dateElement, dateDisplayField.valueString);

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const text = this.resource[date]
? dateDisplayField.valueString
: this.customPlaceholder(this.text.placeholder[date]);
dateDisplayField.render(dateElement, text);

return dateElement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class DateDisplayField extends HighlightableDisplayField {

public get valueString() {
if (this.value) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return this.timezoneService.formattedDate(this.value, this.context.options.dateFormat);
}
return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
split_create.expect_and_dismiss_toaster(message: I18n.t('js.notice_successful_create'))

split_create.expect_attributes(
combinedDate: "#{start_of_week.strftime('%m/%d/%Y')} - #{start_of_week.strftime('%m/%d/%Y')}",
combinedDate: start_of_week.strftime('%m/%d/%Y'),
assignee: user.name
)

Expand Down
2 changes: 1 addition & 1 deletion spec/features/work_packages/details/date_editor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@

start_date.save!
start_date.expect_inactive!
start_date.expect_state_text "#{Time.zone.today.strftime('%Y-%m-%d')} - #{Time.zone.today.strftime('%Y-%m-%d')}"
start_date.expect_state_text Time.zone.today.strftime('%Y-%m-%d')
end

it 'can set a negative duration which gets transformed (Regression #44219)' do
Expand Down

0 comments on commit c28f1d1

Please sign in to comment.