Skip to content

Commit

Permalink
fix: Few fixes on sentry table management and data display (adrien2p#15)
Browse files Browse the repository at this point in the history
* fix: Few fixes on sentry table management and data display

* chore: remove format script since it is now applied by eslint

* fix: sentry plugin on fetch stats should not pass an empty transaction duration

* docs: Add gif demo to readme

* docs: Add gif demo to readme
  • Loading branch information
adrien2p authored Oct 28, 2022
1 parent 3deb5ed commit 44d7342
Show file tree
Hide file tree
Showing 38 changed files with 1,693 additions and 1,898 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ module.exports = {
'**/.prettier*',
'**/.version*',
'**/*.md',
'**/*.json',
'**/*.js',
'**/*.js.map',
'**/*.d.ts'
'**/*.d.ts',
'**/*.d.ts.map',
],
overrides: [
{
files: ["*"],
"rules": {
"prefer-rest-params": "off"
}
}
},
],
rules: {
"prettier/prettier": "error",
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"watch": "./node_modules/.bin/lerna run watch",
"test": "./node_modules/.bin/lerna run test",
"test:local": "./node_modules/.bin/lerna run test:local",
"lint": "./node_modules/.bin/eslint 'packages/**/*.ts' --fix",
"format": "./node_modules/.bin/prettier 'packages/**/*.ts' --write"
"lint": "./node_modules/.bin/eslint 'packages/**' --fix"
},
"repository": {
"type": "git",
Expand Down
10 changes: 5 additions & 5 deletions packages/medusa-plugin-sentry-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<a href="https://github.com/adrien2p/medusa-plugins/issues"><img alt="Issues" src="https://img.shields.io/github/issues/adrien2p/medusa-plugins?style=flat" height="20"/></a>
</p>

<p align="center">
<img src="https://github.com/adrien2p/medusa-plugins/blob/assets/assets/medusa-plugin-sentry-ui.gif?raw=true" alt="Medusa-plugins logo" width="500" height="auto" />
</p>

## Description

Thie spackage provides a set of component to have a sentry dashboard right into your admin
Expand All @@ -22,17 +26,13 @@ and be able to get an overview of what is happening without having to leave your
JavaScript Error and Performance Monitoring
Resolve JavaScript errors with max efficiency, not max effort. Get actionable insights to resolve JavaScript performance issues with the ability to track, debug, and resolve JavaScript errors across platforms.

## Demo

Need to feel that section

## Getting started

> ### Requirements
> Your server need to have installed `medusa-plugin-sentry` before being able to use that library
> as the data are comsumed from that plugin.
First of all, you need to install the plugin as follow `yarn add medusa-plugnin-sentrui`
First of all, you need to install the plugin as follow `yarn add medusa-plugnin-sentry-ui`

For the simple uasge you can open the file `src/pages/a.js` and add the following component above the `Routes` component
```javascript
Expand Down
64 changes: 29 additions & 35 deletions packages/medusa-plugin-sentry-ui/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import dts from "rollup-plugin-dts";
import { terser } from "rollup-plugin-terser";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import dts from 'rollup-plugin-dts';
import { terser } from 'rollup-plugin-terser';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';

export default [
{
input: "src/index.ts",
output: [
{
file: "dist/cjs/index.js",
format: "cjs",
sourcemap: true
},
{
file: "dist/esm/index.js",
format: "esm",
sourcemap: true
}
],
plugins: [
peerDepsExternal(),
resolve(),
commonjs(),
typescript({ tsconfig: "./tsconfig.json" }),
terser()
],
external: ["react", "react-dom", "styled-components", "lodash"]
},
{
input: "./dist/esm/index.d.ts",
output: [{ file: "dist/types/types.d.ts", format: "es" }],
plugins: [dts()],
},
];
{
input: 'src/index.ts',
output: [
{
file: 'dist/cjs/index.js',
format: 'cjs',
sourcemap: true,
},
{
file: 'dist/esm/index.js',
format: 'esm',
sourcemap: true,
},
],
plugins: [peerDepsExternal(), resolve(), commonjs(), typescript({ tsconfig: './tsconfig.json' }), terser()],
external: ['react', 'react-dom', 'styled-components', 'lodash'],
},
{
input: './dist/esm/index.d.ts',
output: [{ file: 'dist/types/types.d.ts', format: 'es' }],
plugins: [dts()],
},
];
49 changes: 31 additions & 18 deletions packages/medusa-plugin-sentry-ui/src/components/graphs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import { VictoryArea, VictoryAxis, VictoryChart, VictoryTooltip, VictoryVoronoiContainer } from "victory";
import styled from "styled-components";
import { VictoryArea, VictoryAxis, VictoryChart, VictoryTooltip, VictoryVoronoiContainer } from 'victory';
import styled from 'styled-components';
import HelpCircleIcon from '../temp/fundamentals/icons/help-circle';
import Tooltip from '../temp/atoms/tooltip';
import { APDEX_HELP_TEXT, FAILURE_RATE_HELP_TEXT, TPM_HELP_TEXT } from '../../types';

type BarChartProps = {
data: [number, [{ count: number }]][];
Expand All @@ -10,14 +13,14 @@ type BarChartProps = {
};

const GraphContainer = styled.div`
.VictoryContainer > svg {
width: 100%;
height: 100%;
overflow: visible;
}
.VictoryContainer > svg {
width: 100%;
height: 100%;
overflow: visible;
}
`;

function BarChart(props: BarChartProps & { yMin: string; yMax: string; }) {
function BarChart(props: BarChartProps & { yMin: string; yMax: string; tooltipContent: string }) {
const data = props.data?.map((d) => ({ timestamp: d[0], value: d[1][0].count }));

const stroke = { yellowGradient: '#FFC42A', purpuleGradient: '#7C3AED', blueGradient: '#4155ED' }[props.gradient];
Expand All @@ -31,7 +34,12 @@ function BarChart(props: BarChartProps & { yMin: string; yMax: string; }) {
borderRadius: 8,
}}
>
<h3 style={{ fontWeight: 'bold', margin: '12px 16px 0 16px' }}>{props.title}</h3>
<h3 style={{ fontWeight: 'bold', margin: '12px 16px 0 16px', display: 'flex' }}>
<span>{props.title}</span>
<Tooltip content={props.tooltipContent}>
<HelpCircleIcon width={15} className={'ml-1'} />
</Tooltip>
</h3>
<div
style={{ fontSize: 12, margin: ' 0 16px', color: 'rgba(107, 114, 128)' }}
className="text-gray font-small mx-16"
Expand Down Expand Up @@ -90,14 +98,16 @@ function BarChart(props: BarChartProps & { yMin: string; yMax: string; }) {
containerComponent={
<VictoryVoronoiContainer
labels={({ datum }) =>
`${new Date(datum.timestamp * 1000).toLocaleString()} \n Value: ${Math.round(datum.value * 100)}`
`${new Date(
datum.timestamp * 1000
).toLocaleString()} \n Value: ${Math.round(datum.value * 100)}`
}
/>
}
animate={{ duration: 200 }}
animate={{ duration: 500 }}
>
<VictoryArea
labelComponent={<VictoryTooltip flyoutStyle={{fill: "white"}} />}
labelComponent={<VictoryTooltip flyoutStyle={{ fill: 'white' }} />}
style={{
data: { fill: `url(#${props.gradient})`, stroke },
}}
Expand All @@ -124,32 +134,35 @@ function BarChart(props: BarChartProps & { yMin: string; yMax: string; }) {
}

function TransactionStats({ graphData }) {
const tpmYMax = Math.max(0, ...(graphData?.['tpm()']?.data.map(d => d?.[1]?.[0]?.count ?? 0) ?? []))
const tpmYMax = Math.max(0, ...(graphData?.['tpm()']?.data.map((d) => d?.[1]?.[0]?.count ?? 0) ?? []));

return (
<div className="flex justify-between">
<BarChart
gradient="purpleGradient"
title="Apdex"
tooltipContent={APDEX_HELP_TEXT}
subtitle="Apdex percentage"
data={graphData?.['apdex()'].data}
yMin={"0"}
yMax={"100"}
yMin={'0'}
yMax={'100'}
/>
<BarChart
gradient="yellowGradient"
title="Failure rate"
tooltipContent={FAILURE_RATE_HELP_TEXT}
subtitle="Failure rate percentage"
data={graphData?.['failure_rate()'].data}
yMin={"0"}
yMax={"100"}
yMin={'0'}
yMax={'100'}
/>
<BarChart
gradient="blueGradient"
title="TPM"
tooltipContent={TPM_HELP_TEXT}
subtitle="Transactions per minute"
data={graphData?.['tpm()'].data}
yMin={"0"}
yMin={'0'}
yMax={tpmYMax.toFixed(1)}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
import clsx from "clsx"
import ArrowLeftIcon from "./temp/fundamentals/icons/arrow-left-icon"
import ArrowRightIcon from "./temp/fundamentals/icons/arrow-right-icon"
import React from "react"
import clsx from 'clsx';
import ArrowLeftIcon from './temp/fundamentals/icons/arrow-left-icon';
import ArrowRightIcon from './temp/fundamentals/icons/arrow-right-icon';
import React from 'react';

export const TablePagination = ({
nextPage,
prevPage,
hasNext,
hasPrev,
}) => {

return (
<div
className={clsx(
"flex w-full justify-between inter-small-regular text-grey-50 mt-14",
)}
>
<div className="w-full flex space-x-4">
<div className="w-full flex space-x-4 items-center justify-end">
<div
className={clsx(
{ ["text-grey-30"]: !hasPrev },
{ ["cursor-pointer"]: hasPrev }
)}
onClick={() => prevPage()}
>
<ArrowLeftIcon />
</div>
<div
className={clsx(
{ ["text-grey-30"]: !hasNext },
{ ["cursor-pointer"]: hasNext }
)}
onClick={() => nextPage()}
>
<ArrowRightIcon />
</div>
</div>
</div>
</div>
)
}
export const TablePagination = ({ nextPage, prevPage, hasNext, hasPrev }) => {
return (
<div className={clsx('flex w-full justify-between inter-small-regular text-grey-50 mt-14')}>
<div className="w-full flex space-x-4">
<div className="w-full flex space-x-4 items-center justify-end">
<div
className={clsx({ ['text-grey-30']: !hasPrev }, { ['cursor-pointer']: hasPrev })}
onClick={() => prevPage()}
>
<ArrowLeftIcon />
</div>
<div
className={clsx({ ['text-grey-30']: !hasNext }, { ['cursor-pointer']: hasNext })}
onClick={() => nextPage()}
>
<ArrowRightIcon />
</div>
</div>
</div>
</div>
);
};
34 changes: 15 additions & 19 deletions packages/medusa-plugin-sentry-ui/src/components/table-row.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import Table from "./temp/molecules/table"
import React from "react"
import Table from './temp/molecules/table';
import React from 'react';

export const SentryTableRow = ({ row, ...rest }) => {
return (
<Table.Row
color={"inherit"}
linkTo={rest.linkTo ?? undefined}
actions={rest?.getActions ? rest.getActions() : []}
{...rest}
>
{row.cells.map((cell, index) => {
return (
<Table.Cell {...cell.getCellProps({ width: 500 })}>
{cell.render("Cell", { index })}
</Table.Cell>
)
})}
</Table.Row>
)
}
return (
<Table.Row
color={'inherit'}
linkTo={rest.linkTo ?? undefined}
actions={rest?.getActions ? rest.getActions() : []}
{...rest}
>
{row.cells.map((cell, index) => {
return <Table.Cell {...cell.getCellProps({ width: 500 })}>{cell.render('Cell', { index })}</Table.Cell>;
})}
</Table.Row>
);
};
Loading

0 comments on commit 44d7342

Please sign in to comment.