|
| 1 | +import { FC, Fragment, PropsWithChildren } from 'react'; |
| 2 | + |
| 3 | +import { Button } from '@app/components/common/Button'; |
| 4 | +import { variantsStyles } from '@app/components/common/Typography/variantsStyles'; |
| 5 | +import { ClassNameProps } from '@app/types/common'; |
| 6 | +import { generateClassNames } from '@app/utils'; |
| 7 | + |
| 8 | +const bands = [ |
| 9 | + { |
| 10 | + band: 'Band 1', |
| 11 | + buckets: [ |
| 12 | + { name: 'Programming language', level: 2, bandScore: 4, threshold: 2, earned: 4 }, |
| 13 | + { name: 'UI/UX Development', level: 2, bandScore: 4, threshold: 2, earned: 4 }, |
| 14 | + ], |
| 15 | + }, |
| 16 | + { |
| 17 | + band: 'Band 2', |
| 18 | + buckets: [ |
| 19 | + { name: 'Dynamic Data & Systems Integration', level: 0, bandScore: 0, threshold: 6, earned: 4 }, |
| 20 | + { name: 'VCS', level: 0, bandScore: 0, threshold: 6, earned: 4 }, |
| 21 | + ], |
| 22 | + }, |
| 23 | + { |
| 24 | + band: 'Band 3', |
| 25 | + buckets: [{ name: 'Bucket', level: 0, bandScore: 0, threshold: 11, earned: 4 }], |
| 26 | + }, |
| 27 | + { |
| 28 | + band: 'Band 4', |
| 29 | + buckets: [{ name: 'Bucket', level: 0, bandScore: 0, threshold: 11, earned: 4 }], |
| 30 | + }, |
| 31 | + { |
| 32 | + band: 'Band 5', |
| 33 | + buckets: [{ name: 'Bucket', level: 0, bandScore: 0, threshold: 11, earned: 4 }], |
| 34 | + }, |
| 35 | + { |
| 36 | + band: 'Band 6', |
| 37 | + buckets: [{ name: 'Bucket', level: 0, bandScore: 0, threshold: 11, earned: 4 }], |
| 38 | + }, |
| 39 | + { |
| 40 | + band: 'Band 7', |
| 41 | + buckets: [{ name: 'Bucket', level: 0, bandScore: 0, threshold: 11, earned: 4 }], |
| 42 | + }, |
| 43 | + { |
| 44 | + band: 'Band 8', |
| 45 | + buckets: [{ name: 'Bucket', level: 0, bandScore: 0, threshold: 11, earned: 4 }], |
| 46 | + }, |
| 47 | + { |
| 48 | + band: 'Band 9', |
| 49 | + buckets: [{ name: 'Bucket', level: 0, bandScore: 0, threshold: 11, earned: 4 }], |
| 50 | + }, |
| 51 | + { |
| 52 | + band: 'Band 10', |
| 53 | + buckets: [{ name: 'Bucket', level: 0, bandScore: 0, threshold: 11, earned: 4 }], |
| 54 | + }, |
| 55 | + { |
| 56 | + band: 'Band 11', |
| 57 | + buckets: [{ name: 'Bucket', level: 0, bandScore: 0, threshold: 11, earned: 4 }], |
| 58 | + }, |
| 59 | + { |
| 60 | + band: 'Band 12', |
| 61 | + buckets: [{ name: 'Bucket', level: 0, bandScore: 0, threshold: 11, earned: 4 }], |
| 62 | + }, |
| 63 | + { |
| 64 | + band: 'Band 13', |
| 65 | + buckets: [{ name: 'Bucket', level: 0, bandScore: 0, threshold: 11, earned: 4 }], |
| 66 | + }, |
| 67 | +]; |
| 68 | + |
| 69 | +// INFO: For now seniority levels are hardcoded. First 3 bands are junior, next |
| 70 | +// 3 are mid, and the rest are senior. |
| 71 | +enum Seniority { |
| 72 | + Junior = 'junior', |
| 73 | + Mid = 'mid', |
| 74 | + Senior = 'senior', |
| 75 | +} |
| 76 | + |
| 77 | +const TableHeader: FC< |
| 78 | + PropsWithChildren<{ |
| 79 | + last?: boolean; |
| 80 | + }> & |
| 81 | + ClassNameProps |
| 82 | +> = ({ children, className, last }) => { |
| 83 | + return ( |
| 84 | + <th |
| 85 | + className={generateClassNames( |
| 86 | + 'border-b border-navy-200 p-4 text-center uppercase text-navy-500', |
| 87 | + variantsStyles['hint/caps-medium'], |
| 88 | + !last && 'border-r', |
| 89 | + className, |
| 90 | + )} |
| 91 | + > |
| 92 | + {children} |
| 93 | + </th> |
| 94 | + ); |
| 95 | +}; |
| 96 | + |
| 97 | +const TableCell: FC< |
| 98 | + PropsWithChildren< |
| 99 | + { |
| 100 | + lastRow?: boolean; |
| 101 | + lastCol?: boolean; |
| 102 | + rowSpan?: number; |
| 103 | + isHeader?: boolean; |
| 104 | + } & ClassNameProps |
| 105 | + > |
| 106 | +> = ({ children, lastRow, lastCol, rowSpan, className }) => { |
| 107 | + return ( |
| 108 | + <td |
| 109 | + className={generateClassNames( |
| 110 | + 'border-r border-navy-200 p-4 text-center text-navy-700', |
| 111 | + !lastRow && 'border-b', |
| 112 | + !lastCol && 'border-r', |
| 113 | + variantsStyles['body-s/semibold'], |
| 114 | + className, |
| 115 | + )} |
| 116 | + rowSpan={rowSpan} |
| 117 | + > |
| 118 | + {children} |
| 119 | + </td> |
| 120 | + ); |
| 121 | +}; |
| 122 | + |
| 123 | +export const Dot: FC<ClassNameProps> = ({ className }) => { |
| 124 | + return <div className={generateClassNames('size-3 rounded-full', className)} />; |
| 125 | +}; |
| 126 | + |
| 127 | +export const ScoreCardTable = () => { |
| 128 | + const bandsWithSeniority = bands.reduce<Record<Seniority, typeof bands>>( |
| 129 | + (acc, { band, buckets }, bandIndex) => { |
| 130 | + if (bandIndex < 3) { |
| 131 | + acc.junior.push({ band, buckets }); |
| 132 | + } else if (bandIndex < 6) { |
| 133 | + acc.mid.push({ band, buckets }); |
| 134 | + } else { |
| 135 | + acc.senior.push({ band, buckets }); |
| 136 | + } |
| 137 | + return acc; |
| 138 | + }, |
| 139 | + { |
| 140 | + junior: [], |
| 141 | + mid: [], |
| 142 | + senior: [], |
| 143 | + }, |
| 144 | + ); |
| 145 | + |
| 146 | + const bucketsCount = bands.reduce<number>((acc, { buckets }) => acc + buckets.length, 0); |
| 147 | + |
| 148 | + const getBucketsInSeniorityCount = (seniority: Seniority) => |
| 149 | + bandsWithSeniority[seniority].reduce<number>((acc, { buckets }) => acc + buckets.length, 0); |
| 150 | + |
| 151 | + const renderLevelDots = (level: number) => { |
| 152 | + return ( |
| 153 | + <div className="flex gap-2"> |
| 154 | + {Array.from({ length: 3 }).map((_, index) => ( |
| 155 | + <Dot key={index} className={level > index ? 'bg-green-600' : 'bg-navy-300'} /> |
| 156 | + ))} |
| 157 | + </div> |
| 158 | + ); |
| 159 | + }; |
| 160 | + |
| 161 | + return ( |
| 162 | + <div className="overflow-x-auto"> |
| 163 | + <table className="min-w-full border-separate border-spacing-0 rounded-lg border border-navy-200"> |
| 164 | + <thead> |
| 165 | + <tr className="bg-gray-100"> |
| 166 | + <TableHeader>Seniority</TableHeader> |
| 167 | + <TableHeader>Band</TableHeader> |
| 168 | + <TableHeader>Bucket</TableHeader> |
| 169 | + <TableHeader>Advancement Level</TableHeader> |
| 170 | + <TableHeader>Band Score</TableHeader> |
| 171 | + <TableHeader>Threshold</TableHeader> |
| 172 | + <TableHeader>Score Earned</TableHeader> |
| 173 | + <TableHeader last>Action</TableHeader> |
| 174 | + </tr> |
| 175 | + </thead> |
| 176 | + <tbody> |
| 177 | + {Object.entries(bandsWithSeniority).map(([seniority, bands], seniorityIndex) => ( |
| 178 | + <Fragment key={seniority}> |
| 179 | + {bands.map(({ band, buckets }, bandIndex) => ( |
| 180 | + <Fragment key={band}> |
| 181 | + {buckets.map((bucket, bucketIndex) => { |
| 182 | + const lastRow = seniorityIndex + bandIndex + bucketIndex === bucketsCount + 1; |
| 183 | + const bucketsInSeniority = getBucketsInSeniorityCount(seniority as Seniority); |
| 184 | + console.log('bucketsInSeniority', bucketsInSeniority); |
| 185 | + return ( |
| 186 | + <tr key={`${band}-${bucketIndex}`}> |
| 187 | + {bucketIndex + bandIndex === 0 && ( |
| 188 | + <TableCell |
| 189 | + rowSpan={bucketsInSeniority} |
| 190 | + lastRow={seniority === 'senior'} |
| 191 | + className="uppercase" |
| 192 | + > |
| 193 | + {seniority} |
| 194 | + </TableCell> |
| 195 | + )} |
| 196 | + {bucketIndex === 0 && ( |
| 197 | + <TableCell rowSpan={buckets.length} lastRow={lastRow}> |
| 198 | + {band} |
| 199 | + </TableCell> |
| 200 | + )} |
| 201 | + <TableCell lastRow={lastRow} className="font-normal"> |
| 202 | + {bucket.name} |
| 203 | + </TableCell> |
| 204 | + <TableCell lastRow={lastRow}>{renderLevelDots(bucket.level)}</TableCell> |
| 205 | + {bucketIndex === 0 && ( |
| 206 | + <> |
| 207 | + <TableCell rowSpan={buckets.length} lastRow={lastRow}> |
| 208 | + {bucket.bandScore} |
| 209 | + </TableCell> |
| 210 | + <TableCell rowSpan={buckets.length} lastRow={lastRow}> |
| 211 | + {bucket.threshold} |
| 212 | + </TableCell> |
| 213 | + <TableCell rowSpan={buckets.length} lastRow={lastRow}> |
| 214 | + {bucket.earned} |
| 215 | + </TableCell> |
| 216 | + <TableCell rowSpan={buckets.length} lastCol lastRow={lastRow} className="text-center"> |
| 217 | + <Button variant="link" className="mx-auto"> |
| 218 | + Evaluate |
| 219 | + </Button> |
| 220 | + </TableCell> |
| 221 | + </> |
| 222 | + )} |
| 223 | + </tr> |
| 224 | + ); |
| 225 | + })} |
| 226 | + </Fragment> |
| 227 | + ))} |
| 228 | + </Fragment> |
| 229 | + ))} |
| 230 | + </tbody> |
| 231 | + </table> |
| 232 | + </div> |
| 233 | + ); |
| 234 | +}; |
0 commit comments