-
Notifications
You must be signed in to change notification settings - Fork 9
feat(website): Cumulative graph of submission on groups page #5839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I guess we could just notshow the graph is |
|
Claude finished @theosanderson's task in 1m 49s —— View job Code Review CompleteI've reviewed the PR and provided inline comments on specific issues. Here's my overall assessment: SummaryThis PR adds a cumulative submissions chart to the group page, controlled by a new config option Key FindingsArchitecture & Design:
Code Quality Issues:
Testing:
Documentation:
RecommendationsHigh Priority:
Medium Priority: Low Priority: Security & Performance
Response to anna-parker's commentRegarding the suggestion to hide the graph when
The PR looks good overall and is ready for merge after addressing the high-priority items. |
|
|
||
| useEffect(() => { | ||
| ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend); | ||
| setIsRegistered(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Chart.js registration should not be done in a component using useEffect. This violates React best practices and can cause issues:
- Chart.js plugins are global and should be registered once at module level
- Using state (
isRegistered) to conditionally render based on registration is unnecessary - Multiple component instances would try to register the same plugins multiple times
Recommendation: Move registration to module level:
// At the top of the file, outside the component
ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend);Then remove the isRegistered state and the useEffect entirely (lines 36-41 and 85-87).
|
|
||
| return { | ||
| labels: sortedDates, | ||
| datasets: datasets.filter((ds) => ds.data[ds.data.length - 1] > 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This filter removes organisms with zero cumulative submissions, but only checks the final data point. Consider these edge cases:
- An organism with submissions that were all revoked would still show as a line at 0
- The check
> 0could be!== 0for consistency (though functionally equivalent)
Recommendation: Add a comment explaining the intent:
// Only show organisms that have at least one submission
datasets: datasets.filter((ds) => ds.data[ds.data.length - 1] > 0),|
|
||
| const { data: timeSeriesData, isLoading: timeSeriesLoading } = useQuery({ | ||
| queryKey: ['group-time-series', groupId, clientConfig, organisms, metadataItemForCumulativeGroupGraph], | ||
| queryFn: () => fetchTimeSeriesData(groupId, clientConfig, organisms, metadataItemForCumulativeGroupGraph!), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query will execute even when metadataItemForCumulativeGroupGraph is null, which could cause issues:
- The non-null assertion (
metadataItemForCumulativeGroupGraph!) on line 76 is unsafe - TypeScript will assume it's non-null but it could still be null - If someone changes the
enabledcondition, the query function could be called withnull
Recommendation: Make the queryFn handle the null case explicitly:
queryFn: () => {
if (metadataItemForCumulativeGroupGraph === null) {
return Promise.resolve({});
}
return fetchTimeSeriesData(groupId, clientConfig, organisms, metadataItemForCumulativeGroupGraph);
},| count: typeof d.count === 'number' ? d.count : 0, | ||
| })) | ||
| .sort((a, b) => a.date.localeCompare(b.date)); | ||
| } catch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silent error handling with an empty array could mask real issues. When the API request fails, users won't know if:
- The group genuinely has no data
- The API is down
- There's a configuration error
Recommendation: Consider logging errors or showing an error state:
} catch (error) {
console.error(`Failed to fetch time series data for ${key}:`, error);
data[key] = [];
}Same issue exists in fetchSequenceCounts at line 318.
| "group": "general", | ||
| "type": ["string", "null"], | ||
| "default": null, | ||
| "description": "The metadata field used to plot cumulative submissions over time on the group page. Set to null to disable the chart." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description could be more specific about the expected metadata field characteristics:
- Should mention that the field should be a date field (though technically any field could work)
- Could clarify what happens when set to
nullvs an invalid field name - The relationship to
earliestReleaseDateconfiguration could be mentioned
Recommendation: Enhance the description:
"description": "The metadata field used to plot cumulative submissions over time on the group page (typically 'earliestReleaseDate' or another date field). Set to null to disable the chart. If the specified field does not exist for an organism, the chart will show no data for that organism."
feat(website): Add cumulative submissions chart to group page
Adds a line chart showing cumulative submissions over time on the group page, with each organism as its own series.
Changes
metadataItemForCumulativeGroupGraphto control which metadata field is used for the x-axis (e.g.earliestReleaseDate)null(chart hidden), set toearliestReleaseDatefor preview serverCumulativeSubmissionsChartcomponent in its own fileFiles changed
Kubernetes config:
values.schema.json- Added schema for new config optionvalues.yaml- Default value (null)values_preview_server.yaml- Set toearliestReleaseDatetemplates/_common-metadata.tpl- Pass config to websiteWebsite:
src/types/config.ts- Added type for new config fieldsrc/components/User/CumulativeSubmissionsChart.tsx- New chart componentsrc/components/User/GroupPage.tsx- Fetch time series data and render chartsrc/pages/group/[groupId]/index.astro- Pass config prop🚀 Preview: https://dates-graph.loculus.org