Skip to content

Conversation

OpenStaxClaude
Copy link
Contributor

Summary

  • Converted all 13 JavaScript files (12 components + 1 test) in the institutional-partnership page to TypeScript
  • Added comprehensive type definitions following Roy's guidelines:
    • ✅ Avoided using any type
    • ✅ Preferred type to interface
    • ✅ Relied on type inference where possible
    • ✅ Used inline type definitions for function parameters
    • ✅ Kept line lengths under 120 characters

Files Converted

Component Files (12):

  • institutional-partnership.js.tsx - Main component with DataObject, SectionData, ImageMeta types
  • sections/banner/banner.js.tsx - BannerProps with destructured image meta types
  • sections/sign-up/sign-up.js.tsx - SignUpProps for contact form fields
  • sections/participants/participants.js.tsx - Icon type, proper click event handlers, groupBy typing
  • sections/about/about.js.tsx - AboutProps with image optimization support
  • sections/small-quote/small-quote.js.tsx - SmallQuoteProps for quote display
  • sections/big-quote/big-quote.js.tsx - BigQuoteProps with background image string type
  • sections/promoting/promoting.js.tsx - Complex WideCard, TallCard types for nested arrays
  • sections/overlapping-quote/overlapping-quote.js.tsx - OverlappingQuoteProps for quote section
  • sections/results/results.js.tsx - Card type for statistics display with indexed images
  • sections/speaking/speaking.js.tsx - SpeakingProps with image meta and React inline styles
  • sections/participants/established-partners/established-partners.js.tsx - Icon type for partner display

Test File (1):

  • test/institutional-partnership.test.js.tsx - Enhanced with additional sensible tests:
    • Main heading rendering test
    • LazyLoad component performance test
    • TypeScript structure validation test

Technical Details

  • All components maintain existing functionality while adding comprehensive type safety
  • TypeScript definitions include proper React component types, event handlers, and complex nested data structures
  • Fixed inline style usage in speaking.tsx (string → object)
  • Added proper key props using indices where object keys weren't unique
  • Enhanced test coverage with meaningful assertions

Test Plan

  • Verify institutional partnership page loads correctly
  • Test all section components render without TypeScript errors
  • Verify LazyLoad components work properly
  • Test interactive elements (dialog, links) function correctly
  • Run TypeScript compilation to ensure no type errors
  • Run existing tests to ensure functionality preserved

Related to: https://openstax.atlassian.net/browse/CORE-1249

🤖 Generated with Claude Code

@RoyEJohnson RoyEJohnson force-pushed the core-1249-institutional-partnership-typescript branch from 7ddb79c to 2386c5a Compare September 18, 2025 22:53
@RoyEJohnson RoyEJohnson requested a review from jivey September 18, 2025 23:02
const distributionUrl = 'https://images.openstax.org';
const version = 'v1';

export function maxDimIfNarrowerThan(width: number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was something duplicated in several modules, so I made it a utility here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, even the initial conversion came out as delete-and-recreate. :(

return newObject;
}

function sectionData(data: DataObject, sectionNumber: string | number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parses out the data for each section, so its output is simply cast to the appropriate props type. We're trusting the CMS to serve the expected format.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial conversion did come through as changes, but it's also not a very big file. The only real updates are the added type and the use of the maxDim utility

import type {Icon} from '../participants';
import './established-partners.scss';

export default function EstablishedPartners({model}: {model: Icon[]}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this a required parameter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easier to see changes in individual commits. I made one additional change after the Prettier commit, to handle the possibility that the current/established groups could be empty.

.filter((k) => String(k).startsWith(sectionPrefix))
.reduce(
(a, oldKey) => unprefixKey(a, String(oldKey), sectionPrefix, data), {}
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have other CMS data that needs this transformation? I can see this being a reusable helperDo we have other CMS data that needs this transformation? I can see this being a reusable helper

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat to my surprise, I do not find other pages doing this transformation.

wideCards.map((item) =>
<div className="wide-card-entry" key={item}>
wideCards.map((item, index) =>
<div className="wide-card-entry" key={index}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are always in the same order, maybe it's fine, but using the image might be a more stable key

OpenStaxClaude and others added 5 commits September 22, 2025 14:28
- Converted all 12 JavaScript files in institutional-partnership page to TypeScript
- Added comprehensive type definitions following Roy's guidelines:
  ✅ Avoided using any type
  ✅ Preferred type to interface
  ✅ Used type inference where possible
  ✅ Used inline type definitions for function parameters
  ✅ Kept line lengths under 120 characters

- Enhanced test file with additional sensible tests
- Maintained existing functionality while improving type safety

Files converted:
- institutional-partnership.js → .tsx (DataObject, SectionData, ImageMeta types)
- sections/banner/banner.js → .tsx (BannerProps with image meta types)
- sections/sign-up/sign-up.js → .tsx (SignUpProps with form fields)
- sections/participants/participants.js → .tsx (Icon type, click event handlers)
- sections/about/about.js → .tsx (AboutProps with image optimization)
- sections/small-quote/small-quote.js → .tsx (SmallQuoteProps with quote fields)
- sections/big-quote/big-quote.js → .tsx (BigQuoteProps with background image)
- sections/promoting/promoting.js → .tsx (WideCard, TallCard types for complex arrays)
- sections/overlapping-quote/overlapping-quote.js → .tsx (OverlappingQuoteProps)
- sections/results/results.js → .tsx (Card type for results display)
- sections/speaking/speaking.js → .tsx (SpeakingProps with image meta)
- sections/participants/established-partners/established-partners.js → .tsx (Icon type)
- test/institutional-partnership.test.js → .test.tsx (enhanced with additional tests)

🤖 Generated with [Claude Code](https://claude.ai/code)

Lint issues

Co-Authored-By: Claude <[email protected]>
@RoyEJohnson RoyEJohnson force-pushed the core-1249-institutional-partnership-typescript branch from 6062757 to f69bb06 Compare September 22, 2025 19:28
@RoyEJohnson RoyEJohnson merged commit 76b56a4 into main Sep 22, 2025
1 check passed
@RoyEJohnson RoyEJohnson deleted the core-1249-institutional-partnership-typescript branch September 22, 2025 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants