about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/components/admin/Counter.js
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2023-04-14 19:22:47 -0500
committerStarfall <us@starfall.systems>2023-04-14 19:22:47 -0500
commit4fe1689de43f4404eb9530fcfbcbfb26d6c1c13a (patch)
tree6811b845bb7f4966b10dcefa3dea404246f161c7 /app/javascript/flavours/glitch/components/admin/Counter.js
parent65c1e53a32cabcdbb7bca57002bb0f6acdebe07e (diff)
parentbed63f6dae0879ac840066b031229e0d139089cd (diff)
Merge remote-tracking branch 'glitch/main' HEAD main
Diffstat (limited to 'app/javascript/flavours/glitch/components/admin/Counter.js')
-rw-r--r--app/javascript/flavours/glitch/components/admin/Counter.js117
1 files changed, 0 insertions, 117 deletions
diff --git a/app/javascript/flavours/glitch/components/admin/Counter.js b/app/javascript/flavours/glitch/components/admin/Counter.js
deleted file mode 100644
index 5b6a19f8d..000000000
--- a/app/javascript/flavours/glitch/components/admin/Counter.js
+++ /dev/null
@@ -1,117 +0,0 @@
-import React from 'react';
-import PropTypes from 'prop-types';
-import api from 'flavours/glitch/api';
-import { FormattedNumber } from 'react-intl';
-import { Sparklines, SparklinesCurve } from 'react-sparklines';
-import classNames from 'classnames';
-import Skeleton from 'flavours/glitch/components/skeleton';
-
-const percIncrease = (a, b) => {
-  let percent;
-
-  if (b !== 0) {
-    if (a !== 0) {
-      percent = (b - a) / a;
-    } else {
-      percent = 1;
-    }
-  } else if (b === 0 && a === 0) {
-    percent = 0;
-  } else {
-    percent = - 1;
-  }
-
-  return percent;
-};
-
-export default class Counter extends React.PureComponent {
-
-  static propTypes = {
-    measure: PropTypes.string.isRequired,
-    start_at: PropTypes.string.isRequired,
-    end_at: PropTypes.string.isRequired,
-    label: PropTypes.string.isRequired,
-    href: PropTypes.string,
-    params: PropTypes.object,
-    target: PropTypes.string,
-  };
-
-  state = {
-    loading: true,
-    data: null,
-  };
-
-  componentDidMount () {
-    const { measure, start_at, end_at, params } = this.props;
-
-    api().post('/api/v1/admin/measures', { keys: [measure], start_at, end_at, [measure]: params }).then(res => {
-      this.setState({
-        loading: false,
-        data: res.data,
-      });
-    }).catch(err => {
-      console.error(err);
-    });
-  }
-
-  render () {
-    const { label, href, target } = this.props;
-    const { loading, data } = this.state;
-
-    let content;
-
-    if (loading) {
-      content = (
-        <React.Fragment>
-          <span className='sparkline__value__total'><Skeleton width={43} /></span>
-          <span className='sparkline__value__change'><Skeleton width={43} /></span>
-        </React.Fragment>
-      );
-    } else {
-      const measure = data[0];
-      const percentChange = measure.previous_total && percIncrease(measure.previous_total * 1, measure.total * 1);
-
-      content = (
-        <React.Fragment>
-          <span className='sparkline__value__total'>{measure.human_value || <FormattedNumber value={measure.total} />}</span>
-          {measure.previous_total && (<span className={classNames('sparkline__value__change', { positive: percentChange > 0, negative: percentChange < 0 })}>{percentChange > 0 && '+'}<FormattedNumber value={percentChange} style='percent' /></span>)}
-        </React.Fragment>
-      );
-    }
-
-    const inner = (
-      <React.Fragment>
-        <div className='sparkline__value'>
-          {content}
-        </div>
-
-        <div className='sparkline__label'>
-          {label}
-        </div>
-
-        <div className='sparkline__graph'>
-          {!loading && (
-            <Sparklines width={259} height={55} data={data[0].data.map(x => x.value * 1)}>
-              <SparklinesCurve />
-            </Sparklines>
-          )}
-        </div>
-      </React.Fragment>
-    );
-
-    if (href) {
-      return (
-        <a href={href} className='sparkline' target={target}>
-          {inner}
-        </a>
-      );
-    } else {
-      return (
-        <div className='sparkline'>
-          {inner}
-        </div>
-      );
-    }
-  }
-
-}