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>
Этот коммит содержится в:
Muzakir Shah
2023-11-07 14:51:21 +05:00
коммит произвёл GitHub
родитель 42b3ef0238
Коммит 7f457ffed3
7 изменённых файлов: 51 добавлений и 144 удалений

Просмотреть файл

@@ -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,49 +19,7 @@ exports[`components/widgets/loading/LoadingWrapper showing spinner with text 1`]
loading={true} loading={true}
text="test" text="test"
> >
<injectIntl(LoadingSpinner) <Memo(LoadingSpinner)
text="test"
>
<LoadingSpinner
intl={
Object {
"$t": [Function],
"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" text="test"
> >
<span <span
@@ -75,8 +33,7 @@ exports[`components/widgets/loading/LoadingWrapper showing spinner with text 1`]
/> />
test test
</span> </span>
</LoadingSpinner> </Memo(LoadingSpinner)>
</injectIntl(LoadingSpinner)>
</Memo(LoadingWrapper)> </Memo(LoadingWrapper)>
`; `;
@@ -84,49 +41,7 @@ exports[`components/widgets/loading/LoadingWrapper showing spinner without text
<Memo(LoadingWrapper) <Memo(LoadingWrapper)
loading={true} loading={true}
> >
<injectIntl(LoadingSpinner) <Memo(LoadingSpinner)
text={null}
>
<LoadingSpinner
intl={
Object {
"$t": [Function],
"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} text={null}
> >
<span <span
@@ -139,7 +54,6 @@ exports[`components/widgets/loading/LoadingWrapper showing spinner without text
title="Loading Icon" title="Loading Icon"
/> />
</span> </span>
</LoadingSpinner> </Memo(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,
};
public render() {
return ( return (
<span <span
id='loadingSpinner' id='loadingSpinner'
className={'LoadingSpinner' + (this.props.text ? ' with-text' : '')} className={classNames('LoadingSpinner', {'with-text': Boolean(text)})}
style={this.props.style} style={style}
data-testid='loadingSpinner' data-testid='loadingSpinner'
> >
<span <span
className='fa fa-spinner fa-fw fa-pulse spinner' className='fa fa-spinner fa-fw fa-pulse spinner'
title={this.props.intl.formatMessage({id: 'generic_icons.loading', defaultMessage: 'Loading Icon'})} title={formatMessage({id: 'generic_icons.loading', defaultMessage: 'Loading Icon'})}
/> />
{this.props.text} {text}
</span> </span>
); );
} };
}
export default injectIntl(LoadingSpinner); export default React.memo(LoadingSpinner);