Skip to content

Conversation

martastain
Copy link
Member

@martastain martastain commented Jul 15, 2025

This pull request refactors how productTypes are handled across multiple components and contexts. The changes replace the usage of a static productTypes object with dynamic data sourced from the ProjectContext or project configuration. This improves flexibility and ensures productTypes are project-specific. Additionally, several utility functions and components were updated to accommodate this change.

Refactoring of productTypes

Replaced the static productTypes object with dynamic data retrieved from ProjectContext or project configuration. This ensures productTypes are project-specific.

This requires ynput/ayon-backend#622

ProjectContextProvider

Introduced ProjectContextProvider to provide project-specific data, including productTypes and various project-specific helper functions. This could be further expanded and eventually could replace project data in redux and allow consolidation of project specific logic.

@martastain martastain added the type: feature Adding something new and exciting to the product label Jul 15, 2025
@martastain martastain self-assigned this Jul 15, 2025
@martastain martastain requested a review from Copilot July 16, 2025 15:41
@martastain martastain marked this pull request as ready for review July 16, 2025 15:42
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request refactors how productTypes are handled across multiple components by replacing the usage of static productTypes object with dynamic data sourced from the ProjectContext. The change ensures that product types are project-specific and improves flexibility through the introduction of a ProjectContextProvider that provides project-specific data and helper functions.

Key changes:

  • Introduction of ProjectContextProvider to centralize project-specific data access
  • Replacement of static productTypes imports with dynamic project context consumption
  • Addition of utility functions for retrieving product type icons and colors from project configuration

Reviewed Changes

Copilot reviewed 22 out of 23 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/pages/ProjectPage/ProjectPage.tsx Wraps main project page with ProjectContextProvider
src/pages/ProjectDashboard/ProjectDashboard.jsx Adds ProjectContextProvider wrapper to dashboard
src/pages/BrowserPage/Products/ProductsGrid.jsx Replaces static productTypes with project context methods
shared/src/context/ProjectContext.tsx New context provider for project-specific data and helper functions
shared/src/containers/ProjectTreeTable/utils/getTableFieldOptions.ts Updates table field options to use dynamic product types
shared/src/components/VersionUploader/components/UploadVersionForm.tsx Migrates to use project context for product type options

Comment on lines +81 to 85
arrayProps[prop].push(projectInfo.config.productTypes.default as any)
}
}
else if (Array.isArray(projectInfo[prop])) {
arrayProps[prop].push(projectInfo[prop] as any)
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Using 'as any' type assertion bypasses TypeScript's type safety. Consider using proper type assertions or defining the expected type structure.

Suggested change
arrayProps[prop].push(projectInfo.config.productTypes.default as any)
}
}
else if (Array.isArray(projectInfo[prop])) {
arrayProps[prop].push(projectInfo[prop] as any)
const productTypesDefault = projectInfo.config.productTypes.default;
if (Array.isArray(productTypesDefault) && productTypesDefault.every(item => typeof item === 'object')) {
arrayProps[prop].push(productTypesDefault as ProductTypeOverride[]);
}
}
}
else if (Array.isArray(projectInfo[prop])) {
const propValue = projectInfo[prop];
if (Array.isArray(propValue)) {
arrayProps[prop].push(propValue as typeof arrayProps[typeof prop]);
}

Copilot uses AI. Check for mistakes.

Comment on lines +101 to 105
(result as any)[prop] = mergeArraysByKey(arrayProps[prop] as ProductTypeOverride[][])
}

else if (arrayProps[prop].length > 0) {
;(result as any)[prop] = mergeArraysByKey(arrayProps[prop])
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Using 'as any' type assertion bypasses TypeScript's type safety. Consider properly typing the result object or using more specific type assertions.

Suggested change
(result as any)[prop] = mergeArraysByKey(arrayProps[prop] as ProductTypeOverride[][])
}
else if (arrayProps[prop].length > 0) {
;(result as any)[prop] = mergeArraysByKey(arrayProps[prop])
result[prop] = mergeArraysByKey(arrayProps[prop] as ProductTypeOverride[][])
}
else if (arrayProps[prop].length > 0) {
result[prop] = mergeArraysByKey(arrayProps[prop] as typeof result[typeof prop])

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Adding something new and exciting to the product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant