From 5243228c964e47e098bdbf6fa925c99e2829f51f Mon Sep 17 00:00:00 2001 From: Robert Joonas Date: Sun, 24 Mar 2024 11:54:59 +0000 Subject: [PATCH] Extract SamplingNotice function component --- .../js/dashboard/stats/graph/sampling-notice.js | 17 +++++++++++++++++ .../js/dashboard/stats/graph/visitor-graph.js | 17 ++--------------- 2 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 assets/js/dashboard/stats/graph/sampling-notice.js diff --git a/assets/js/dashboard/stats/graph/sampling-notice.js b/assets/js/dashboard/stats/graph/sampling-notice.js new file mode 100644 index 000000000..03181e321 --- /dev/null +++ b/assets/js/dashboard/stats/graph/sampling-notice.js @@ -0,0 +1,17 @@ +import React from "react" + +export default function SamplingNotice({topStatData}) { + const samplePercent = topStatData?.samplePercent + + if (samplePercent && samplePercent < 100) { + return ( +
+ + + +
+ ) + } else { + return null + } +} \ No newline at end of file diff --git a/assets/js/dashboard/stats/graph/visitor-graph.js b/assets/js/dashboard/stats/graph/visitor-graph.js index b4dab7317..211219b91 100644 --- a/assets/js/dashboard/stats/graph/visitor-graph.js +++ b/assets/js/dashboard/stats/graph/visitor-graph.js @@ -7,6 +7,7 @@ import { LoadingState } from './graph-util' import TopStats from './top-stats'; import { IntervalPicker, getCurrentInterval } from './interval-picker' import StatsExport from './stats-export' +import SamplingNotice from './sampling-notice'; import FadeIn from '../../fade-in'; import * as url from '../../util/url' import { parseNaiveDate, isBefore } from '../../util/date' @@ -117,20 +118,6 @@ export default class VisitorGraph extends React.Component { storage.setItem(`topStatsHeight__${this.props.site.domain}`, document.getElementById('top-stats-container').clientHeight) } - samplingNotice() { - const samplePercent = this.state.topStatData?.sample_percent - - if (samplePercent && samplePercent < 100) { - return ( -
- - - -
- ) - } - } - importedNotice() { const { topStatData } = this.state @@ -198,7 +185,7 @@ export default class VisitorGraph extends React.Component { {loading === LoadingState.updatingGraph && renderLoader()}
{!isRealtime && } - {this.samplingNotice()} + {this.importedNotice()}