Skip to content

Commit 0e26f72

Browse files
jase156ridouku
authored andcommitted
fix: TT-290 add method to avoid text overflow
1 parent b6a3fa4 commit 0e26f72

File tree

5 files changed

+85
-4
lines changed

5 files changed

+85
-4
lines changed

src/app/modules/time-entries/components/calendar/calendar.component.html

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
{{ timeEntries.end_date | date: 'HH:mm' }}
2323
</p>
2424
</div>
25+
<div
26+
*ngIf="
27+
isVisibleForCurrentView(calendarView, CalendarViewEnum.Week) ||
28+
isVisibleForCurrentView(calendarView, CalendarViewEnum.Day)
29+
"
30+
>
31+
<p
32+
class="additional {{ 'line-' + getCardEntryHeight(timeEntries.start_date, timeEntries.end_date) }}"
33+
*ngIf="timeIsGreaterThan(timeEntries.start_date, timeEntries.end_date, 60)"
34+
>
35+
{{ timeEntries.description }}
36+
</p>
37+
</div>
2538
</div>
2639
</ng-template>
2740

@@ -140,15 +153,15 @@
140153
*ngSwitchCase="CalendarViewEnum.Week"
141154
[viewDate]="currentDate"
142155
[events]="timeEntriesAsEvent"
143-
[hourSegmentHeight]="60"
156+
[hourSegmentHeight]="HALF_HOUR * VARIATION_HEIGHT"
144157
[eventTemplate]="timeEntriesInsideDaysCalendarTemplate"
145158
>
146159
</mwl-calendar-week-view>
147160
<mwl-calendar-day-view
148161
*ngSwitchCase="CalendarViewEnum.Day"
149162
[viewDate]="currentDate"
150163
[events]="timeEntriesAsEvent"
151-
[hourSegmentHeight]="60"
164+
[hourSegmentHeight]="HALF_HOUR * VARIATION_HEIGHT"
152165
[eventTemplate]="timeEntriesInsideDaysCalendarTemplate"
153166
>
154167
</mwl-calendar-day-view>

src/app/modules/time-entries/components/calendar/calendar.component.scss

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
@import '/src/styles/colors.scss';
2+
@import '/src/styles/vars.scss';
3+
4+
$line-height-value: $line-height-base * $font-size-base;
5+
6+
$max-lines-project: 2;
7+
$max-lines-activity: 1;
8+
$max-lines-description: 50;
9+
$container-time-entries-margin: 0.125;
10+
$time-entries-padding: 0.5rem;
11+
$project-name-line-height: 1;
12+
13+
$project-text-size: $max-lines-project * $project-name-line-height;
14+
$activity-text-size: $max-lines-activity * $line-height-base;
215

316
@function calculate-border-color($base-background-color) {
417
@return darken(desaturate(adjust-hue($base-background-color, 6), 18), 27);
@@ -8,12 +21,29 @@
821
@return darken(saturate(adjust-hue($text-color, 6), 46.19), 40.98);
922
}
1023

24+
@for $card-height from 12 through $max-lines-description {
25+
$wrap-height: ($card-height * 0.625rem) -
26+
$project-text-size -
27+
$activity-text-size -
28+
$container-time-entries-margin -
29+
$time-entries-padding;
30+
$line-clamp: ($wrap-height / $line-height-value);
31+
.line-#{$card-height} {
32+
overflow-y: hidden;
33+
height: $wrap-height;
34+
display: -webkit-box;
35+
-webkit-line-clamp: round($line-clamp);
36+
-webkit-box-orient: vertical;
37+
}
38+
}
39+
1140
.container-time-entries {
12-
margin: 2px;
41+
margin: $container-time-entries-margin;
1342
div.time-entries {
14-
padding: 8px;
43+
padding: $time-entries-padding;
1544
height: 100%;
1645
border-radius: 7px;
46+
overflow-y: hidden;
1747
color: $primary-text;
1848
margin: 2px 6px 0px 5px;
1949
background-color: $background-card-entry;
@@ -27,8 +57,12 @@
2757
p.project-name {
2858
color: calculate-bold-text-color($primary-text);
2959
line-height: 1;
60+
display: -webkit-box;
61+
-webkit-line-clamp: $max-lines-project;
62+
-webkit-box-orient: vertical;
3063
}
3164
p.additional {
65+
overflow-wrap: break-word;
3266
color: calculate-bold-text-color($primary-text);
3367
}
3468
}

src/app/modules/time-entries/components/calendar/calendar.component.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,22 @@ describe('CalendarComponent', () => {
314314
expect(result).toBe(expected);
315315
});
316316
});
317+
318+
it('return card entry height multiplied by height variation when call getCardEntryHeight', () => {
319+
[
320+
{ startDate: '2021-04-11T08:00:00Z', endDate: '2021-04-11T10:20:00Z', expected: 28 },
321+
{ startDate: '2021-04-12T17:00:00Z', endDate: '2021-04-12T17:00:00Z', expected: 0 },
322+
{ startDate: '2021-04-11T18:00:00Z', endDate: '2021-04-12T18:00:00Z', expected: 288 },
323+
{ startDate: '2021-04-12T12:00:00Z', endDate: '2021-04-12T12:01:01Z', expected: 0 },
324+
].forEach(({startDate, endDate, expected}) => {
325+
const fakeStartDate = new Date(startDate);
326+
const fakeEndDate = new Date(endDate);
327+
328+
const result = component.getCardEntryHeight(fakeStartDate, fakeEndDate);
329+
330+
expect(result).toBe(expected);
331+
});
332+
333+
334+
});
317335
});

src/app/modules/time-entries/components/calendar/calendar.component.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import { SubstractDatePipe } from 'src/app/modules/shared/pipes/substract-date/s
1616
styleUrls: ['./calendar.component.scss'],
1717
})
1818
export class CalendarComponent implements OnInit {
19+
readonly HALF_HOUR: number = 30;
20+
readonly VARIATION_HEIGHT: number = 2;
21+
1922
@Input() set timeEntries$(timeEntries: Observable<DataSource<Entry>>){
2023
this.castEntryToCalendarEvent(timeEntries);
2124
}
@@ -115,6 +118,12 @@ export class CalendarComponent implements OnInit {
115118
return new SubstractDatePipe().transformInMinutes( endDate , startDate);
116119
}
117120

121+
getCardEntryHeight(startDate: Date, endDate: Date): number{
122+
const heightCard = this.getTimeWork(startDate, endDate) * this.VARIATION_HEIGHT;
123+
const finalHeightCard = heightCard / 10;
124+
return Math.floor(finalHeightCard) ;
125+
}
126+
118127
timeIsGreaterThan(startDate: Date, endDate: Date, timeRange: number ): boolean{
119128
const timeWorkInMinutes = this.getTimeWork(startDate, endDate);
120129
return timeWorkInMinutes > timeRange;

src/styles/vars.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
Font
3+
*/
4+
$font-size-base: 1rem;
5+
$font-family-base: 'Roboto', sans-serif;
6+
$font-weight-base: 400;
7+
$line-height-base: 1.5;

0 commit comments

Comments
 (0)