Skip to content

Commit d09c17b

Browse files
author
himaniraghav3
committed
PM-589 Opportunity table fixes
1 parent 28a3742 commit d09c17b

File tree

5 files changed

+39
-11
lines changed

5 files changed

+39
-11
lines changed

src/apps/copilots/src/pages/copilot-opportunity-list/index.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ import {
1313
import { CopilotOpportunity } from '../../models/CopilotOpportunity'
1414
import { copilotRoutesMap } from '../../copilots.routes'
1515
import { CopilotOpportunitiesResponse, useCopilotOpportunities } from '../../services/copilot-opportunities'
16+
import { ProjectTypeLabels } from '../../constants'
1617

1718
import styles from './styles.module.scss'
1819

1920
const tableColumns: TableColumn<CopilotOpportunity>[] = [
2021
{
2122
label: 'Title',
2223
propertyName: 'projectName',
23-
type: 'text',
24+
renderer: (copilotOpportunity: CopilotOpportunity) => (
25+
<div>
26+
{copilotOpportunity.projectName}
27+
</div>
28+
),
29+
type: 'element',
2430
},
2531
{
2632
label: 'Status',
@@ -33,6 +39,7 @@ const tableColumns: TableColumn<CopilotOpportunity>[] = [
3339
type: 'element',
3440
},
3541
{
42+
isSortable: false,
3643
label: 'Skills Required',
3744
propertyName: 'skills',
3845
renderer: (copilotOpportunity: CopilotOpportunity) => (
@@ -49,7 +56,12 @@ const tableColumns: TableColumn<CopilotOpportunity>[] = [
4956
{
5057
label: 'Type',
5158
propertyName: 'type',
52-
type: 'text',
59+
renderer: (copilotOpportunity: CopilotOpportunity) => (
60+
<div className={styles.type}>
61+
{ProjectTypeLabels[copilotOpportunity.projectType]}
62+
</div>
63+
),
64+
type: 'element',
5365
},
5466
{
5567
label: 'Starting Date',
@@ -80,7 +92,10 @@ const CopilotOpportunityList: FC<{}> = () => {
8092
data: opportunities, isValidating, size, setSize,
8193
}: CopilotOpportunitiesResponse = useCopilotOpportunities()
8294

83-
const tableData = useMemo(() => opportunities, [opportunities])
95+
const tableData = useMemo(() => opportunities.map(opportunity => ({
96+
...opportunity,
97+
type: ProjectTypeLabels[opportunity.projectType] ?? '',
98+
})), [opportunities])
8499

85100
function loadMore(): void {
86101
setSize(size + 1)
@@ -103,6 +118,7 @@ const CopilotOpportunityList: FC<{}> = () => {
103118
moreToLoad={isValidating || opportunities.length > 0}
104119
onLoadMoreClick={loadMore}
105120
onRowClick={handleRowClick}
121+
removeDefaultSort
106122
/>
107123
{opportunitiesLoading && (
108124
<LoadingSpinner overlay />

src/apps/copilots/src/pages/copilot-opportunity-list/styles.module.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
.skillsContainer {
44
display: flex;
55
flex-wrap: wrap;
6+
overflow-x: auto;
7+
overflow-y: hidden;
68
gap: 8px;
79
}
810

@@ -26,4 +28,8 @@
2628

2729
.activeStatus {
2830
color: green;
29-
}
31+
}
32+
33+
.type {
34+
white-space: nowrap;
35+
}

src/libs/ui/lib/components/table/Table.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ const Table: <T extends { [propertyName: string]: any }>(props: TableProps<T>) =
102102

103103
function toggleSort(fieldName: string): void {
104104

105+
const col = props.columns.find(c => c.propertyName === fieldName)
106+
107+
// if sortable is false, we return
108+
if (!col?.isSortable === false) return
109+
105110
// if we don't have anything to sort by, we shouldn't be here
106111
if (!sort && !props.removeDefaultSort) {
107112
return
@@ -129,7 +134,7 @@ const Table: <T extends { [propertyName: string]: any }>(props: TableProps<T>) =
129134

130135
const headerRow: Array<JSX.Element> = displayColumns
131136
.map((col, index) => {
132-
const isSortable: boolean = !!col.propertyName
137+
const isSortable: boolean = !!col.propertyName && col.isSortable !== false
133138
const isCurrentlySorted: boolean = isSortable && col.propertyName === sort?.fieldName
134139
const colorClass: string = isCurrentlySorted ? 'black-100' : 'black-60'
135140
const sortableClass: string | undefined = isSortable ? styles.sortable : undefined
@@ -151,7 +156,7 @@ const Table: <T extends { [propertyName: string]: any }>(props: TableProps<T>) =
151156
</Tooltip>
152157
</div>
153158
)}
154-
{!props.disableSorting && (
159+
{!props.disableSorting && isSortable && (
155160
<TableSort
156161
iconClass={colorClass}
157162
isCurrentlySorted={isCurrentlySorted}

src/libs/ui/lib/components/table/table-column.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export interface TableColumn<T> {
1111
readonly isExpand?: boolean
1212
readonly colSpan?: number
1313
readonly type: TableCellType
14+
readonly isSortable?: boolean
1415
}

src/libs/ui/lib/components/table/table-functions/table.functions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ export function getSorted<T extends { [propertyName: string]: any }>(
5353

5454
if (sortColumn.type === 'date') {
5555
return sortedData
56-
.sort((a: T, b: T) => sortNumbers(
57-
(a[sort.fieldName] as Date).getTime(),
58-
(b[sort.fieldName] as Date).getTime(),
59-
sort.direction,
60-
))
56+
.sort((a: T, b: T) => {
57+
const aDate = new Date(a[sort.fieldName])
58+
const bDate = new Date(b[sort.fieldName])
59+
return sortNumbers(aDate.getTime(), bDate.getTime(), sort.direction)
60+
})
6161
}
6262

6363
return sortedData

0 commit comments

Comments
 (0)