Skip to content

Commit 838933a

Browse files
committed
Remove dependencies from core to other packages
1 parent b65b2b6 commit 838933a

File tree

21 files changed

+107
-69
lines changed

21 files changed

+107
-69
lines changed

.github/workflows/unit-test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ jobs:
1919
node-version: 20.x
2020
cache: 'npm'
2121
- run: yarn install --production=false
22-
- run: cd packages/core && npm link
2322
- run: lerna run build
2423
- run: npm run test --workspaces

docs/PACKAGE_DEPENDENCIES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ To check for dependency violations:
244244
npx lerna run test
245245

246246
# Search for explicit cross-package imports (excluding core, stories, dashboard, and editor)
247-
grep -r "from '@cdc/" packages/*/src --exclude="*.stories.*" | grep -v "/_stories/" | grep -v "@cdc/core" | grep -v "packages/dashboard/" | grep -v "packages/editor/"
247+
grep -r "from '@cdc/" packages/ --exclude="*.stories.*" --exclude-dir=node_modules | grep -v "/_stories/" | grep -v "@cdc/core" | grep -v "packages/dashboard/" | grep -v "packages/editor/" | grep -v "/types/" | grep -v "README.md"
248248

249249
# Search for relative imports that explicitly reference other package names
250250
# These patterns catch imports like: from '../../chart/...' or from '../../../map/src/...'
251-
grep -rE "from ['\"]\.\..*/(chart|map|data-table|data-bite|waffle-chart|filtered-text|markup-include|dashboard|editor)/" packages/*/src --exclude="*.stories.*" | grep -v "/_stories/" | grep -v "packages/dashboard/" | grep -v "packages/editor/"
251+
grep -rE "from ['\"]\.\..*/(chart|map|data-table|data-bite|waffle-chart|filtered-text|markup-include|dashboard|editor)/" packages/ --exclude="*.stories.*" --exclude-dir=node_modules | grep -v "/_stories/" | grep -v "packages/dashboard/" | grep -v "packages/editor/"
252252
```

packages/core/components/DataTable/DataTable.tsx

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ export type DataTableProps = {
4848
setFilteredCountryCode?: string // used for Maps only
4949
tabbingId: string
5050
tableTitle: string
51+
applyLegendToRow?: (
52+
rowObj: any,
53+
config: any,
54+
runtimeLegend: any,
55+
legendMemo: any,
56+
legendSpecialClassLastMemo: any
57+
) => string[]
58+
getPatternForRow?: (rowObj: any, config: any) => any
5159
viewport: 'lg' | 'md' | 'sm' | 'xs' | 'xxs'
5260
vizTitle?: string
5361
// determines if columns should be wrapped in the table
@@ -145,23 +153,23 @@ const DataTable = (props: DataTableProps) => {
145153
const rows =
146154
isVertical && sortBy.column
147155
? rawRows.sort((a, b) => {
148-
let dataA
149-
let dataB
150-
if (config.type === 'map' && config.columns) {
151-
const sortByColName = config.columns[sortBy.column].name
152-
dataA = runtimeData[a][sortByColName]
153-
dataB = runtimeData[b][sortByColName]
154-
}
155-
if (['chart', 'dashboard', 'table'].includes(config.type)) {
156-
dataA = runtimeData[a][sortBy.column]
157-
dataB = runtimeData[b][sortBy.column]
158-
}
159-
if (!dataA && !dataB && config.type === 'chart' && config.xAxis && config.xAxis.type === 'date-time') {
160-
dataA = timeParse(config.runtime.xAxis.dateParseFormat)(runtimeData[a][config.xAxis.dataKey])
161-
dataB = timeParse(config.runtime.xAxis.dateParseFormat)(runtimeData[b][config.xAxis.dataKey])
162-
}
163-
return dataA || dataB ? customSort(dataA, dataB, sortBy, config) : 0
164-
})
156+
let dataA
157+
let dataB
158+
if (config.type === 'map' && config.columns) {
159+
const sortByColName = config.columns[sortBy.column].name
160+
dataA = runtimeData[a][sortByColName]
161+
dataB = runtimeData[b][sortByColName]
162+
}
163+
if (['chart', 'dashboard', 'table'].includes(config.type)) {
164+
dataA = runtimeData[a][sortBy.column]
165+
dataB = runtimeData[b][sortBy.column]
166+
}
167+
if (!dataA && !dataB && config.type === 'chart' && config.xAxis && config.xAxis.type === 'date-time') {
168+
dataA = timeParse(config.runtime.xAxis.dateParseFormat)(runtimeData[a][config.xAxis.dataKey])
169+
dataB = timeParse(config.runtime.xAxis.dateParseFormat)(runtimeData[b][config.xAxis.dataKey])
170+
}
171+
return dataA || dataB ? customSort(dataA, dataB, sortBy, config) : 0
172+
})
165173
: rawRows
166174

167175
const limitHeight = {
@@ -240,17 +248,17 @@ const DataTable = (props: DataTableProps) => {
240248
const visibleData =
241249
config.type === 'map'
242250
? getMapRowData(
243-
rows,
244-
columns,
245-
config,
246-
formatLegendLocation,
247-
runtimeData as Record<string, Object>,
248-
displayGeoName,
249-
filterColumns
250-
)
251+
rows,
252+
columns,
253+
config,
254+
formatLegendLocation,
255+
runtimeData as Record<string, Object>,
256+
displayGeoName,
257+
filterColumns
258+
)
251259
: runtimeData.map(d => {
252-
return _.pick(d, [...filterColumns, ...dataSeriesColumns])
253-
})
260+
return _.pick(d, [...filterColumns, ...dataSeriesColumns])
261+
})
254262
const csvData = config.table?.downloadVisibleDataOnly ? visibleData : rawData
255263

256264
// only use fullGeoName on County maps and no other
@@ -287,28 +295,28 @@ const DataTable = (props: DataTableProps) => {
287295
const childrenMatrix =
288296
config.type === 'map'
289297
? mapCellMatrix({
290-
...props,
291-
rows,
292-
wrapColumns,
293-
runtimeData,
294-
viewport,
295-
legendMemo: props.legendMemo || defaultLegendMemo,
296-
legendSpecialClassLastMemo: props.legendSpecialClassLastMemo || defaultLegendSpecialClassLastMemo,
297-
runtimeLegend: props.runtimeLegend || defaultRuntimeLegend
298-
})
298+
...props,
299+
rows,
300+
wrapColumns,
301+
runtimeData,
302+
viewport,
303+
legendMemo: props.legendMemo || defaultLegendMemo,
304+
legendSpecialClassLastMemo: props.legendSpecialClassLastMemo || defaultLegendSpecialClassLastMemo,
305+
runtimeLegend: props.runtimeLegend || defaultRuntimeLegend
306+
})
299307
: chartCellMatrix({ rows, ...props, runtimeData, isVertical, sortBy, hasRowType, viewport })
300308

301309
const useBottomExpandCollapse = config.table.showBottomCollapse && expanded && Array.isArray(childrenMatrix)
302310

303311
// If every value in a column is a number, record the column index so the header and cells can be right-aligned
304312
const rightAlignedCols = childrenMatrix.length
305313
? Object.fromEntries(
306-
Object.keys(childrenMatrix[0])
307-
.filter(
308-
i => childrenMatrix.filter(row => isRightAlignedTableValue(row[i])).length === childrenMatrix.length
309-
)
310-
.map(x => [x, true])
311-
)
314+
Object.keys(childrenMatrix[0])
315+
.filter(
316+
i => childrenMatrix.filter(row => isRightAlignedTableValue(row[i])).length === childrenMatrix.length
317+
)
318+
.map(x => [x, true])
319+
)
312320
: {}
313321

314322
const showCollapseButton = config.table.collapsible !== false && useBottomExpandCollapse
@@ -384,8 +392,9 @@ const DataTable = (props: DataTableProps) => {
384392
)
385393
}
386394
tableOptions={{
387-
className: `table table-striped table-width-unset ${expanded ? 'data-table' : 'data-table cdcdataviz-sr-only'
388-
}${isVertical ? '' : ' horizontal'}`,
395+
className: `table table-striped table-width-unset ${
396+
expanded ? 'data-table' : 'data-table cdcdataviz-sr-only'
397+
}${isVertical ? '' : ' horizontal'}`,
389398
'aria-live': 'assertive',
390399
'aria-rowcount': config?.data?.length ? config.data.length : -1,
391400
hidden: !expanded,

packages/core/components/DataTable/helpers/mapCellMatrix.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ import { DataTableProps } from '../DataTable'
44
import { ReactNode } from 'react'
55
import { displayDataAsText } from '@cdc/core/helpers/displayDataAsText'
66
import _ from 'lodash'
7-
import { applyLegendToRow } from '@cdc/map/src/helpers/applyLegendToRow'
8-
import { hashObj } from '@cdc/map/src/helpers'
9-
import { getPatternForRow } from '@cdc/map/src/helpers/getPatternForRow'
7+
import { hashObj } from '../../../helpers/hashObj'
108

119
type MapRowsProps = DataTableProps & {
1210
rows: string[]
11+
applyLegendToRow: (
12+
rowObj: any,
13+
config: any,
14+
runtimeLegend: any,
15+
legendMemo: any,
16+
legendSpecialClassLastMemo: any
17+
) => string[]
18+
getPatternForRow: (rowObj: any, config: any) => any
1319
}
1420

1521
const getGeoLabel = (config, row, formatLegendLocation, displayGeoName, runtimeData = null) => {
@@ -92,7 +98,9 @@ const mapCellArray = ({
9298
setFilteredCountryCode,
9399
legendMemo,
94100
legendSpecialClassLastMemo,
95-
runtimeLegend
101+
runtimeLegend,
102+
applyLegendToRow,
103+
getPatternForRow
96104
}: MapRowsProps): ReactNode[][] => {
97105
const { allowMapZoom, geoType, type } = config.general
98106
return rows.map(row =>
@@ -116,11 +124,11 @@ const mapCellArray = ({
116124
type === 'bubble' && allowMapZoom && geoType === 'world' ? () => setFilteredCountryCode(row) : undefined
117125

118126
const validColor = legendColor && legendColor.length > 0 && !noColor
119-
127+
120128
// Check for pattern information
121129
const patternInfo = getPatternForRow(rowObj, config)
122130
const mapId = config.runtime?.uniqueId || 'map'
123-
131+
124132
return (
125133
<div className='col-12'>
126134
{validColor ? (

packages/core/components/Filters/Filters.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { getNestedOptions } from './helpers/getNestedOptions'
1414
import { getWrappingStatuses } from './helpers/filterWrapping'
1515
import { handleSorting } from './helpers/handleSorting'
1616
import { getChangedFilters } from './helpers/getChangedFilters'
17-
import { getUniqueValues } from '@cdc/map/src/helpers'
17+
import { getUniqueValues } from '../../helpers/getUniqueValues'
1818
import { getQueryParams, updateQueryString } from '../../helpers/queryStringUtils'
1919
import { applyQueuedActive } from './helpers/applyQueuedActive'
2020
import Tabs from './components/Tabs'
@@ -95,7 +95,9 @@ const Filters: React.FC<FilterProps> = ({
9595
eventAction: 'change',
9696
eventLabel: interactionLabel,
9797
vizTitle: getVizTitle(visualizationConfig),
98-
specifics: `key: ${String(newFilters?.[index]?.columnName).toLowerCase()}, value: ${String(newFilters?.[index]?.active).toLowerCase()}`
98+
specifics: `key: ${String(newFilters?.[index]?.columnName).toLowerCase()}, value: ${String(
99+
newFilters?.[index]?.active
100+
).toLowerCase()}`
99101
})
100102
}
101103

packages/core/components/Legend/Legend.Gradient.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { type MapConfig } from '@cdc/map/src/types/MapConfig'
44
import { type ChartConfig } from '@cdc/chart/src/types/ChartConfig'
55
import { getTextWidth } from '../../helpers/getTextWidth'
66
import { DimensionsType } from '../../types/Dimensions'
7-
import useLegendSeparators from '@cdc/map/src/hooks/useLegendSeparators'
7+
import useLegendSeparators from '../../hooks/useLegendSeparators'
88

99
const MARGIN = 1
1010
const BORDER_SIZE = 1
File renamed without changes.

packages/core/helpers/tests/testStandaloneBuild.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,32 @@ export function testStandaloneBuild(pkgDir) {
2727
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), `cdc-open-viz-${pkgName}-`))
2828
copyDirSync(pkgDir, tmpDir)
2929

30+
let coreTarballPath = null
31+
3032
try {
3133
execSync('npm install --include=dev', { cwd: tmpDir })
32-
execSync('npm link @cdc/core', { cwd: tmpDir })
34+
35+
// Pack core into tmp directory with unique name then install from package tarball
36+
const coreDir = path.join(pkgDir, '..', 'core')
37+
const uniqueId = `${Date.now()}-${Math.random().toString(36).substring(7)}`
38+
const tarballDir = os.tmpdir()
39+
const packOutput = execSync(`npm pack --pack-destination="${tarballDir}"`, { cwd: coreDir, encoding: 'utf-8' })
40+
const tarballName = packOutput.trim().split('\n').pop() // Get last line (tarball filename)
41+
const originalTarballPath = path.join(tarballDir, tarballName)
42+
coreTarballPath = path.join(tarballDir, `cdc-core-${uniqueId}.tgz`)
43+
fs.renameSync(originalTarballPath, coreTarballPath)
44+
execSync(`npm install "${coreTarballPath}"`, { cwd: tmpDir, stdio: 'inherit' })
45+
3346
execSync('npm run build', { cwd: tmpDir })
3447
return true
3548
} catch (err) {
3649
console.error(`❌ Isolated build for ${pkgName} package failed`)
50+
console.error(err.message)
3751
return false
3852
} finally {
53+
if (coreTarballPath && fs.existsSync(coreTarballPath)) {
54+
fs.unlinkSync(coreTarballPath)
55+
}
3956
fs.rmSync(tmpDir, { recursive: true, force: true })
4057
}
4158
}

packages/core/helpers/useDataVizClasses.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import useResizeObserver from '@cdc/map/src/hooks/useResizeObserver'
21
import { isBelowBreakpoint } from './viewports'
32

43
export default function useDataVizClasses(config, viewport = null) {

0 commit comments

Comments
 (0)