-
Notifications
You must be signed in to change notification settings - Fork 21
PM-3329 show skills activity details #1419
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
Changes from all commits
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 |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| import { Dispatch, FC, SetStateAction, useEffect, useMemo, useState } from 'react' | ||
| /* eslint-disable complexity */ | ||
| import { Dispatch, FC, SetStateAction, useCallback, useEffect, useMemo, useState } from 'react' | ||
| import { useSearchParams } from 'react-router-dom' | ||
| import { filter, orderBy } from 'lodash' | ||
|
|
||
| import { UserProfile, UserSkill, UserSkillDisplayModes } from '~/libs/core' | ||
| import { getMemberSkillDetails, UserProfile, UserSkill, UserSkillDisplayModes } from '~/libs/core' | ||
| import { GroupedSkillsUI, HowSkillsWorkModal, isSkillVerified, SkillPill, useLocalStorage } from '~/libs/shared' | ||
| import { Button } from '~/libs/ui' | ||
|
|
||
|
|
@@ -23,6 +24,7 @@ interface MemberSkillsInfoProps { | |
| const MemberSkillsInfo: FC<MemberSkillsInfoProps> = (props: MemberSkillsInfoProps) => { | ||
| const [queryParams]: [URLSearchParams, any] = useSearchParams() | ||
| const editMode: string | null = queryParams.get(EDIT_MODE_QUERY_PARAM) | ||
| const [canFetchSkillDetails, setCanFetchSkillDetails] = useState(true) | ||
|
|
||
| const canEdit: boolean = props.authProfile?.handle === props.profile.handle | ||
| const [hasSeenPrincipalIntro, setHasSeenPrincipalIntro] = useLocalStorage('seen-principal-intro', {} as any) | ||
|
|
@@ -131,6 +133,15 @@ const MemberSkillsInfo: FC<MemberSkillsInfoProps> = (props: MemberSkillsInfoProp | |
| setPrincipalIntroModalVisible(false) | ||
| } | ||
|
|
||
| const fetchSkillDetails = useCallback((skillId: string) => getMemberSkillDetails(props.profile.handle, skillId) | ||
| .catch(e => { | ||
| if (e.response.status === 403) { | ||
| setCanFetchSkillDetails(false) | ||
| } | ||
|
|
||
| throw e | ||
| }), [props.profile.handle]) | ||
|
|
||
| return ( | ||
| <div className={styles.container}> | ||
| <div className={styles.titleWrap}> | ||
|
|
@@ -174,6 +185,7 @@ const MemberSkillsInfo: FC<MemberSkillsInfoProps> = (props: MemberSkillsInfoProp | |
| skill={skill} | ||
| key={skill.id} | ||
| theme={isSkillVerified(skill) ? 'verified' : 'dark'} | ||
| fetchSkillDetails={canFetchSkillDetails ? fetchSkillDetails : undefined} | ||
|
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. [ |
||
| /> | ||
| ))} | ||
| </div> | ||
|
|
@@ -188,6 +200,7 @@ const MemberSkillsInfo: FC<MemberSkillsInfoProps> = (props: MemberSkillsInfoProp | |
| )} | ||
| <GroupedSkillsUI | ||
| groupedSkillsByCategory={groupedSkillsByCategory} | ||
| fetchSkillDetails={canFetchSkillDetails ? fetchSkillDetails : undefined} | ||
| /> | ||
| </div> | ||
| )} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { UpdateProfileRequest, UserPhotoUpdateResponse } from '../../modify-user | |
| import { ModifyUserPropertyRequest, ModifyUserPropertyResponse } from '../../modify-user-role.model' | ||
| import { UserEmailPreferences } from '../../user-email-preference.model' | ||
| import { UserProfile } from '../../user-profile.model' | ||
| import { UserSkillWithActivity } from '../../user-skill.model' | ||
| import { UserStats } from '../../user-stats.model' | ||
| import { UserTraits } from '../../user-traits.model' | ||
|
|
||
|
|
@@ -123,3 +124,7 @@ export async function updateMemberPhoto(handle: string, payload: FormData): Prom | |
| export async function downloadProfile(handle: string): Promise<Blob> { | ||
| return xhrGetBlobAsync<Blob>(`${profileUrl(handle)}/profileDownload`) | ||
| } | ||
|
|
||
| export function getMemberSkillDetails(handle: string, skillId: string): Promise<UserSkillWithActivity> { | ||
|
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. [ |
||
| return xhrGetAsync<UserSkillWithActivity>(`${profileUrl(handle)}/skills/${skillId}`) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,4 +38,25 @@ export type UserSkill = { | |
| description?: string | null | undefined | ||
| } | ||
|
|
||
| export type UserSkillActivity = { | ||
| count: number | ||
| lastSources: Array<{ | ||
| id?: string | ||
| completionEventId?: string | ||
| title?: string | ||
| name?: string | ||
| certification?: string | ||
| dashedName?: string | ||
| }> | ||
| } | ||
|
|
||
| export type UserSkillWithActivity = { | ||
| lastUsedDate: string | ||
|
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. [ |
||
| activity: { | ||
| certification?: UserSkillActivity | ||
| course?: UserSkillActivity | ||
| challenge?: UserSkillActivity | ||
| } | ||
| } & UserSkill | ||
|
|
||
| export type SearchUserSkill = Pick<UserSkill, 'id'|'name'> & Partial<Pick<UserSkill, 'levels'>> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| import { FC, ReactNode, useCallback, useMemo } from 'react' | ||
| /* eslint-disable complexity */ | ||
| import { FC, ReactNode, useCallback, useMemo, useState } from 'react' | ||
|
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. [💡 |
||
| import { format } from 'date-fns' | ||
| import classNames from 'classnames' | ||
| import useSWR, { SWRResponse } from 'swr' | ||
|
|
||
| import { IconOutline } from '~/libs/ui' | ||
| import { UserSkill } from '~/libs/core' | ||
| import { EnvironmentConfig } from '~/config' | ||
| import { IconOutline, Tooltip } from '~/libs/ui' | ||
| import { UserSkill, UserSkillWithActivity } from '~/libs/core' | ||
|
|
||
| import { isSkillVerified } from '../../services/standard-skills' | ||
|
|
||
|
|
@@ -12,11 +16,15 @@ export interface SkillPillProps { | |
| children?: ReactNode | ||
| onClick?: (skill: UserSkill) => void | ||
| selected?: boolean | ||
| skill: Partial<Pick<UserSkill, 'name'|'levels'>> | ||
| skill: Partial<Pick<UserSkill, 'id'|'name'|'levels'>> | ||
| theme?: 'dark' | 'verified' | 'presentation' | 'etc' | 'catList' | ||
| fetchSkillDetails?: (skillId: string) => Promise<UserSkillWithActivity> | ||
| } | ||
|
|
||
| const SkillPill: FC<SkillPillProps> = props => { | ||
| const [hideDetails, setHideDetails] = useState(false) | ||
| const [loadDetails, setLoadDetails] = useState(false) | ||
|
|
||
| const isVerified = useMemo(() => ( | ||
| isSkillVerified({ levels: props.skill.levels ?? [] }) | ||
| ), [props.skill]) | ||
|
|
@@ -29,10 +37,103 @@ const SkillPill: FC<SkillPillProps> = props => { | |
| styles[`theme-${props.theme ?? ''}`], | ||
| ) | ||
|
|
||
| const handleMouseEnter = useCallback(() => { | ||
| setLoadDetails(true) | ||
| }, []) | ||
|
|
||
| const handleClick = useCallback(() => props.onClick?.call(undefined, props.skill as UserSkill), [ | ||
| props.onClick, props.skill, | ||
| ]) | ||
|
|
||
| const { data: skillDetails, isValidating: isLoadingDetails }: SWRResponse<UserSkillWithActivity> | ||
| = useSWR<UserSkillWithActivity>( | ||
| loadDetails | ||
| && props.fetchSkillDetails | ||
| && props.skill?.id ? `user-skill-activity/${props.skill.id}` : undefined, | ||
| () => props.fetchSkillDetails!(props.skill.id!) | ||
| .catch(() => { | ||
| setHideDetails(true) | ||
| return {} as any | ||
| }), | ||
| ) | ||
|
|
||
| const skillDetailsTooltipContent = useMemo(() => { | ||
| if (!skillDetails || isLoadingDetails || hideDetails) { | ||
| return 'Loading...' | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <div className={styles.tooltipRow}> | ||
| <strong>Last used:</strong> | ||
| <span>{format(new Date(skillDetails.lastUsedDate), 'MMM dd, yyyy HH:mm')}</span> | ||
| </div> | ||
| <ul className={styles.tooltipDetails}> | ||
| {skillDetails.activity.challenge && ( | ||
| <li> | ||
| <div className={styles.tooltipRow}> | ||
| Challenges ( | ||
| {skillDetails.activity.challenge.count} | ||
| ): | ||
| </div> | ||
| {skillDetails.activity.challenge.lastSources.map(s => ( | ||
| <a | ||
| key={s.id} | ||
| className={classNames(styles.tooltipRow, styles.padLeft)} | ||
| href={`${EnvironmentConfig.URLS.CHALLENGES_PAGE}/${s.id}`} | ||
|
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. [❗❗
Collaborator
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. For fix. |
||
| target='_blank' | ||
|
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. [❗❗ |
||
| rel='noopener noreferrer' | ||
| > | ||
| {s.name} | ||
| </a> | ||
| ))} | ||
| </li> | ||
| )} | ||
| {skillDetails.activity.course && ( | ||
| <li> | ||
| <div className={styles.tooltipRow}> | ||
| Courses ( | ||
| {skillDetails.activity.course.count} | ||
| ): | ||
| </div> | ||
| {skillDetails.activity.course.lastSources.map(s => ( | ||
| <a | ||
| key={s.completionEventId} | ||
| className={classNames(styles.tooltipRow, styles.padLeft)} | ||
| href={`${EnvironmentConfig.URLS.ACADEMY_COURSE}/${s.certification}`} | ||
|
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. [❗❗
Collaborator
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. @vas3a let's fix. |
||
| target='_blank' | ||
|
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. [❗❗ |
||
| rel='noopener noreferrer' | ||
| > | ||
| {s.title} | ||
| </a> | ||
| ))} | ||
| </li> | ||
| )} | ||
| {skillDetails.activity.certification && ( | ||
| <li> | ||
| <div className={styles.tooltipRow}> | ||
| TCA Certifications ( | ||
| {skillDetails.activity.certification.count} | ||
| ): | ||
| </div> | ||
| {skillDetails.activity.certification.lastSources.map(s => ( | ||
| <a | ||
| key={s.completionEventId} | ||
| className={classNames(styles.tooltipRow, styles.padLeft)} | ||
| href={`${EnvironmentConfig.URLS.ACADEMY_CERTIFICATION}/${s.dashedName}`} | ||
|
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. [❗❗
Collaborator
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. To fix. |
||
| target='_blank' | ||
|
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. [❗❗ |
||
| rel='noopener noreferrer' | ||
| > | ||
| {s.title} | ||
| </a> | ||
| ))} | ||
| </li> | ||
| )} | ||
| </ul> | ||
| </> | ||
| ) | ||
| }, [skillDetails, isLoadingDetails, hideDetails]) | ||
|
|
||
| return ( | ||
| <div | ||
| className={className} | ||
|
|
@@ -42,7 +143,17 @@ const SkillPill: FC<SkillPillProps> = props => { | |
| {props.skill.name} | ||
| {props.children} | ||
| </span> | ||
| {isVerified && <IconOutline.CheckCircleIcon />} | ||
| {isVerified && props.fetchSkillDetails && !hideDetails && ( | ||
| <Tooltip | ||
| clickable | ||
| content={isLoadingDetails ? 'Loading...' : skillDetailsTooltipContent} | ||
| > | ||
| <IconOutline.CheckCircleIcon onMouseEnter={handleMouseEnter} /> | ||
| </Tooltip> | ||
| )} | ||
| {isVerified && (!props.fetchSkillDetails || hideDetails) && ( | ||
| <IconOutline.CheckCircleIcon /> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.