mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 18:27:25 +03:00
Moved helper functions in GraphCard outside of component function
This commit is contained in:
parent
4c1a044fd3
commit
812e391e34
4 changed files with 45 additions and 44 deletions
|
@ -10,8 +10,7 @@ const propTypes = {
|
|||
stats: PropTypes.object,
|
||||
};
|
||||
|
||||
export function GraphCard({ title, isBarChart, stats }) {
|
||||
const generateGraphData = (stats) => ({
|
||||
const generateGraphData = (title, isBarChart, stats) => ({
|
||||
labels: keys(stats),
|
||||
datasets: [
|
||||
{
|
||||
|
@ -30,8 +29,9 @@ export function GraphCard({ title, isBarChart, stats }) {
|
|||
borderWidth: 2,
|
||||
},
|
||||
],
|
||||
});
|
||||
const renderGraph = () => {
|
||||
});
|
||||
|
||||
const renderGraph = (title, isBarChart, stats) => {
|
||||
const Component = isBarChart ? HorizontalBar : Doughnut;
|
||||
const options = {
|
||||
legend: isBarChart ? { display: false } : { position: 'right' },
|
||||
|
@ -44,15 +44,16 @@ export function GraphCard({ title, isBarChart, stats }) {
|
|||
} : null,
|
||||
};
|
||||
|
||||
return <Component data={generateGraphData(stats)} options={options} />;
|
||||
};
|
||||
return <Component data={generateGraphData(title, isBarChart, stats)} options={options} />;
|
||||
};
|
||||
|
||||
return (
|
||||
const GraphCard = ({ title, isBarChart, stats }) => (
|
||||
<Card className="mt-4">
|
||||
<CardHeader>{title}</CardHeader>
|
||||
<CardBody>{renderGraph()}</CardBody>
|
||||
<CardBody>{renderGraph(title, isBarChart, stats)}</CardBody>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
GraphCard.propTypes = propTypes;
|
||||
|
||||
export default GraphCard;
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
processReferrersStats,
|
||||
} from './services/VisitsParser';
|
||||
import { VisitsHeader } from './VisitsHeader';
|
||||
import { GraphCard } from './GraphCard';
|
||||
import GraphCard from './GraphCard';
|
||||
import { getShortUrlDetail, shortUrlDetailType } from './reducers/shortUrlDetail';
|
||||
import './ShortUrlVisits.scss';
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import React from 'react';
|
|||
import { shallow } from 'enzyme';
|
||||
import { Doughnut, HorizontalBar } from 'react-chartjs-2';
|
||||
import { keys, values } from 'ramda';
|
||||
import { GraphCard } from '../../src/visits/GraphCard';
|
||||
import GraphCard from '../../src/visits/GraphCard';
|
||||
|
||||
describe('<GraphCard />', () => {
|
||||
let wrapper;
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Card } from 'reactstrap';
|
|||
import * as sinon from 'sinon';
|
||||
import { ShortUrlsVisitsComponent as ShortUrlsVisits } from '../../src/visits/ShortUrlVisits';
|
||||
import MutedMessage from '../../src/utils/MuttedMessage';
|
||||
import { GraphCard } from '../../src/visits/GraphCard';
|
||||
import GraphCard from '../../src/visits/GraphCard';
|
||||
import DateInput from '../../src/common/DateInput';
|
||||
|
||||
describe('<ShortUrlVisits />', () => {
|
||||
|
|
Loading…
Reference in a new issue