commit
5ec28758f0
@ -1,255 +1,152 @@ |
||||
version: 2 |
||||
version: 2.1 |
||||
|
||||
aliases: |
||||
- &defaults |
||||
orbs: |
||||
ruby: circleci/ruby@1.2.0 |
||||
node: circleci/node@4.7.0 |
||||
|
||||
executors: |
||||
default: |
||||
parameters: |
||||
ruby-version: |
||||
type: string |
||||
docker: |
||||
- image: circleci/ruby:2.7-buster-node |
||||
environment: &ruby_environment |
||||
- image: cimg/ruby:<< parameters.ruby-version >> |
||||
environment: |
||||
BUNDLE_JOBS: 3 |
||||
BUNDLE_RETRY: 3 |
||||
BUNDLE_APP_CONFIG: ./.bundle/ |
||||
BUNDLE_PATH: ./vendor/bundle/ |
||||
CONTINUOUS_INTEGRATION: true |
||||
DB_HOST: localhost |
||||
DB_USER: root |
||||
RAILS_ENV: test |
||||
ALLOW_NOPAM: true |
||||
CONTINUOUS_INTEGRATION: true |
||||
DISABLE_SIMPLECOV: true |
||||
PAM_ENABLED: true |
||||
PAM_DEFAULT_SERVICE: pam_test |
||||
PAM_CONTROLLED_SERVICE: pam_test_controlled |
||||
working_directory: ~/projects/mastodon/ |
||||
|
||||
- &attach_workspace |
||||
attach_workspace: |
||||
at: ~/projects/ |
||||
|
||||
- &persist_to_workspace |
||||
persist_to_workspace: |
||||
root: ~/projects/ |
||||
paths: |
||||
- ./mastodon/ |
||||
|
||||
- &restore_ruby_dependencies |
||||
restore_cache: |
||||
keys: |
||||
- v3-ruby-dependencies-{{ checksum "/tmp/.ruby-version" }}-{{ checksum "Gemfile.lock" }} |
||||
- v3-ruby-dependencies-{{ checksum "/tmp/.ruby-version" }}- |
||||
- v3-ruby-dependencies- |
||||
RAILS_ENV: test |
||||
- image: cimg/postgres:14.0 |
||||
environment: |
||||
POSTGRES_USER: root |
||||
POSTGRES_HOST_AUTH_METHOD: trust |
||||
- image: circleci/redis:6-alpine |
||||
|
||||
- &install_steps |
||||
commands: |
||||
install-system-dependencies: |
||||
steps: |
||||
- checkout |
||||
- *attach_workspace |
||||
- restore_cache: |
||||
keys: |
||||
- v2-node-dependencies-{{ checksum "yarn.lock" }} |
||||
- v2-node-dependencies- |
||||
- run: |
||||
name: Install yarn dependencies |
||||
command: yarn install --frozen-lockfile |
||||
- save_cache: |
||||
key: v2-node-dependencies-{{ checksum "yarn.lock" }} |
||||
paths: |
||||
- ./node_modules/ |
||||
- *persist_to_workspace |
||||
|
||||
- &install_system_dependencies |
||||
run: |
||||
name: Install system dependencies |
||||
command: | |
||||
sudo apt-get update |
||||
sudo apt-get install -y libicu-dev libidn11-dev libprotobuf-dev protobuf-compiler |
||||
|
||||
- &install_ruby_dependencies |
||||
steps: |
||||
- *attach_workspace |
||||
- *install_system_dependencies |
||||
- run: |
||||
name: Set Ruby version |
||||
command: ruby -e 'puts RUBY_VERSION' | tee /tmp/.ruby-version |
||||
- *restore_ruby_dependencies |
||||
- run: |
||||
name: Set bundler settings |
||||
command: | |
||||
bundle config --local clean 'true' |
||||
bundle config --local deployment 'true' |
||||
bundle config --local with 'pam_authentication' |
||||
bundle config --local without 'development production' |
||||
bundle config --local frozen 'true' |
||||
bundle config --local path $BUNDLE_PATH |
||||
- run: |
||||
name: Install bundler dependencies |
||||
command: bundle check || (bundle install && bundle clean) |
||||
- save_cache: |
||||
key: v3-ruby-dependencies-{{ checksum "/tmp/.ruby-version" }}-{{ checksum "Gemfile.lock" }} |
||||
paths: |
||||
- ./.bundle/ |
||||
- ./vendor/bundle/ |
||||
- persist_to_workspace: |
||||
root: ~/projects/ |
||||
paths: |
||||
- ./mastodon/.bundle/ |
||||
- ./mastodon/vendor/bundle/ |
||||
name: Install system dependencies |
||||
command: | |
||||
sudo apt-get update |
||||
sudo apt-get install -y libicu-dev libidn11-dev libprotobuf-dev protobuf-compiler |
||||
install-ruby-dependencies: |
||||
parameters: |
||||
ruby-version: |
||||
type: string |
||||
steps: |
||||
- run: |
||||
command: | |
||||
bundle config clean 'true' |
||||
bundle config frozen 'true' |
||||
bundle config without 'development production' |
||||
name: Set bundler settings |
||||
- ruby/install-deps: |
||||
bundler-version: '2.2.31' |
||||
key: ruby<< parameters.ruby-version >>-gems-v1 |
||||
wait-db: |
||||
steps: |
||||
- run: |
||||
command: dockerize -wait tcp://localhost:5432 -wait tcp://localhost:6379 -timeout 1m |
||||
name: Wait for PostgreSQL and Redis |
||||
|
||||
- &test_steps |
||||
parallelism: 4 |
||||
steps: |
||||
- *attach_workspace |
||||
- *install_system_dependencies |
||||
- run: |
||||
name: Install FFMPEG |
||||
command: sudo apt-get install -y ffmpeg |
||||
- run: |
||||
name: Load database schema |
||||
command: ./bin/rails db:create db:schema:load db:seed |
||||
- run: |
||||
name: Run rspec in parallel |
||||
command: | |
||||
bundle exec rspec --profile 10 \ |
||||
--format RspecJunitFormatter \ |
||||
--out test_results/rspec.xml \ |
||||
--format progress \ |
||||
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings) |
||||
- store_test_results: |
||||
path: test_results |
||||
jobs: |
||||
install: |
||||
<<: *defaults |
||||
<<: *install_steps |
||||
|
||||
install-ruby2.7: |
||||
<<: *defaults |
||||
<<: *install_ruby_dependencies |
||||
|
||||
install-ruby2.6: |
||||
<<: *defaults |
||||
docker: |
||||
- image: circleci/ruby:2.6-buster-node |
||||
environment: *ruby_environment |
||||
<<: *install_ruby_dependencies |
||||
|
||||
install-ruby3.0: |
||||
<<: *defaults |
||||
docker: |
||||
- image: circleci/ruby:3.0-buster-node |
||||
environment: *ruby_environment |
||||
<<: *install_ruby_dependencies |
||||
|
||||
build: |
||||
<<: *defaults |
||||
docker: |
||||
- image: cimg/ruby:3.0-node |
||||
environment: |
||||
RAILS_ENV: test |
||||
steps: |
||||
- *attach_workspace |
||||
- *install_system_dependencies |
||||
- checkout |
||||
- install-system-dependencies |
||||
- install-ruby-dependencies: |
||||
ruby-version: '3.0' |
||||
- node/install-packages: |
||||
cache-version: v1 |
||||
pkg-manager: yarn |
||||
- run: |
||||
name: Precompile assets |
||||
command: ./bin/rails assets:precompile |
||||
name: Precompile assets |
||||
- persist_to_workspace: |
||||
root: ~/projects/ |
||||
paths: |
||||
- ./mastodon/public/assets |
||||
- ./mastodon/public/packs-test/ |
||||
- public/assets |
||||
- public/packs-test |
||||
root: . |
||||
|
||||
test: |
||||
parameters: |
||||
ruby-version: |
||||
type: string |
||||
executor: |
||||
name: default |
||||
ruby-version: << parameters.ruby-version >> |
||||
environment: |
||||
ALLOW_NOPAM: true |
||||
PAM_ENABLED: true |
||||
PAM_DEFAULT_SERVICE: pam_test |
||||
PAM_CONTROLLED_SERVICE: pam_test_controlled |
||||
parallelism: 4 |
||||
steps: |
||||
- checkout |
||||
- install-system-dependencies |
||||
- run: |
||||
command: sudo apt-get install -y ffmpeg imagemagick libpam-dev |
||||
name: Install additional system dependencies |
||||
- run: |
||||
command: bundle config with 'pam_authentication' |
||||
name: Enable PAM authentication |
||||
- install-ruby-dependencies: |
||||
ruby-version: << parameters.ruby-version >> |
||||
- attach_workspace: |
||||
at: . |
||||
- wait-db |
||||
- run: |
||||
command: ./bin/rails db:create db:schema:load db:seed |
||||
name: Load database schema |
||||
- ruby/rspec-test |
||||
|
||||
test-migrations: |
||||
<<: *defaults |
||||
docker: |
||||
- image: circleci/ruby:2.7-buster-node |
||||
environment: *ruby_environment |
||||
- image: circleci/postgres:12.2 |
||||
environment: |
||||
POSTGRES_USER: root |
||||
POSTGRES_HOST_AUTH_METHOD: trust |
||||
- image: circleci/redis:5-alpine |
||||
executor: |
||||
name: default |
||||
ruby-version: '3.0' |
||||
steps: |
||||
- *attach_workspace |
||||
- *install_system_dependencies |
||||
- checkout |
||||
- install-system-dependencies |
||||
- install-ruby-dependencies: |
||||
ruby-version: '3.0' |
||||
- wait-db |
||||
- run: |
||||
name: Create database |
||||
command: ./bin/rails db:create |
||||
name: Create database |
||||
- run: |
||||
name: Run migrations |
||||
command: ./bin/rails db:migrate |
||||
|
||||
test-ruby2.7: |
||||
<<: *defaults |
||||
docker: |
||||
- image: circleci/ruby:2.7-buster-node |
||||
environment: *ruby_environment |
||||
- image: circleci/postgres:12.2 |
||||
environment: |
||||
POSTGRES_USER: root |
||||
POSTGRES_HOST_AUTH_METHOD: trust |
||||
- image: circleci/redis:5-alpine |
||||
<<: *test_steps |
||||
|
||||
test-ruby2.6: |
||||
<<: *defaults |
||||
docker: |
||||
- image: circleci/ruby:2.6-buster-node |
||||
environment: *ruby_environment |
||||
- image: circleci/postgres:12.2 |
||||
environment: |
||||
POSTGRES_USER: root |
||||
POSTGRES_HOST_AUTH_METHOD: trust |
||||
- image: circleci/redis:5-alpine |
||||
<<: *test_steps |
||||
|
||||
test-ruby3.0: |
||||
<<: *defaults |
||||
docker: |
||||
- image: circleci/ruby:3.0-buster-node |
||||
environment: *ruby_environment |
||||
- image: circleci/postgres:12.2 |
||||
environment: |
||||
POSTGRES_USER: root |
||||
POSTGRES_HOST_AUTH_METHOD: trust |
||||
- image: circleci/redis:5-alpine |
||||
<<: *test_steps |
||||
|
||||
test-webui: |
||||
<<: *defaults |
||||
docker: |
||||
- image: circleci/node:12-buster |
||||
steps: |
||||
- *attach_workspace |
||||
- run: |
||||
name: Run jest |
||||
command: yarn test:jest |
||||
name: Run migrations |
||||
|
||||
workflows: |
||||
version: 2 |
||||
build-and-test: |
||||
jobs: |
||||
- install |
||||
- install-ruby2.7: |
||||
requires: |
||||
- install |
||||
- install-ruby2.6: |
||||
requires: |
||||
- install |
||||
- install-ruby2.7 |
||||
- install-ruby3.0: |
||||
- build |
||||
- test: |
||||
matrix: |
||||
parameters: |
||||
ruby-version: |
||||
- '2.7' |
||||
- '3.0' |
||||
name: test-ruby<< matrix.ruby-version >> |
||||
requires: |
||||
- install |
||||
- install-ruby2.7 |
||||
- build: |
||||
requires: |
||||
- install-ruby2.7 |
||||
- test-migrations: |
||||
requires: |
||||
- install-ruby2.7 |
||||
- test-ruby2.7: |
||||
requires: |
||||
- install-ruby2.7 |
||||
- build |
||||
- test-ruby2.6: |
||||
- test-migrations: |
||||
requires: |
||||
- install-ruby2.6 |
||||
- build |
||||
- test-ruby3.0: |
||||
- node/run: |
||||
cache-version: v1 |
||||
name: test-webui |
||||
pkg-manager: yarn |
||||
requires: |
||||
- install-ruby3.0 |
||||
- build |
||||
- test-webui: |
||||
requires: |
||||
- install |
||||
version: lts |
||||
yarn-run: test:jest |
||||
|
@ -0,0 +1,34 @@ |
||||
name: Build container image |
||||
on: |
||||
workflow_dispatch: |
||||
push: |
||||
branches: |
||||
- "main" |
||||
tags: |
||||
- "*" |
||||
jobs: |
||||
build-image: |
||||
runs-on: ubuntu-latest |
||||
steps: |
||||
- uses: actions/checkout@v2 |
||||
- uses: docker/setup-buildx-action@v1 |
||||
- uses: docker/login-action@v1 |
||||
with: |
||||
username: ${{ secrets.DOCKERHUB_USERNAME }} |
||||
password: ${{ secrets.DOCKERHUB_TOKEN }} |
||||
- uses: docker/metadata-action@v3 |
||||
id: meta |
||||
with: |
||||
images: tootsuite/mastodon |
||||
flavor: | |
||||
latest=auto |
||||
tags: | |
||||
type=edge,branch=main |
||||
type=semver,pattern={{ raw }} |
||||
- uses: docker/build-push-action@v2 |
||||
with: |
||||
context: . |
||||
push: true |
||||
tags: ${{ steps.meta.outputs.tags }} |
||||
cache-from: type=registry,ref=tootsuite/mastodon:latest |
||||
cache-to: type=inline |
@ -1 +1 @@ |
||||
2.7.4 |
||||
3.0.2 |
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,23 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class Api::V1::Admin::DimensionsController < Api::BaseController |
||||
protect_from_forgery with: :exception |
||||
|
||||
before_action :require_staff! |
||||
before_action :set_dimensions |
||||
|
||||
def create |
||||
render json: @dimensions, each_serializer: REST::Admin::DimensionSerializer |
||||
end |
||||
|
||||
private |
||||
|
||||
def set_dimensions |
||||
@dimensions = Admin::Metrics::Dimension.retrieve( |
||||
params[:keys], |
||||
params[:start_at], |
||||
params[:end_at], |
||||
params[:limit] |
||||
) |
||||
end |
||||
end |
@ -0,0 +1,22 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class Api::V1::Admin::MeasuresController < Api::BaseController |
||||
protect_from_forgery with: :exception |
||||
|
||||
before_action :require_staff! |
||||
before_action :set_measures |
||||
|
||||
def create |
||||
render json: @measures, each_serializer: REST::Admin::MeasureSerializer |
||||
end |
||||
|
||||
private |
||||
|
||||
def set_measures |
||||
@measures = Admin::Metrics::Measure.retrieve( |
||||
params[:keys], |
||||
params[:start_at], |
||||
params[:end_at] |
||||
) |
||||
end |
||||
end |
@ -0,0 +1,22 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class Api::V1::Admin::RetentionController < Api::BaseController |
||||
protect_from_forgery with: :exception |
||||
|
||||
before_action :require_staff! |
||||
before_action :set_cohorts |
||||
|
||||
def create |
||||
render json: @cohorts, each_serializer: REST::Admin::CohortSerializer |
||||
end |
||||
|
||||
private |
||||
|
||||
def set_cohorts |
||||
@cohorts = Admin::Metrics::Retention.new( |
||||
params[:start_at], |
||||
params[:end_at], |
||||
params[:frequency] |
||||
).cohorts |
||||
end |
||||
end |
@ -0,0 +1,16 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class Api::V1::Admin::TrendsController < Api::BaseController |
||||
before_action :require_staff! |
||||
before_action :set_trends |
||||
|
||||
def index |
||||
render json: @trends, each_serializer: REST::Admin::TagSerializer |
||||
end |
||||
|
||||
private |
||||
|
||||
def set_trends |
||||
@trends = TrendingTags.get(10, filtered: false) |
||||
end |
||||
end |
@ -0,0 +1,40 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class StatusesCleanupController < ApplicationController |
||||
layout 'admin' |
||||
|
||||
before_action :authenticate_user! |
||||
before_action :set_policy |
||||
before_action :set_body_classes |
||||
before_action :set_pack |
||||
|
||||
def show; end |
||||
|
||||
def update |
||||
if @policy.update(resource_params) |
||||
redirect_to statuses_cleanup_path, notice: I18n.t('generic.changes_saved_msg') |
||||
else |
||||
render action: :show |
||||
end |
||||
rescue ActionController::ParameterMissing |
||||
# Do nothing |
||||
end |
||||
|
||||
private |
||||
|
||||
def set_pack |
||||
use_pack 'settings' |
||||
end |
||||
|
||||
def set_policy |
||||
@policy = current_account.statuses_cleanup_policy || current_account.build_statuses_cleanup_policy(enabled: false) |
||||
end |
||||
|
||||
def resource_params |
||||
params.require(:account_statuses_cleanup_policy).permit(:enabled, :min_status_age, :keep_direct, :keep_pinned, :keep_polls, :keep_media, :keep_self_fav, :keep_self_bookmark, :min_favs, :min_reblogs) |
||||
end |
||||
|
||||
def set_body_classes |
||||
@body_classes = 'admin' |
||||
end |
||||
end |
@ -0,0 +1,115 @@ |
||||
import React from 'react'; |
||||
import PropTypes from 'prop-types'; |
||||
import api from 'flavours/glitch/util/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, |
||||
}; |
||||
|
||||
state = { |
||||
loading: true, |
||||
data: null, |
||||
}; |
||||
|
||||
componentDidMount () { |
||||
const { measure, start_at, end_at } = this.props; |
||||
|
||||
api().post('/api/v1/admin/measures', { keys: [measure], start_at, end_at }).then(res => { |
||||
this.setState({ |
||||
loading: false, |
||||
data: res.data, |
||||
}); |
||||
}).catch(err => { |
||||
console.error(err); |
||||
}); |
||||
} |
||||
|
||||
render () { |
||||
const { label, href } = 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 = percIncrease(measure.previous_total * 1, measure.total * 1); |
||||
|
||||
content = ( |
||||
<React.Fragment> |
||||
<span className='sparkline__value__total'><FormattedNumber value={measure.total} /></span> |
||||
<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'> |
||||
{inner} |
||||
</a> |
||||
); |
||||
} else { |
||||
return ( |
||||
<div className='sparkline'> |
||||
{inner} |
||||
</div> |
||||
); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,92 @@ |
||||
import React from 'react'; |
||||
import PropTypes from 'prop-types'; |
||||
import api from 'flavours/glitch/util/api'; |
||||
import { FormattedNumber } from 'react-intl'; |
||||
import { roundTo10 } from 'flavours/glitch/util/numbers'; |
||||
import Skeleton from 'flavours/glitch/components/skeleton'; |
||||
|
||||
export default class Dimension extends React.PureComponent { |
||||
|
||||
static propTypes = { |
||||
dimension: PropTypes.string.isRequired, |
||||
start_at: PropTypes.string.isRequired, |
||||
end_at: PropTypes.string.isRequired, |
||||
limit: PropTypes.number.isRequired, |
||||
label: PropTypes.string.isRequired, |
||||
}; |
||||
|
||||
state = { |
||||
loading: true, |
||||
data: null, |
||||
}; |
||||
|
||||
componentDidMount () { |
||||
const { start_at, end_at, dimension, limit } = this.props; |
||||
|
||||
api().post('/api/v1/admin/dimensions', { keys: [dimension], start_at, end_at, limit }).then(res => { |
||||
this.setState({ |
||||
loading: false, |
||||
data: res.data, |
||||
}); |
||||
}).catch(err => { |
||||
console.error(err); |
||||
}); |
||||
} |
||||
|
||||
render () { |
||||
const { label, limit } = this.props; |
||||
const { loading, data } = this.state; |
||||
|
||||
let content; |
||||
|
||||
if (loading) { |
||||
content = ( |
||||
<table> |
||||
<tbody> |
||||
{Array.from(Array(limit)).map((_, i) => ( |
||||
<tr className='dimension__item' key={i}> |
||||
<td className='dimension__item__key'> |
||||
<Skeleton width={100} /> |
||||
</td> |
||||
|
||||
<td className='dimension__item__value'> |
||||
<Skeleton width={60} /> |
||||
</td> |
||||
</tr> |
||||
))} |
||||
</tbody> |
||||
</table> |
||||
); |
||||
} else { |
||||
const sum = data[0].data.reduce((sum, cur) => sum + (cur.value * 1), 0); |
||||
|
||||
content = ( |
||||
<table> |
||||
<tbody> |
||||
{data[0].data.map(item => ( |
||||
<tr className='dimension__item' key={item.key}> |
||||
<td className='dimension__item__key'> |
||||
<span className={`dimension__item__indicator dimension__item__indicator--${roundTo10(((item.value * 1) / sum) * 100)}`} /> |
||||
<span title={item.key}>{item.human_key}</span> |
||||
</td> |
||||
|
||||
<td className='dimension__item__value'> |
||||
{typeof item.human_value !== 'undefined' ? item.human_value : <FormattedNumber value={item.value} />} |
||||
</td> |
||||
</tr> |
||||
))} |
||||
</tbody> |
||||
</table> |
||||
); |
||||
} |
||||
|
||||
return ( |
||||
<div className='dimension'> |
||||
<h4>{label}</h4> |
||||
|
||||
{content} |
||||
</div> |
||||
); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,141 @@ |
||||
import React from 'react'; |
||||
import PropTypes from 'prop-types'; |
||||
import api from 'flavours/glitch/util/api'; |
||||
import { FormattedMessage, FormattedNumber, FormattedDate } from 'react-intl'; |
||||
import classNames from 'classnames'; |
||||
import { roundTo10 } from 'flavours/glitch/util/numbers'; |
||||
|
||||
const dateForCohort = cohort => { |
||||
switch(cohort.frequency) { |
||||
case 'day': |
||||
return <FormattedDate value={cohort.period} month='long' day='2-digit' />; |
||||
default: |
||||
return <FormattedDate value={cohort.period} month='long' year='numeric' />; |
||||
} |
||||
}; |
||||
|
||||
export default class Retention extends React.PureComponent { |
||||
|
||||
static propTypes = { |
||||
start_at: PropTypes.string, |
||||
end_at: PropTypes.string, |
||||
frequency: PropTypes.string, |
||||
}; |
||||
|
||||
state = { |
||||
loading: true, |
||||
data: null, |
||||
}; |
||||
|
||||
componentDidMount () { |
||||
const { start_at, end_at, frequency } = this.props; |
||||
|
||||
api().post('/api/v1/admin/retention', { start_at, end_at, frequency }).then(res => { |
||||
this.setState({ |
||||
loading: false, |
||||
data: res.data, |
||||
}); |
||||
}).catch(err => { |
||||
console.error(err); |
||||
}); |
||||
} |
||||
|
||||
render () { |
||||
const { loading, data } = this.state; |
||||
|
||||
let content; |
||||
|
||||
if (loading) { |
||||
content = <FormattedMessage id='loading_indicator.label' defaultMessage='Loading...' />; |
||||
} else { |
||||
content = ( |
||||
<table className='retention__table'> |
||||
<thead> |
||||
<tr> |
||||
<th> |
||||
<div className='retention__table__date retention__table__label'> |
||||
<FormattedMessage id='admin.dashboard.retention.cohort' defaultMessage='Sign-up month' /> |
||||
</div> |
||||
</th> |
||||
|
||||
<th> |
||||
<div className='retention__table__number retention__table__label'> |
||||
<FormattedMessage id='admin.dashboard.retention.cohort_size' defaultMessage='New users' /> |
||||
</div> |
||||
</th> |
||||
|
||||
{data[0].data.slice(1).map((retention, i) => ( |
||||
<th key={retention.date}> |
||||
<div className='retention__table__number retention__table__label'> |
||||
{i + 1} |
||||
</div> |
||||
</th> |
||||
))} |
||||
</tr> |
||||
|
||||
<tr> |
||||
<td> |
||||
<div className='retention__table__date retention__table__average'> |
||||
<FormattedMessage id='admin.dashboard.retention.average' defaultMessage='Average' /> |
||||
</div> |
||||
</td> |
||||
|
||||
<td> |
||||
<div className='retention__table__size'> |
||||
<FormattedNumber value={data.reduce((sum, cohort, i) => sum + ((cohort.data[0].value * 1) - sum) / (i + 1), 0)} maximumFractionDigits={0} /> |
||||
</div> |
||||
</td> |
||||
|
||||
{data[0].data.slice(1).map((retention, i) => { |
||||
const average = data.reduce((sum, cohort, k) => cohort.data[i + 1] ? sum + (cohort.data[i + 1].percent - sum)/(k + 1) : sum, 0); |
||||
|
||||
return ( |
||||
<td key={retention.date}> |
||||
<div className={classNames('retention__table__box', 'retention__table__average', `retention__table__box--${roundTo10(average * 100)}`)}> |
||||
<FormattedNumber value={average} style='percent' /> |
||||
</div> |
||||
</td> |
||||
); |
||||
})} |
||||
</tr> |
||||
</thead> |
||||
|
||||
<tbody> |
||||
{data.slice(0, -1).map(cohort => ( |
||||
<tr key={cohort.period}> |
||||
<td> |
||||
<div className='retention__table__date'> |
||||
{dateForCohort(cohort)} |
||||
</div> |
||||
</td> |
||||
|
||||
<td> |
||||
<div className='retention__table__size'> |
||||
<FormattedNumber value={cohort.data[0].value} /> |
||||
</div> |
||||
</td> |
||||
|
||||
{cohort.data.slice(1).map(retention => ( |
||||
<td key={retention.date}> |
||||
<div className={classNames('retention__table__box', `retention__table__box--${roundTo10(retention.percent * 100)}`)}> |
||||
<FormattedNumber value={retention.percent} style='percent' /> |
||||
</div> |
||||
</td> |
||||
))} |
||||
</tr> |
||||
))} |
||||
</tbody> |
||||
</table> |
||||
); |
||||
} |
||||
|
||||
return ( |
||||
<div className='retention'> |
||||
<h4><FormattedMessage id='admin.dashboard.retention' defaultMessage='Retention' /></h4> |
||||
|
||||
{content} |
||||
</div> |
||||
); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,73 @@ |
||||
import React from 'react'; |
||||
import PropTypes from 'prop-types'; |
||||
import api from 'flavours/glitch/util/api'; |
||||
import { FormattedMessage } from 'react-intl'; |
||||
import classNames from 'classnames'; |
||||
import Hashtag from 'flavours/glitch/components/hashtag'; |
||||
|
||||
export default class Trends extends React.PureComponent { |
||||
|
||||
static propTypes = { |
||||
limit: PropTypes.number.isRequired, |
||||
}; |
||||
|
||||
state = { |
||||
loading: true, |
||||
data: null, |
||||
}; |
||||
|
||||
componentDidMount () { |
||||
const { limit } = this.props; |
||||
|
||||
api().get('/api/v1/admin/trends', { params: { limit } }).then(res => { |
||||
this.setState({ |
||||
loading: false, |
||||
data: res.data, |
||||
}); |
||||
}).catch(err => { |
||||
console.error(err); |
||||
}); |
||||
} |
||||
|
||||
render () { |
||||
const { limit } = this.props; |
||||
const { loading, data } = this.state; |
||||
|
||||
let content; |
||||
|
||||
if (loading) { |
||||
content = ( |
||||
<div> |
||||
{Array.from(Array(limit)).map((_, i) => ( |
||||
<Hashtag key={i} /> |
||||
))} |
||||
</div> |
||||
); |
||||
} else { |
||||
content = ( |
||||
<div> |
||||
{data.map(hashtag => ( |
||||
<Hashtag |
||||
key={hashtag.name} |
||||
name={hashtag.name} |
||||
href={`/admin/tags/${hashtag.id}`} |
||||
people={hashtag.history[0].accounts * 1 + hashtag.history[1].accounts * 1} |
||||
uses={hashtag.history[0].uses * 1 + hashtag.history[1].uses * 1} |
||||
history={hashtag.history.reverse().map(day => day.uses)} |
||||
className={classNames(hashtag.requires_review && 'trends__item--requires-review', !hashtag.trendable && !hashtag.requires_review && 'trends__item--disabled')} |
||||
/> |
||||
))} |
||||
</div> |
||||
); |
||||
} |
||||
|
||||
return ( |
||||
<div className='trends trends--compact'> |
||||
<h4><FormattedMessage id='trends.trending_now' defaultMessage='Trending now' /></h4> |
||||
|
||||
{content} |
||||
</div> |
||||
); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,11 @@ |
||||
import React from 'react'; |
||||
import PropTypes from 'prop-types'; |
||||
|
||||
const Skeleton = ({ width, height }) => <span className='skeleton' style={{ width, height }}>‌</span>; |
||||
|
||||
Skeleton.propTypes = { |
||||
width: PropTypes.number, |
||||
height: PropTypes.number, |
||||
}; |
||||
|
||||
export default Skeleton; |
@ -0,0 +1,26 @@ |
||||
import React from 'react'; |
||||
import PropTypes from 'prop-types'; |
||||
import { IntlProvider, addLocaleData } from 'react-intl'; |
||||
import { getLocale } from 'mastodon/locales'; |
||||
|
||||
const { localeData, messages } = getLocale(); |
||||
addLocaleData(localeData); |
||||
|
||||
export default class AdminComponent extends React.PureComponent { |
||||
|
||||
static propTypes = { |
||||
locale: PropTypes.string.isRequired, |
||||
children: PropTypes.node.isRequired, |
||||
}; |
||||
|
||||
render () { |
||||
const { locale, children } = this.props; |
||||
|
||||
return ( |
||||
<IntlProvider locale={locale} messages={messages}> |
||||
{children} |
||||
</IntlProvider> |
||||
); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,18 @@ |
||||
import { ScrollContainer as OriginalScrollContainer } from 'react-router-scroll-4'; |
||||
|
||||
// ScrollContainer is used to automatically scroll to the top when pushing a
|
||||
// new history state and remembering the scroll position when going back.
|
||||
// There are a few things we need to do differently, though.
|
||||
const defaultShouldUpdateScroll = (prevRouterProps, { location }) => { |
||||
// If the change is caused by opening a modal, do not scroll to top
|
||||
return !(location.state?.mastodonModalKey && location.state?.mastodonModalKey !== prevRouterProps?.location?.state?.mastodonModalKey); |
||||
}; |
||||
|
||||
export default |
||||
class ScrollContainer extends OriginalScrollContainer { |
||||
|
||||
static defaultProps = { |
||||
shouldUpdateScroll: defaultShouldUpdateScroll, |
||||
}; |
||||
|
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue