mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
loading_spinner.tsx converted to functional component. (#25115)
* loading_spinner.tsx converted to functional component. * merging changes revised * fixing CI failures * fixing linting errors * snapshot updation * Update snapshot * Update snapshot * update snapshot * Update snapshot --------- Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
parent
42b3ef0238
commit
7f457ffed3
@ -4,7 +4,7 @@ exports[`components/LoadingImagePreview should match snapshot 1`] = `
|
|||||||
<div
|
<div
|
||||||
className="view-image__loading"
|
className="view-image__loading"
|
||||||
>
|
>
|
||||||
<injectIntl(LoadingSpinner) />
|
<Memo(LoadingSpinner) />
|
||||||
<span
|
<span
|
||||||
className="loader-percent"
|
className="loader-percent"
|
||||||
>
|
>
|
||||||
@ -17,7 +17,7 @@ exports[`components/LoadingImagePreview should match snapshot 2`] = `
|
|||||||
<div
|
<div
|
||||||
className="view-image__loading"
|
className="view-image__loading"
|
||||||
>
|
>
|
||||||
<injectIntl(LoadingSpinner) />
|
<Memo(LoadingSpinner) />
|
||||||
<span
|
<span
|
||||||
className="loader-percent"
|
className="loader-percent"
|
||||||
>
|
>
|
||||||
|
@ -4,7 +4,7 @@ exports[`component/PDFPreview should match snapshot, loading 1`] = `
|
|||||||
<div
|
<div
|
||||||
className="view-image__loading"
|
className="view-image__loading"
|
||||||
>
|
>
|
||||||
<injectIntl(LoadingSpinner) />
|
<Memo(LoadingSpinner) />
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ exports[`components/admin_console/data_grid/DataGrid should match snapshot while
|
|||||||
<div
|
<div
|
||||||
className="DataGrid_loading"
|
className="DataGrid_loading"
|
||||||
>
|
>
|
||||||
<injectIntl(LoadingSpinner) />
|
<Memo(LoadingSpinner) />
|
||||||
<MemoizedFormattedMessage
|
<MemoizedFormattedMessage
|
||||||
defaultMessage="Loading"
|
defaultMessage="Loading"
|
||||||
id="admin.data_grid.loading"
|
id="admin.data_grid.loading"
|
||||||
|
@ -75,7 +75,7 @@ exports[`AppsFormComponent should set match snapshot 1`] = `
|
|||||||
<div
|
<div
|
||||||
className="apps-form-modal-body-common apps-form-modal-body-loaded"
|
className="apps-form-modal-body-common apps-form-modal-body-loaded"
|
||||||
>
|
>
|
||||||
<injectIntl(LoadingSpinner)
|
<Memo(LoadingSpinner)
|
||||||
style={
|
style={
|
||||||
Object {
|
Object {
|
||||||
"fontSize": "24px",
|
"fontSize": "24px",
|
||||||
|
@ -19,64 +19,21 @@ exports[`components/widgets/loading/LoadingWrapper showing spinner with text 1`]
|
|||||||
loading={true}
|
loading={true}
|
||||||
text="test"
|
text="test"
|
||||||
>
|
>
|
||||||
<injectIntl(LoadingSpinner)
|
<Memo(LoadingSpinner)
|
||||||
text="test"
|
text="test"
|
||||||
>
|
>
|
||||||
<LoadingSpinner
|
<span
|
||||||
intl={
|
className="LoadingSpinner with-text"
|
||||||
Object {
|
data-testid="loadingSpinner"
|
||||||
"$t": [Function],
|
id="loadingSpinner"
|
||||||
"defaultFormats": Object {},
|
|
||||||
"defaultLocale": "en",
|
|
||||||
"defaultRichTextElements": undefined,
|
|
||||||
"fallbackOnEmptyString": true,
|
|
||||||
"formatDate": [Function],
|
|
||||||
"formatDateTimeRange": [Function],
|
|
||||||
"formatDateToParts": [Function],
|
|
||||||
"formatDisplayName": [Function],
|
|
||||||
"formatList": [Function],
|
|
||||||
"formatListToParts": [Function],
|
|
||||||
"formatMessage": [Function],
|
|
||||||
"formatNumber": [Function],
|
|
||||||
"formatNumberToParts": [Function],
|
|
||||||
"formatPlural": [Function],
|
|
||||||
"formatRelativeTime": [Function],
|
|
||||||
"formatTime": [Function],
|
|
||||||
"formatTimeToParts": [Function],
|
|
||||||
"formats": Object {},
|
|
||||||
"formatters": Object {
|
|
||||||
"getDateTimeFormat": [Function],
|
|
||||||
"getDisplayNames": [Function],
|
|
||||||
"getListFormat": [Function],
|
|
||||||
"getMessageFormat": [Function],
|
|
||||||
"getNumberFormat": [Function],
|
|
||||||
"getPluralRules": [Function],
|
|
||||||
"getRelativeTimeFormat": [Function],
|
|
||||||
},
|
|
||||||
"locale": "en",
|
|
||||||
"messages": Object {},
|
|
||||||
"onError": [Function],
|
|
||||||
"onWarn": [Function],
|
|
||||||
"textComponent": "span",
|
|
||||||
"timeZone": "Etc/UTC",
|
|
||||||
"wrapRichTextChunksInFragment": undefined,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
text="test"
|
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
className="LoadingSpinner with-text"
|
className="fa fa-spinner fa-fw fa-pulse spinner"
|
||||||
data-testid="loadingSpinner"
|
title="Loading Icon"
|
||||||
id="loadingSpinner"
|
/>
|
||||||
>
|
test
|
||||||
<span
|
</span>
|
||||||
className="fa fa-spinner fa-fw fa-pulse spinner"
|
</Memo(LoadingSpinner)>
|
||||||
title="Loading Icon"
|
|
||||||
/>
|
|
||||||
test
|
|
||||||
</span>
|
|
||||||
</LoadingSpinner>
|
|
||||||
</injectIntl(LoadingSpinner)>
|
|
||||||
</Memo(LoadingWrapper)>
|
</Memo(LoadingWrapper)>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -84,62 +41,19 @@ exports[`components/widgets/loading/LoadingWrapper showing spinner without text
|
|||||||
<Memo(LoadingWrapper)
|
<Memo(LoadingWrapper)
|
||||||
loading={true}
|
loading={true}
|
||||||
>
|
>
|
||||||
<injectIntl(LoadingSpinner)
|
<Memo(LoadingSpinner)
|
||||||
text={null}
|
text={null}
|
||||||
>
|
>
|
||||||
<LoadingSpinner
|
<span
|
||||||
intl={
|
className="LoadingSpinner"
|
||||||
Object {
|
data-testid="loadingSpinner"
|
||||||
"$t": [Function],
|
id="loadingSpinner"
|
||||||
"defaultFormats": Object {},
|
|
||||||
"defaultLocale": "en",
|
|
||||||
"defaultRichTextElements": undefined,
|
|
||||||
"fallbackOnEmptyString": true,
|
|
||||||
"formatDate": [Function],
|
|
||||||
"formatDateTimeRange": [Function],
|
|
||||||
"formatDateToParts": [Function],
|
|
||||||
"formatDisplayName": [Function],
|
|
||||||
"formatList": [Function],
|
|
||||||
"formatListToParts": [Function],
|
|
||||||
"formatMessage": [Function],
|
|
||||||
"formatNumber": [Function],
|
|
||||||
"formatNumberToParts": [Function],
|
|
||||||
"formatPlural": [Function],
|
|
||||||
"formatRelativeTime": [Function],
|
|
||||||
"formatTime": [Function],
|
|
||||||
"formatTimeToParts": [Function],
|
|
||||||
"formats": Object {},
|
|
||||||
"formatters": Object {
|
|
||||||
"getDateTimeFormat": [Function],
|
|
||||||
"getDisplayNames": [Function],
|
|
||||||
"getListFormat": [Function],
|
|
||||||
"getMessageFormat": [Function],
|
|
||||||
"getNumberFormat": [Function],
|
|
||||||
"getPluralRules": [Function],
|
|
||||||
"getRelativeTimeFormat": [Function],
|
|
||||||
},
|
|
||||||
"locale": "en",
|
|
||||||
"messages": Object {},
|
|
||||||
"onError": [Function],
|
|
||||||
"onWarn": [Function],
|
|
||||||
"textComponent": "span",
|
|
||||||
"timeZone": "Etc/UTC",
|
|
||||||
"wrapRichTextChunksInFragment": undefined,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
text={null}
|
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
className="LoadingSpinner"
|
className="fa fa-spinner fa-fw fa-pulse spinner"
|
||||||
data-testid="loadingSpinner"
|
title="Loading Icon"
|
||||||
id="loadingSpinner"
|
/>
|
||||||
>
|
</span>
|
||||||
<span
|
</Memo(LoadingSpinner)>
|
||||||
className="fa fa-spinner fa-fw fa-pulse spinner"
|
|
||||||
title="Loading Icon"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</LoadingSpinner>
|
|
||||||
</injectIntl(LoadingSpinner)>
|
|
||||||
</Memo(LoadingWrapper)>
|
</Memo(LoadingWrapper)>
|
||||||
`;
|
`;
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
|
import {shallow} from 'enzyme';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import {shallowWithIntl} from 'tests/helpers/intl-test-helper';
|
|
||||||
|
|
||||||
import LoadingSpinner from './loading_spinner';
|
import LoadingSpinner from './loading_spinner';
|
||||||
|
|
||||||
describe('components/widgets/loadingLoadingSpinner', () => {
|
describe('components/widgets/loadingLoadingSpinner', () => {
|
||||||
test('showing spinner with text', () => {
|
test('showing spinner with text', () => {
|
||||||
const wrapper = shallowWithIntl(<LoadingSpinner text='test'/>);
|
const wrapper = shallow(<LoadingSpinner text='test'/>);
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
test('showing spinner without text', () => {
|
test('showing spinner without text', () => {
|
||||||
const wrapper = shallowWithIntl(<LoadingSpinner/>);
|
const wrapper = shallow(<LoadingSpinner/>);
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,36 +1,30 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
import React, {PureComponent} from 'react';
|
import classNames from 'classnames';
|
||||||
import type {ReactNode, CSSProperties} from 'react';
|
import React from 'react';
|
||||||
import {injectIntl, type IntlShape} from 'react-intl';
|
import {useIntl} from 'react-intl';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
text?: ReactNode;
|
text?: React.ReactNode;
|
||||||
style?: CSSProperties;
|
style?: React.CSSProperties;
|
||||||
intl: IntlShape;
|
|
||||||
}
|
}
|
||||||
class LoadingSpinner extends PureComponent<Props> {
|
const LoadingSpinner = ({text = null, style}: Props) => {
|
||||||
public static defaultProps: Partial<Props> = {
|
const {formatMessage} = useIntl();
|
||||||
text: null,
|
return (
|
||||||
};
|
<span
|
||||||
|
id='loadingSpinner'
|
||||||
public render() {
|
className={classNames('LoadingSpinner', {'with-text': Boolean(text)})}
|
||||||
return (
|
style={style}
|
||||||
|
data-testid='loadingSpinner'
|
||||||
|
>
|
||||||
<span
|
<span
|
||||||
id='loadingSpinner'
|
className='fa fa-spinner fa-fw fa-pulse spinner'
|
||||||
className={'LoadingSpinner' + (this.props.text ? ' with-text' : '')}
|
title={formatMessage({id: 'generic_icons.loading', defaultMessage: 'Loading Icon'})}
|
||||||
style={this.props.style}
|
/>
|
||||||
data-testid='loadingSpinner'
|
{text}
|
||||||
>
|
</span>
|
||||||
<span
|
);
|
||||||
className='fa fa-spinner fa-fw fa-pulse spinner'
|
};
|
||||||
title={this.props.intl.formatMessage({id: 'generic_icons.loading', defaultMessage: 'Loading Icon'})}
|
|
||||||
/>
|
|
||||||
{this.props.text}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default injectIntl(LoadingSpinner);
|
export default React.memo(LoadingSpinner);
|
||||||
|
Loading…
Reference in New Issue
Block a user