-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…or Sender statistics Dashboard (#1202) * chore: wip first setup for new component library * chore: wip new react component * feat: add FiledNotificationsStatistics component draft chore: add types for echarts library chore: some minor changes to PnEcharts component * feat: add default theme to PnEcharts component feat: add ability to override default theme to PnEcharts component feat: add FiledNotificationsStatistics component to test PnEcharts component * chore: update yarn.lock * feat: add draft code to perform mocked api call and update redux state * chore: export of pn-data-viz for other packages * chore: adding env variable for enabling statistics page and route * test: fixed compilation errors and skipped one test * chore: add cxType parameter to getStatistics api call * chore: fix positioning for statistics menu item --------- Co-authored-by: Carlotta Dimatteo <[email protected]>
- Loading branch information
1 parent
44dff14
commit ad87fff
Showing
23 changed files
with
3,609 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
test-report.xml | ||
|
||
# sonar | ||
/.scannerwork | ||
|
||
# production | ||
/build | ||
/dist | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `pn-data-viz` | ||
|
||
> TODO: description | ||
## Usage | ||
|
||
``` | ||
const pnDataViz = require('pn-data-viz'); | ||
// TODO: DEMONSTRATE API | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@pagopa-pn/pn-data-viz", | ||
"version": "0.0.1", | ||
"private": true, | ||
"description": "SEND component library for data visualization", | ||
"keywords": [ | ||
"data-viz", | ||
"charts", | ||
"send" | ||
], | ||
"homepage": "https://github.com/pagopa/pn-frontend/pn-data-viz#readme", | ||
"main": "./src/index.ts", | ||
"dependencies": { | ||
"@types/echarts": "^4.9.22", | ||
"echarts": "^5.5.0", | ||
"typescript": "^5.2.2" | ||
}, | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "node ./__tests__/pn-data-viz.test.js" | ||
}, | ||
"peerDependencies": { | ||
"@mui/material": "^5.14.5", | ||
"react": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "7.11.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-functional": "^3.7.2", | ||
"eslint-plugin-import": "^2.25.3", | ||
"eslint-plugin-react": "^7.27.1", | ||
"eslint-plugin-react-hooks": "^4.3.0", | ||
"eslint-plugin-sonarjs": "^0.10.0", | ||
"vite": "^5.1.4", | ||
"vitest": "1.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import senderDashboard from "./theme/senderDashboard"; | ||
import { init, getInstanceByDom, registerTheme } from "echarts"; | ||
import type { EChartOption, ECharts, SetOptionOpts } from "echarts"; | ||
import { useRef, useEffect } from "react"; | ||
import type { CSSProperties } from "react"; | ||
|
||
export interface PnEChartsProps { | ||
option: EChartOption; | ||
style?: CSSProperties; | ||
settings?: SetOptionOpts; | ||
loading?: boolean; | ||
theme?: "light" | "dark" | object; | ||
} | ||
|
||
export function PnECharts({ | ||
option, | ||
style, | ||
settings, | ||
loading, | ||
theme, | ||
}: PnEChartsProps): JSX.Element { | ||
const chartRef = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
// Initialize chart | ||
let chart: ECharts | undefined; | ||
if (chartRef.current !== null) { | ||
let selectedTheme = "defaultTheme"; | ||
|
||
registerTheme("defaultTheme", senderDashboard); | ||
if (typeof theme === "object") { | ||
registerTheme("customTheme", theme); | ||
selectedTheme = "customTheme"; | ||
} | ||
chart = init(chartRef.current, selectedTheme); | ||
} | ||
|
||
// Add chart resize listener | ||
// ResizeObserver is leading to a bit janky UX | ||
function resizeChart() { | ||
chart?.resize(); | ||
} | ||
window.addEventListener("resize", resizeChart); | ||
|
||
// Return cleanup function | ||
return () => { | ||
chart?.dispose(); | ||
window.removeEventListener("resize", resizeChart); | ||
}; | ||
}, [theme]); | ||
|
||
useEffect(() => { | ||
// Update chart | ||
if (chartRef.current !== null) { | ||
const chart = getInstanceByDom(chartRef.current); | ||
chart?.setOption(option, settings); | ||
} | ||
}, [option, settings, theme]); // Whenever theme changes we need to add option and setting due to it being deleted in cleanup function | ||
|
||
useEffect(() => { | ||
// Update chart | ||
if (chartRef.current !== null) { | ||
const chart = getInstanceByDom(chartRef.current); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions | ||
loading === true ? chart?.showLoading() : chart?.hideLoading(); | ||
} | ||
}, [loading, theme]); | ||
|
||
return ( | ||
<div ref={chartRef} style={{ width: "100%", height: "100%", ...style }} /> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PnEChartsProps, PnECharts } from "./PnEcharts"; | ||
|
||
export { PnECharts }; | ||
export type { PnEChartsProps }; |
Oops, something went wrong.