Skip to content

Commit

Permalink
Initialize item table data refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcohen committed Nov 17, 2023
1 parent 529ae04 commit b124ffc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
6 changes: 4 additions & 2 deletions src/components/ItemTable/ItemTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ interface ItemTableProps {
* The ItemTable displays the Item info, StatusLinks, and RequestButtons
*/
const ItemTable = ({ itemTableData }: ItemTableProps) => {
console.log(itemTableData)
return (
<Table columnHeaders={[]} tableData={[["test", "test2"]]}>
<Table
columnHeaders={itemTableData.tableHeadings}
tableData={[["test", "test2"]]}
>
Items
</Table>
)
Expand Down
26 changes: 24 additions & 2 deletions src/models/ItemTableData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,41 @@ export default class ItemTableData {
isDesktop: boolean
isBibPage: boolean
isArchiveCollection: boolean
tableHeadings: string[]
tableData: string[][]

constructor(items: Item[], itemTableParams: ItemTableParams) {
this.items = items
this.isDesktop = itemTableParams.isDesktop
this.isBibPage = itemTableParams.isBibPage
this.isArchiveCollection = itemTableParams.isArchiveCollection
this.tableHeadings = []
this.tableData = [[]]
}

get tableHeadings(): string[] {
return [
...(this.hasStatusColumn() ? ["Status"] : []),
...(this.hasVolumeColumn() ? [this.volumeColumnHeading()] : []),
"Format",
...(!this.hasVolumeColumn() && !this.isDesktop ? ["Call Number"] : []),
...(this.isBibPage && this.isDesktop ? ["Access"] : []),
...(this.isDesktop ? ["Call Number"] : []),
...(this.hasLocationColumn ? ["Item Location"] : []),
]
}

hasVolumeColumn(): boolean {
return this.items.some((item) => item.volume?.length) && this.isBibPage
}

hasStatusColumn(): boolean {
return this.isBibPage
}

hasLocationColumn(): boolean {
return this.isDesktop
}

volumeColumnHeading(): string {
return this.isArchiveCollection ? "Vol/Date" : "Container"
}
}
19 changes: 0 additions & 19 deletions src/utils/itemUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,3 @@ export const locationEndpointsMap: Record<
export function locationLabelToKey(label: string): ItemLocationKey {
return label.replace(/SASB/, "Schwarzman").split(" ")[0] as ItemLocationKey
}

export const getItemTableHeadings = (
isDesktop = true,
isBibPage = false,
isArchiveCollection = false,
includeVolColumn = false
) => {
const volColumnHeading = isArchiveCollection ? "Vol/Date" : "Container"

return [
...(isBibPage ? ["Status"] : []),
...(includeVolColumn ? [volColumnHeading] : []),
"Format",
...(!includeVolColumn && !isDesktop ? ["Call Number"] : []),
...(isBibPage && isDesktop ? ["Access"] : []),
...(isDesktop ? ["Call Number"] : []),
...(isDesktop ? ["Item Location"] : []),
]
}

0 comments on commit b124ffc

Please sign in to comment.