Browse Source

SONAR-9936 Add loading spinner when doing the license preview

tags/6.7-RC1
Grégoire Aubert 6 years ago
parent
commit
37a16f6737

+ 2
- 2
server/sonar-web/src/main/js/app/components/AdminContainer.tsx View File

} }


fetchNavigationSettings = () => fetchNavigationSettings = () =>
getSettingsNavigation().then(r => this.props.setAdminPages(r.extensions), () => { });
getSettingsNavigation().then(r => this.props.setAdminPages(r.extensions), () => {});


fetchEditionStatus = () => fetchEditionStatus = () =>
getEditionStatus().then(editionStatus => this.props.setEditionStatus(editionStatus), () => { });
getEditionStatus().then(editionStatus => this.props.setEditionStatus(editionStatus), () => {});


render() { render() {
const { adminPages, organizationsEnabled } = this.props.appState; const { adminPages, organizationsEnabled } = this.props.appState;

+ 42
- 18
server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionSet.tsx View File

import * as classNames from 'classnames'; import * as classNames from 'classnames';
import { stringify } from 'querystring'; import { stringify } from 'querystring';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import DeferredSpinner from '../../../components/common/DeferredSpinner';
import { omitNil } from '../../../helpers/request'; import { omitNil } from '../../../helpers/request';
import { Edition, getFormData, getLicensePreview } from '../../../api/marketplace'; import { Edition, getFormData, getLicensePreview } from '../../../api/marketplace';
import { translate, translateWithParameters } from '../../../helpers/l10n'; import { translate, translateWithParameters } from '../../../helpers/l10n';
interface State { interface State {
license: string; license: string;
licenseEdition?: Edition; licenseEdition?: Edition;
loading: boolean;
previewStatus?: string; previewStatus?: string;
formData?: { formData?: {
serverId?: string; serverId?: string;


constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.state = { license: '' };
this.state = { license: '', loading: false };
this.fetchLicensePreview = debounce(this.fetchLicensePreview, 100); this.fetchLicensePreview = debounce(this.fetchLicensePreview, 100);
} }


this.mounted = false; this.mounted = false;
} }


fetchLicensePreview = (license: string) =>
fetchLicensePreview = (license: string) => {
this.setState({ loading: true });
getLicensePreview({ license }).then( getLicensePreview({ license }).then(
({ previewStatus, nextEditionKey }) => { ({ previewStatus, nextEditionKey }) => {
if (this.mounted) { if (this.mounted) {
} }
} }
); );
};


fetchFormData = () => { fetchFormData = () => {
getFormData().then( getFormData().then(
this.setState({ formData }); this.setState({ formData });
} }
}, },
() => {}
() => { }
); );
}; };


}; };


updateLicense = (license: string, licenseEdition?: Edition, previewStatus?: string) => { updateLicense = (license: string, licenseEdition?: Edition, previewStatus?: string) => {
this.setState({ license, licenseEdition, previewStatus });
this.setState({ license, licenseEdition, loading: false, previewStatus });
this.props.updateLicense(license, previewStatus); this.props.updateLicense(license, previewStatus);
}; };


renderAlert() {
const { licenseEdition, previewStatus } = this.state;
if (!previewStatus) {
return undefined;
}
return (
<p
className={classNames('alert spacer-top', {
'alert-warning': previewStatus === 'AUTOMATIC_INSTALL',
'alert-success': previewStatus === 'NO_INSTALL',
'alert-danger': previewStatus === 'MANUAL_INSTALL'
})}>
{translateWithParameters(
'marketplace.license_preview_status.' + previewStatus,
licenseEdition ? licenseEdition.name : translate('marketplace.commercial_edition')
)}
</p>
);
}

render() { render() {
const { className, edition } = this.props; const { className, edition } = this.props;
const { license, licenseEdition, previewStatus } = this.state;
const { license, loading } = this.state;


return ( return (
<div className={className}> <div className={className}>
style={{ resize: 'none' }} style={{ resize: 'none' }}
value={license} value={license}
/> />
{previewStatus && (
<p
className={classNames('alert spacer-top', {
'alert-warning': previewStatus === 'AUTOMATIC_INSTALL',
'alert-success': previewStatus === 'NO_INSTALL',
'alert-danger': previewStatus === 'MANUAL_INSTALL'
})}>
{translateWithParameters(
'marketplace.license_preview_status.' + previewStatus,
licenseEdition ? licenseEdition.name : translate('marketplace.commercial_edition')
)}
</p>
)}
<DeferredSpinner
className="spacer-top"
loading={loading}
customSpinner={
<p className="spacer-top">
<i className="spinner spacer-right text-bottom" />
{translate('marketplace.checking_license')}
</p>
}>
{this.renderAlert()}
</DeferredSpinner>
{edition && ( {edition && (
<a <a
className="display-inline-block spacer-top" className="display-inline-block spacer-top"

+ 15
- 0
server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionSet-test.tsx.snap View File

} }
value="" value=""
/> />
<DeferredSpinner
className="spacer-top"
customSpinner={
<p
className="spacer-top"
>
<i
className="spinner spacer-right text-bottom"
/>
marketplace.checking_license
</p>
}
loading={false}
timeout={100}
/>
<a <a
className="display-inline-block spacer-top" className="display-inline-block spacer-top"
href="license_url" href="license_url"

+ 5
- 2
server/sonar-web/src/main/js/components/common/DeferredSpinner.tsx View File

children?: JSX.Element; children?: JSX.Element;
className?: string; className?: string;
loading?: boolean; loading?: boolean;
timeout: number;
customSpinner?: JSX.Element;
timeout?: number;
} }


interface State { interface State {


render() { render() {
if (this.state.showSpinner) { if (this.state.showSpinner) {
return <i className={classNames('spinner', this.props.className)} />;
return (
this.props.customSpinner || <i className={classNames('spinner', this.props.className)} />
);
} }
return (this.props.children as JSX.Element) || null; return (this.props.children as JSX.Element) || null;
} }

+ 1
- 1
server/sonar-web/src/main/js/store/marketplace/actions.ts View File

} }
if (status.installationStatus === 'AUTOMATIC_IN_PROGRESS') { if (status.installationStatus === 'AUTOMATIC_IN_PROGRESS') {
editionTimer = window.setTimeout(() => { editionTimer = window.setTimeout(() => {
getEditionStatus().then(status => setEditionStatus(status)(dispatch), () => { });
getEditionStatus().then(status => setEditionStatus(status)(dispatch), () => {});
editionTimer = undefined; editionTimer = undefined;
}, 2000); }, 2000);
} }

+ 1
- 0
sonar-core/src/main/resources/org/sonar/l10n/core.properties View File

marketplace.uninstall_x=Uninstall {0} marketplace.uninstall_x=Uninstall {0}
marketplace.uninstall_x_confirmation=Are you sure you want to uninstall {0}? marketplace.uninstall_x_confirmation=Are you sure you want to uninstall {0}?
marketplace.pending=Pending... marketplace.pending=Pending...
marketplace.checking_license=Checking your license...
marketplace._installed=installed marketplace._installed=installed
marketplace.available_under_commercial_license=Available under our commercial editions marketplace.available_under_commercial_license=Available under our commercial editions
marketplace.learn_more=Learn more marketplace.learn_more=Learn more

Loading…
Cancel
Save