Skip to content

Commit

Permalink
Merge pull request #424 from NYPL/SCC-4428/fix-source-on-hold-requests
Browse files Browse the repository at this point in the history
SCC-4428 - Pass item source in kebab case to hold forms
  • Loading branch information
dgcohen authored Dec 20, 2024
2 parents c8e9809 + cd229ba commit a401427
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pages/hold/request/[id]/edd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function EDDRequestPage({
const [eddFormState, setEddFormState] = useState({
...initialEDDFormState,
patronId,
source: item.source,
source: item.formattedSourceForHoldRequest,
})
const [formPosting, setFormPosting] = useState(false)

Expand Down
2 changes: 1 addition & 1 deletion pages/hold/request/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default function HoldRequestPage({
handleSubmit={handleSubmit}
holdId={holdId}
patronId={patronId}
source={item.source}
source={item.formattedSourceForHoldRequest}
/>
</>
) : null}
Expand Down
5 changes: 5 additions & 0 deletions src/models/Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
locationEndpointsMap,
} from "../utils/itemUtils"
import { appConfig } from "../config/config"
import { convertCamelToShishKabobCase } from "../utils/appUtils"

/**
* The Item class contains the data and getter functions
Expand Down Expand Up @@ -81,6 +82,10 @@ export default class Item {
.includes("all")
}

get formattedSourceForHoldRequest(): string {
return convertCamelToShishKabobCase(this.source)
}

// Pre-processing logic for setting Item holding location
getLocationFromItem(item: DiscoveryItemResult): ItemLocation {
let location = defaultNYPLLocation
Expand Down
4 changes: 4 additions & 0 deletions src/models/modelTests/Item.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ describe("Item model", () => {
"A history of spaghetti eating and cooking for: spaghetti dinner."
)
})

it("returns the source in kebabcase for use in hold requests", () => {
expect(item.formattedSourceForHoldRequest).toBe("sierra-nypl")
})
})

describe("ReCAP checks", () => {
Expand Down
16 changes: 16 additions & 0 deletions src/utils/appUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,19 @@ export const convertToSentenceCase = (str: string) =>
str.split(" ").length > 1
? str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()
: str

/**
* Converts camel case string to shish kabob case
*
* e.g. camelToShishKabobCase("RecapPul")
* => "recap-pul"
* camelToShishKabobCase("firstCharCanBeLowerCase")
* => "first-char-can-be-lower-case"
*/
export const convertCamelToShishKabobCase = (str: string) =>
str
// Change capital letters into "-{lowercase letter}"
.replace(/([A-Z])/g, (capitalLetter, placeholderVar, index) => {
// If capital letter is not first character, precede with '-':
return (index > 0 ? "-" : "") + capitalLetter.toLowerCase()
})

0 comments on commit a401427

Please sign in to comment.