refactor(imports): Improving imports pass #1 - #886
Conversation
madge --circular reports 46 circular dependencies in src/ (an earlier graphify pass undercounted at 19). This removes 34 of them with no behavior change: all the runtime-relevant barrel-incest cycles plus several type-only ones. The remaining 12 are benign type-only cycles (store slices, SearchFacet, CitationExporter) and are deferred to a follow-up. - Redirect Visualizations container/pane imports off the @/components/Visualizations barrel to direct module paths - Extract NetworkDetails node/link types and the AuthorNetworkGraph/BubblePlot hook-component type pairs into leaf *.types.ts files - Redirect FeedbackForms, Settings/Export, HistogramSlider and useExportFormats barrel imports to direct paths - Drop api/metrics/model's dependency on metrics by typing bibcodes as Bibcode[] - Move ApiRequestConfig into api/types.ts; api.ts re-exports it - Extract AffTableState/AffTableAction into AuthorAffiliations/types.ts - Move UserDataSetterEvent out of the settings/export page into components/Settings/Export/types.ts (it was imported by four components)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #886 +/- ##
========================================
+ Coverage 61.2% 65.9% +4.7%
========================================
Files 349 335 -14
Lines 41439 39811 -1628
Branches 1836 2006 +170
========================================
+ Hits 25359 26211 +852
+ Misses 16037 13557 -2480
Partials 43 43
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Refactors imports and colocates shared types to reduce circular dependencies in src/ (per madge), aiming for no behavior change while removing runtime-relevant barrel cycles.
Changes:
- Replaced several barrel imports (notably
@/components/Visualizations,@/components/Settings,@/components/FeedbackForms) with direct/relative imports. - Extracted shared type definitions into dedicated
*.types.ts/types.tsmodules (Visualizations, Settings Export, Author Affiliations) to avoid cross-module cycles. - Centralized
ApiRequestConfigtype insrc/api/types.tsand re-exported it fromsrc/api/api.ts.
Risk summary
Medium risk: broad import-path churn across many modules (regression risk from missed/incorrect import semantics), plus a few places where type-only dependencies should be made explicit to avoid reintroducing runtime edges.
Findings (priority order)
blocker
- None.
high
- None.
medium
- Type-only imports should consistently use
import typein several newly introduced/updated type modules and consumers to ensure these refactors don’t accidentally preserve runtime dependency edges (especially relevant to a circular-dependency cleanup).
Locations include:src/api/types.ts,src/auth-utils.ts,src/components/Settings/Export/types.ts,src/components/Visualizations/**/(types|*.types).ts(x), and several updated Visualizations components/hooks/utils.
low
- None.
Reviewed changes
Copilot reviewed 44 out of 44 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pages/user/settings/export.tsx | Stops exporting reducer event types from a page module; imports shared event type from a component types file. |
| src/lib/useExportFormats.ts | Switches DEFAULT_EXPORT_FORMATS import to a direct models module to avoid barrel cycles. |
| src/components/Visualizations/utils/graphUtils.ts | Replaces Visualizations barrel type imports with direct NetworkDetails type imports. |
| src/components/Visualizations/Panes/NetworkDetails/types.ts | New shared types module for network details panes. |
| src/components/Visualizations/Panes/NetworkDetails/SummaryPane.tsx | Replaces Visualizations barrel imports with direct relative imports (types + graph component). |
| src/components/Visualizations/Panes/NetworkDetails/PaperNetworkDetailsPane.tsx | Moves inline interface definitions to shared types.ts. |
| src/components/Visualizations/Panes/NetworkDetails/index.ts | Re-exports shared NetworkDetails types from the pane index. |
| src/components/Visualizations/Panes/NetworkDetails/AuthorNetworkDetailsPane.tsx | Uses shared types.ts for Paper/NodeDetails types. |
| src/components/Visualizations/Graphs/useBubblePlot.tsx | Imports BubblePlot types from a dedicated BubblePlot.types.ts module. |
| src/components/Visualizations/Graphs/useAuthorNetworkGraph.tsx | Imports shared graph types from AuthorNetworkGraph.types.ts. |
| src/components/Visualizations/Graphs/BubblePlot.types.ts | New extracted type module for BubblePlot props/config. |
| src/components/Visualizations/Graphs/BubblePlot.tsx | Removes inline types in favor of BubblePlot.types.ts. |
| src/components/Visualizations/Graphs/AuthorNetworkGraph.types.ts | New extracted type module for AuthorNetworkGraph shared types. |
| src/components/Visualizations/Graphs/AuthorNetworkGraph.tsx | Moves shared interfaces out to AuthorNetworkGraph.types.ts and trims d3 imports. |
| src/components/Visualizations/GraphPanes/YearsGraphPane.tsx | Replaces Visualizations barrel import with direct BarGraph import. |
| src/components/Visualizations/GraphPanes/MetricsPane.tsx | Replaces Visualizations barrel imports with direct Graph/Table imports. |
| src/components/Visualizations/GraphPanes/HIndexGraphPane.tsx | Replaces Visualizations barrel import with direct LineGraph import. |
| src/components/Visualizations/GraphPanes/BubblePlotPane.tsx | Splits BubblePlot component import from BubblePlot config type import. |
| src/components/Visualizations/GraphPanes/AuthorNetworkGraphPane.tsx | Replaces Visualizations barrel import with direct AuthorNetworkGraph import. |
| src/components/Visualizations/Containers/ResultsGraphPageContainer.tsx | Imports IBubblePlotNodeData directly from local Visualizations types. |
| src/components/Visualizations/Containers/PaperNetworkPageContainer.tsx | Imports PaperNetwork pane/components/types directly instead of via barrel. |
| src/components/Visualizations/Containers/OverviewPageContainer.tsx | Imports graph panes directly instead of via Visualizations barrel. |
| src/components/Visualizations/Containers/MetricsPageContainer.tsx | Imports MetricsPane directly instead of via Visualizations barrel. |
| src/components/Visualizations/Containers/ConceptCloudPageContainer.tsx | Imports WordCloudPane directly instead of via Visualizations barrel. |
| src/components/Visualizations/Containers/AuthorNetworkPageContainer.tsx | Imports network panes/types directly instead of via Visualizations barrel. |
| src/components/Settings/Export/types.ts | New extracted type module for Settings Export reducer events. |
| src/components/Settings/Export/Tabs/QuickExportFormatTabPane.tsx | Uses new Settings Export types module instead of importing from a page. |
| src/components/Settings/Export/Tabs/GeneralTabPanel.tsx | Uses new Settings Export types module; replaces Settings barrel import with local SampleTextArea. |
| src/components/Settings/Export/Tabs/CustomFormatsTabPanel.tsx | Uses new Settings Export types module; replaces Settings barrel import with local SampleTextArea. |
| src/components/Settings/Export/Tabs/BibtexTabPanel.tsx | Uses new Settings Export types module; replaces Settings barrel imports with local components. |
| src/components/Settings/Export/ExportFormatSelect.tsx | Replaces Settings barrel description import with local Description module. |
| src/components/Settings/Export/CustomFormatsTable.tsx | Replaces Settings barrel description import with local Description module. |
| src/components/HistogramSlider/HistogramSlider.tsx | Replaces Visualizations barrel imports with direct Histogram + HistogramDatum imports. |
| src/components/FeedbackForms/MissingRecord/RecordPanel.tsx | Replaces FeedbackForms barrel import with direct PreviewModal import. |
| src/components/FeedbackForms/AssociatedArticles/AssociatedArticlesForm.tsx | Replaces FeedbackForms barrel import with direct PreviewModal import. |
| src/components/AuthorAffiliations/types.ts | Extracts table state/action types to shared types module. |
| src/components/AuthorAffiliations/hooks/UseSubCaption.tsx | Imports AffTableState from shared types.ts instead of component module. |
| src/components/AuthorAffiliations/hooks/UseFetchAffData.tsx | Imports AffTableState from shared types.ts instead of component module. |
| src/components/AuthorAffiliations/AuthorAffiliations.tsx | Uses extracted AffTableState/AffTableAction from types.ts. |
| src/components/AuthorAffiliations/AffiliationControls.tsx | Imports state/action types from shared types.ts instead of component module. |
| src/auth-utils.ts | Switches ApiRequestConfig import source to @/api/types. |
| src/api/types.ts | Introduces shared ApiRequestConfig type alias for request config typing. |
| src/api/metrics/model.ts | Removes dependency on metricsKeys for typing; uses Bibcode[] directly. |
| src/api/api.ts | Imports and re-exports ApiRequestConfig from src/api/types.ts to avoid cycles. |
Only an allowed whitelist of doctypes emits Google Scholar-compatible meta tags (Highwire citation_*, PRISM prism.*, Dublin Core dc.*) on the abstract page. Other or unknown doctypes omit them; Schema.org JSON-LD, Open Graph, Twitter, canonical, and description tags remain for all records. Doctype comparisons are normalized to lowercase.
madge reports 46 circular dependencies in src. This breaks 34 of them with no behavior change.