Skip to content

Commit

Permalink
Merge pull request #159 from kmycode/upstream-20231021
Browse files Browse the repository at this point in the history
Upstream 20231021
  • Loading branch information
kmycode authored Oct 26, 2023
2 parents 3caa413 + a16f982 commit 551a9e8
Show file tree
Hide file tree
Showing 133 changed files with 1,161 additions and 819 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ module.exports = {
},
// Common React utilities
{
pattern: '{classnames,react-helmet,react-router-dom}',
pattern: '{classnames,react-helmet,react-router,react-router-dom}',
group: 'external',
position: 'before',
},
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ jobs:
BUNDLE_WITH: 'pam_authentication test'
CI_JOBS: ${{ matrix.ci_job }}/4
ES_ENABLED: false
GITHUB_RSPEC: ${{ matrix.ruby-version == '.ruby-version' && github.event.pull_request && 'true' }}

strategy:
fail-fast: false
Expand Down
41 changes: 0 additions & 41 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,6 @@ Lint/UnusedBlockArgument:
- 'config/initializers/paperclip.rb'
- 'config/initializers/simple_form.rb'

# This cop supports unsafe autocorrection (--autocorrect-all).
Lint/UselessAssignment:
Exclude:
- 'app/services/activitypub/process_status_update_service.rb'
- 'config/initializers/3_omniauth.rb'
- 'db/migrate/20190511134027_add_silenced_at_suspended_at_to_accounts.rb'
- 'db/post_migrate/20190511152737_remove_suspended_silenced_account_fields.rb'
- 'spec/controllers/api/v1/favourites_controller_spec.rb'
- 'spec/controllers/concerns/account_controller_concern_spec.rb'
- 'spec/helpers/jsonld_helper_spec.rb'
- 'spec/models/account_spec.rb'
- 'spec/models/domain_block_spec.rb'
- 'spec/models/status_spec.rb'
- 'spec/models/user_spec.rb'
- 'spec/models/webauthn_credentials_spec.rb'
- 'spec/services/account_search_service_spec.rb'
- 'spec/services/post_status_service_spec.rb'
- 'spec/services/precompute_feed_service_spec.rb'
- 'spec/services/resolve_url_service_spec.rb'
- 'spec/views/statuses/show.html.haml_spec.rb'

# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 144
Expand All @@ -86,26 +65,6 @@ Metrics/CyclomaticComplexity:
Metrics/PerceivedComplexity:
Max: 27

# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Naming/VariableNumber:
Exclude:
- 'db/migrate/20180106000232_add_index_on_statuses_for_api_v1_accounts_account_id_statuses.rb'
- 'db/migrate/20180514140000_revert_index_change_on_statuses_for_api_v1_accounts_account_id_statuses.rb'
- 'db/migrate/20190820003045_update_statuses_index.rb'
- 'db/migrate/20190823221802_add_local_index_to_statuses.rb'
- 'db/migrate/20200119112504_add_public_index_to_statuses.rb'
- 'spec/models/account_spec.rb'
- 'spec/models/domain_block_spec.rb'
- 'spec/models/user_spec.rb'

# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SafeMultiline.
Performance/DeletePrefix:
Exclude:
- 'app/models/featured_tag.rb'

Performance/MapMethodChain:
Exclude:
- 'app/models/feed.rb'
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/api/v1/apps/credentials_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

class Api::V1::Apps::CredentialsController < Api::BaseController
before_action -> { doorkeeper_authorize! :read }

def show
render json: doorkeeper_token.application, serializer: REST::ApplicationSerializer, fields: %i(name website vapid_key)
return doorkeeper_render_error unless valid_doorkeeper_token?

render json: doorkeeper_token.application, serializer: REST::ApplicationSerializer, fields: %i(name website vapid_key client_id scopes)
end
end
19 changes: 19 additions & 0 deletions app/helpers/admin/disputes_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Admin
module DisputesHelper
def strike_action_label(appeal)
t(key_for_action(appeal),
scope: 'admin.strikes.actions',
name: content_tag(:span, appeal.strike.account.username, class: 'username'),
target: content_tag(:span, appeal.account.username, class: 'target'))
.html_safe
end

private

def key_for_action(appeal)
AccountWarning.actions.slice(appeal.strike.action).keys.first
end
end
end
4 changes: 4 additions & 0 deletions app/helpers/formatting_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def linkify(text, options = {})
TextFormatter.new(text, options).to_s
end

def url_for_preview_card(preview_card)
preview_card.url
end

def extract_status_plain_text(status)
PlainTextFormatter.new(status.text, status.local?).to_s
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, fireEvent, screen } from '@testing-library/react';
import renderer from 'react-test-renderer';

import Button from '../button';
import { Button } from '../button';

describe('<Button />', () => {
it('renders a button element', () => {
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/components/account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { VerifiedBadge } from 'mastodon/components/verified_badge';
import { me } from '../initial_state';

import { Avatar } from './avatar';
import Button from './button';
import { Button } from './button';
import { FollowersCounter } from './counters';
import { DisplayName } from './display_name';
import { IconButton } from './icon_button';
Expand Down
58 changes: 0 additions & 58 deletions app/javascript/mastodon/components/button.jsx

This file was deleted.

58 changes: 58 additions & 0 deletions app/javascript/mastodon/components/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { useCallback } from 'react';

import classNames from 'classnames';

interface BaseProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
block?: boolean;
secondary?: boolean;
text?: JSX.Element;
}

interface PropsWithChildren extends BaseProps {
text?: never;
}

interface PropsWithText extends BaseProps {
text: JSX.Element;
children: never;
}

type Props = PropsWithText | PropsWithChildren;

export const Button: React.FC<Props> = ({
text,
type = 'button',
onClick,
disabled,
block,
secondary,
className,
title,
children,
...props
}) => {
const handleClick = useCallback<React.MouseEventHandler<HTMLButtonElement>>(
(e) => {
if (!disabled && onClick) {
onClick(e);
}
},
[disabled, onClick],
);

return (
<button
className={classNames('button', className, {
'button-secondary': secondary,
'button--block': block,
})}
disabled={disabled}
onClick={handleClick}
title={title}
type={type}
{...props}
>
{text ?? children}
</button>
);
};
21 changes: 11 additions & 10 deletions app/javascript/mastodon/components/column_back_button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@ import { createPortal } from 'react-dom';

import { FormattedMessage } from 'react-intl';

import { Icon } from 'mastodon/components/icon';
import { withRouter } from 'react-router-dom';

export default class ColumnBackButton extends PureComponent {
import { Icon } from 'mastodon/components/icon';
import { WithRouterPropTypes } from 'mastodon/utils/react_router';

static contextTypes = {
router: PropTypes.object,
};
class ColumnBackButton extends PureComponent {

static propTypes = {
multiColumn: PropTypes.bool,
onClick: PropTypes.func,
...WithRouterPropTypes,
};

handleClick = () => {
const { router } = this.context;
const { onClick } = this.props;
const { onClick, history } = this.props;

if (onClick) {
onClick();
} else if (router.history.location?.state?.fromMastodon) {
router.history.goBack();
} else if (history.location?.state?.fromMastodon) {
history.goBack();
} else {
router.history.push('/');
history.push('/');
}
};

Expand Down Expand Up @@ -60,3 +59,5 @@ export default class ColumnBackButton extends PureComponent {
}

}

export default withRouter(ColumnBackButton);
21 changes: 11 additions & 10 deletions app/javascript/mastodon/components/column_header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { createPortal } from 'react-dom';
import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';

import classNames from 'classnames';
import { withRouter } from 'react-router-dom';

import { Icon } from 'mastodon/components/icon';
import { WithRouterPropTypes } from 'mastodon/utils/react_router';

const messages = defineMessages({
show: { id: 'column_header.show_settings', defaultMessage: 'Show settings' },
Expand All @@ -18,7 +20,6 @@ const messages = defineMessages({
class ColumnHeader extends PureComponent {

static contextTypes = {
router: PropTypes.object,
identity: PropTypes.object,
};

Expand All @@ -38,6 +39,7 @@ class ColumnHeader extends PureComponent {
onClick: PropTypes.func,
appendContent: PropTypes.node,
collapseIssues: PropTypes.bool,
...WithRouterPropTypes,
};

state = {
Expand All @@ -63,12 +65,12 @@ class ColumnHeader extends PureComponent {
};

handleBackClick = () => {
const { router } = this.context;
const { history } = this.props;

if (router.history.location?.state?.fromMastodon) {
router.history.goBack();
if (history.location?.state?.fromMastodon) {
history.goBack();
} else {
router.history.push('/');
history.push('/');
}
};

Expand All @@ -78,15 +80,14 @@ class ColumnHeader extends PureComponent {

handlePin = () => {
if (!this.props.pinned) {
this.context.router.history.replace('/');
this.props.history.replace('/');
}

this.props.onPin();
};

render () {
const { router } = this.context;
const { title, icon, active, children, pinned, multiColumn, extraButton, showBackButton, intl: { formatMessage }, placeholder, appendContent, collapseIssues } = this.props;
const { title, icon, active, children, pinned, multiColumn, extraButton, showBackButton, intl: { formatMessage }, placeholder, appendContent, collapseIssues, history } = this.props;
const { collapsed, animating } = this.state;

const wrapperClassName = classNames('column-header__wrapper', {
Expand Down Expand Up @@ -129,7 +130,7 @@ class ColumnHeader extends PureComponent {
pinButton = <button key='pin-button' className='text-btn column-header__setting-btn' onClick={this.handlePin}><Icon id='plus' /> <FormattedMessage id='column_header.pin' defaultMessage='Pin' /></button>;
}

if (!pinned && ((multiColumn && router.history.location?.state?.fromMastodon) || showBackButton)) {
if (!pinned && ((multiColumn && history.location?.state?.fromMastodon) || showBackButton)) {
backButton = (
<button onClick={this.handleBackClick} className='column-header__back-button'>
<Icon id='chevron-left' className='column-back-button__icon' fixedWidth />
Expand Down Expand Up @@ -215,4 +216,4 @@ class ColumnHeader extends PureComponent {

}

export default injectIntl(ColumnHeader);
export default injectIntl(withRouter(ColumnHeader));
Loading

0 comments on commit 551a9e8

Please sign in to comment.