Skip to content

Commit

Permalink
fix(dashboard-page): fix total resource number in world map
Browse files Browse the repository at this point in the history
  • Loading branch information
sijav committed Oct 4, 2024
1 parent 46a7d2a commit 128298a
Show file tree
Hide file tree
Showing 3 changed files with 370 additions and 611 deletions.
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@mui/x-data-grid-premium": "^7.18.0",
"@mui/x-date-pickers-pro": "^7.18.0",
"@mui/x-tree-view": "^7.18.0",
"@tanstack/react-query": "^5.56.2",
"@tanstack/react-query": "^5.59.0",
"@uidotdev/usehooks": "^2.4.1",
"axios": "^1.7.7",
"d3": "^7.9.0",
Expand All @@ -61,7 +61,7 @@
"js-cookie": "^3.0.5",
"lowlight": "^3.1.0",
"mustache": "^4.2.0",
"posthog-js": "^1.164.3",
"posthog-js": "^1.166.1",
"qrcode": "^1.5.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand All @@ -83,24 +83,24 @@
"@lingui/cli": "^4.11.4",
"@lingui/swc-plugin": "^4.0.10",
"@lingui/vite-plugin": "^4.11.4",
"@storybook/addon-essentials": "^8.3.3",
"@storybook/addon-links": "^8.3.3",
"@storybook/blocks": "^8.3.3",
"@storybook/react": "^8.3.3",
"@storybook/react-vite": "^8.3.3",
"@storybook/test": "^8.3.3",
"@storybook/addon-essentials": "^8.3.4",
"@storybook/addon-links": "^8.3.4",
"@storybook/blocks": "^8.3.4",
"@storybook/react": "^8.3.4",
"@storybook/react-vite": "^8.3.4",
"@storybook/test": "^8.3.4",
"@testing-library/jest-dom": "^6.5.0",
"@types/d3": "^7.4.3",
"@types/diff": "^5.2.2",
"@types/js-cookie": "^3.0.6",
"@types/mustache": "^4.2.5",
"@types/qrcode": "^1.5.5",
"@types/react": "^18.3.9",
"@types/react": "^18.3.10",
"@types/react-dom": "^18.3.0",
"@types/react-is": "^18.3.0",
"@types/react-lazy-load-image-component": "^1.6.4",
"@types/react-window": "^1.8.8",
"@vitejs/plugin-react-swc": "^3.7.0",
"@vitejs/plugin-react-swc": "^3.7.1",
"@vitest/coverage-v8": "^2.1.1",
"@vitest/ui": "^2.1.1",
"babel-plugin-macros": "3.1.0",
Expand All @@ -109,25 +109,25 @@
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.12",
"eslint-plugin-storybook": "^0.8.0",
"globals": "^15.9.0",
"eslint-plugin-storybook": "^0.9.0",
"globals": "^15.10.0",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"prettier-plugin-organize-imports": "^4.1.0",
"prop-types": "15",
"react-refresh": "^0.14.2",
"shx": "^0.3.4",
"storybook": "^8.3.3",
"storybook": "^8.3.4",
"tsc-files": "^1.1.4",
"type-fest": "^4.26.1",
"typescript": "^5.6.2",
"typescript-eslint": "^8.7.0",
"typescript-eslint": "^8.8.0",
"unique-names-generator": "^4.7.1",
"uuid": "^10.0.0",
"vite": "^5.4.7",
"vite": "^5.4.8",
"vite-plugin-html": "^3.2.2",
"vite-plugin-mock-dev-server": "^1.7.2",
"vite-plugin-mock-dev-server": "^1.7.3",
"vite-plugin-svgr": "^4.2.0",
"vitest": "^2.1.1",
"web-vitals": "^4.2.3"
Expand Down
12 changes: 5 additions & 7 deletions src/pages/panel/dashboard/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function DashboardPage() {
const [
{ data: lastScan },
{
data: { countries, data: worldMapDataWithCountries, regions, resources },
data: { countries, data: worldMapDataWithCountries, regions },
},
{
data: {
Expand Down Expand Up @@ -67,13 +67,12 @@ export default function DashboardPage() {
queryFn: postWorkspaceInventoryAggregateForDashboardQuery,
select: (data: PostWorkspaceInventoryAggregateForDashboardResponse) =>
data.reduce(
({ data, countries, regions, resources }, item) => {
({ data, countries, regions }, item) => {
const country = findCountryBasedOnCoordinates(item) ?? ''
return {
data: [...data, { ...item, country }],
countries: countries.includes(country) ? countries : [...countries, country],
regions: { ...regions, [item.group.cloud]: (regions[item.group.cloud] ?? 0) + 1 },
resources: resources + item.resource_count,
}
},
{
Expand All @@ -82,7 +81,6 @@ export default function DashboardPage() {
})[],
countries: [] as string[],
regions: {} as Record<AccountCloud, number | undefined>,
resources: 0,
},
),
},
Expand Down Expand Up @@ -206,7 +204,7 @@ export default function DashboardPage() {
<Tooltip title={`Last scanned on ${splittedLastScan[0].substring(2)} @ ${splittedLastScan[1].split('.')[0]} UTC`}>
<span>
<Trans>
Last scanned{' '}
Last scanned:{' '}
<Trans>{iso8601DurationToString(diffDateTimeToDuration(new Date(), new Date(lastScan)), 1).toLowerCase()} ago</Trans>
</Trans>
</span>
Expand Down Expand Up @@ -248,8 +246,8 @@ export default function DashboardPage() {
title={<Trans>Assets by region</Trans>}
subtitle={
<Trans>
{resources.toLocaleString(locale)} resources in {worldMapDataWithCountries.length.toLocaleString(locale)} regions in{' '}
{countries.length.toLocaleString(locale)} countries
{((awsResources ?? 0) + (azureResources ?? 0) + (gcpResources ?? 0)).toLocaleString(locale)} resources in{' '}
{worldMapDataWithCountries.length.toLocaleString(locale)} regions in {countries.length.toLocaleString(locale)} countries
</Trans>
}
SubtitleIcon={GlobeIcon}
Expand Down
Loading

0 comments on commit 128298a

Please sign in to comment.