-
-
Notifications
You must be signed in to change notification settings - Fork 11
835-fix: Stale data on the website #843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 11 commits
224911c
0c156e3
12dc5c8
fe5f8c4
80f6eaa
fd466c5
816f2e2
c2fd57a
ab878d2
2de9ce5
6413da6
5ffacbb
6dc48b6
ec6cd2b
01d9171
d90c937
9927125
cba7bad
c6d3310
4719ecb
6e96876
2a14c70
6ea440b
7e24a3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use client'; | ||
|
||
import type { Course } from '@/entities/course'; | ||
import { getActualData } from '@/shared/helpers/getActualData'; | ||
import { SchoolMenu } from '@/widgets/school-menu'; | ||
|
||
type AllCoursesProps = { | ||
courses: Course[]; | ||
}; | ||
|
||
const AllCourses = ({ courses }: AllCoursesProps) => { | ||
const actualCourses = getActualData({ | ||
data: courses, | ||
filterStale: false, | ||
sort: false, | ||
}); | ||
|
||
return actualCourses.map((course) => ( | ||
<SchoolMenu.Item | ||
key={course.id} | ||
icon={course.iconFooter} | ||
title={course.title} | ||
description={course.startDate} | ||
url={course.detailsUrl} | ||
color="light" | ||
/> | ||
)); | ||
}; | ||
|
||
export default AllCourses; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to use default export here and in the Header? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replaced with named export |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use client'; | ||
|
||
import { Course } from '@/entities/course'; | ||
import { getActualData } from '@/shared/helpers/getActualData'; | ||
import { SchoolMenu } from '@/widgets/school-menu'; | ||
|
||
type AllCoursesProps = { | ||
courses: Course[]; | ||
}; | ||
|
||
const AllCourses = ({ courses }: AllCoursesProps) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I can see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
const actualCourses = getActualData({ | ||
data: courses, | ||
filterStale: false, | ||
sort: false, | ||
}); | ||
|
||
return actualCourses.map((course) => ( | ||
<SchoolMenu.Item | ||
key={course.id} | ||
icon={course.iconSmall} | ||
title={course.title} | ||
description={course.startDate} | ||
url={course.detailsUrl} | ||
/> | ||
)); | ||
}; | ||
|
||
export default AllCourses; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,18 +11,36 @@ type GetActualDataParams<T extends DataType> = { | |||||||||||||||||||||
data: T; | ||||||||||||||||||||||
staleAfter?: number; | ||||||||||||||||||||||
filterStale?: boolean; | ||||||||||||||||||||||
isMentorship?: boolean; | ||||||||||||||||||||||
sort?: boolean; | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
|
||||||||||||||||||||||
type GetActualDataType = <T extends DataType>(params: GetActualDataParams<T>) => T; | ||||||||||||||||||||||
|
||||||||||||||||||||||
export const getActualData: GetActualDataType = ({ data, staleAfter, filterStale = true }) => { | ||||||||||||||||||||||
let dataWithTBD = mapStaleAsTBD(data, staleAfter); | ||||||||||||||||||||||
export const getActualData: GetActualDataType = ({ | ||||||||||||||||||||||
data, | ||||||||||||||||||||||
staleAfter, | ||||||||||||||||||||||
filterStale = true, | ||||||||||||||||||||||
isMentorship = false, | ||||||||||||||||||||||
sort = true, | ||||||||||||||||||||||
}) => { | ||||||||||||||||||||||
let dataWithTBD; | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could avoid variable reassignment. I suggest several changes below. The same in the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||||||||||||||||||
|
||||||||||||||||||||||
if (isMentorship) { | ||||||||||||||||||||||
dataWithTBD = mapMentorshipStaleAsTBD(data); | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
dataWithTBD = mapStaleAsTBD(data, staleAfter); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO this refactoring should be made in separate task, since it's require to change the functions inner and types logic |
||||||||||||||||||||||
|
||||||||||||||||||||||
if (filterStale) { | ||||||||||||||||||||||
dataWithTBD = filterStaleData(dataWithTBD); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we avoid variable reassignment? |
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return sortData(dataWithTBD); | ||||||||||||||||||||||
if (sort) { | ||||||||||||||||||||||
dataWithTBD = sortData(dataWithTBD); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return dataWithTBD; | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
|
||||||||||||||||||||||
const mapStaleAsTBD = <T extends DataType>(data: T, staleAfter?: number): T => | ||||||||||||||||||||||
|
@@ -45,6 +63,37 @@ const mapStaleAsTBD = <T extends DataType>(data: T, staleAfter?: number): T => | |||||||||||||||||||||
}; | ||||||||||||||||||||||
}) as T; | ||||||||||||||||||||||
|
||||||||||||||||||||||
const mapMentorshipStaleAsTBD = <T extends DataType>(data: T): T => { | ||||||||||||||||||||||
if ('eventType' in data) { | ||||||||||||||||||||||
return data; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return (data as Course[]).map((item) => { | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose if we assign the code below to a variable and then return it, it will be more readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||||||||||||||||||
const date = item.personalMentoringStartDate; | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||||||||||||||||||
|
||||||||||||||||||||||
if (!date) { | ||||||||||||||||||||||
return item; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
const daysBeforeStale = dayJS(item.personalMentoringEndDate).diff( | ||||||||||||||||||||||
item.personalMentoringStartDate, | ||||||||||||||||||||||
'd', | ||||||||||||||||||||||
); | ||||||||||||||||||||||
|
||||||||||||||||||||||
const startDate = getCourseDate(date, daysBeforeStale); | ||||||||||||||||||||||
Quiddlee marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
|
||||||||||||||||||||||
if (startDate === TO_BE_DETERMINED) { | ||||||||||||||||||||||
return { | ||||||||||||||||||||||
...item, | ||||||||||||||||||||||
personalMentoringStartDate: null, | ||||||||||||||||||||||
personalMentoringEndDate: null, | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return item; | ||||||||||||||||||||||
}) as T; | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
|
||||||||||||||||||||||
const filterStaleData = <T extends DataType>(data: T): T => | ||||||||||||||||||||||
data.filter((item) => { | ||||||||||||||||||||||
const date = isCourse(item) ? item.startDate : item.date; | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use client'; | ||
|
||
import { PropsWithChildren } from 'react'; | ||
|
||
import { calculateFreshDate } from '@/shared/helpers/getCourseDate'; | ||
import { DateSimple } from '@/shared/ui/date-simple'; | ||
|
||
type CourseStartLabelProps = PropsWithChildren & { | ||
startDate: string | null; | ||
registrationEndDate: string | null; | ||
label: string | undefined; | ||
}; | ||
|
||
export const CourseStartLabel = ({ | ||
startDate, | ||
registrationEndDate, | ||
label, | ||
children, | ||
}: CourseStartLabelProps) => { | ||
const freshDate = | ||
startDate && registrationEndDate ? calculateFreshDate(startDate, registrationEndDate) : null; | ||
|
||
return ( | ||
<DateSimple label={label} startDate={freshDate}> | ||
{children} | ||
</DateSimple> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
|
||
import { Course, CourseCard } from '@/entities/course'; | ||
import { getActualData } from '@/shared/helpers/getActualData'; | ||
import { | ||
transformCoursesToMentorship, | ||
} from '@/views/mentorship/helpers/transformCoursesToMentorship'; | ||
|
||
type CourseItems = { | ||
courses: Course[]; | ||
className: string; | ||
}; | ||
|
||
const CourseItems = ({ courses, className }: CourseItems) => { | ||
const actualCourses = getActualData({ | ||
data: courses, | ||
filterStale: false, | ||
isMentorship: true, | ||
sort: false, | ||
}); | ||
const coursesWithMentorship = transformCoursesToMentorship(actualCourses); | ||
|
||
return coursesWithMentorship.map((course) => ( | ||
<CourseCard key={course.id} className={className} {...course} showMentoringStartDate={true} /> | ||
)); | ||
}; | ||
|
||
export default CourseItems; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use client'; | ||
|
||
import { Course, CourseCard } from '@/entities/course'; | ||
import { getActualData } from '@/shared/helpers/getActualData'; | ||
|
||
type CourseItemsProps = { | ||
courses: Course[]; | ||
}; | ||
|
||
const CourseItems = ({ courses }: CourseItemsProps) => { | ||
const actualCourses = getActualData({ | ||
data: courses, | ||
filterStale: false, | ||
}); | ||
|
||
return ( | ||
actualCourses.map((course) => | ||
<CourseCard size="sm" key={course.id} {...course} />, | ||
) | ||
); | ||
}; | ||
|
||
export default CourseItems; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use client'; | ||
|
||
import { dayJS } from '@/shared/helpers/dayJS'; | ||
import { SectionLabel } from '@/shared/ui/section-label'; | ||
import { getCourseStatus } from '@/widgets/hero-course/helpers/get-course-status'; | ||
|
||
type AvailabilityStatusProps = { | ||
startDate: string; | ||
registrationEndDate: string; | ||
}; | ||
|
||
export const AvailabilityStatus = ({ startDate, registrationEndDate }: AvailabilityStatusProps) => { | ||
const status = getCourseStatus(startDate, dayJS(registrationEndDate).diff(startDate, 'd')); | ||
|
||
return <SectionLabel data-testid="course-label">{status}</SectionLabel>; | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.