= ({
{pluginIsConnected ? (
<>
-
- Plugin is connected! Continue to Grafana OnCall by clicking OnCall under Alerts & IRM in the navigation over
- there 👈
-
diff --git a/grafana-plugin/src/containers/PluginConfigPage/__snapshots__/PluginConfigPage.test.tsx.snap b/grafana-plugin/src/containers/PluginConfigPage/__snapshots__/PluginConfigPage.test.tsx.snap
index 32d6cc104e..c15126c189 100644
--- a/grafana-plugin/src/containers/PluginConfigPage/__snapshots__/PluginConfigPage.test.tsx.snap
+++ b/grafana-plugin/src/containers/PluginConfigPage/__snapshots__/PluginConfigPage.test.tsx.snap
@@ -55,7 +55,7 @@ exports[`PluginConfigPage If onCallApiUrl is not set in the plugin's meta jsonDa
`;
-exports[`PluginConfigPage If onCallApiUrl is not set in the plugin's meta jsonData, or in process.env, checkIfPluginIsConnected is not called, and the configuration form is shown 1`] = `
+exports[`PluginConfigPage If onCallApiUrl is not set in the plugin's meta jsonData, or in process.env, updatePluginStatus is not called, and the configuration form is shown 1`] = `
`;
-exports[`PluginConfigPage OnCallApiUrl is set, and checkApiTokenSyncData does not return an error. It displays properly the plugin connected items based on the license - License: OpenSource 1`] = `
+exports[`PluginConfigPage OnCallApiUrl is set, and checkTokenAndIfPluginIsConnected does not return an error. It displays properly the plugin connected items based on the license - License: OpenSource 1`] = `
Configure Grafana OnCall
-
- Plugin is connected! Continue to Grafana OnCall by clicking OnCall under Alerts & IRM in the navigation over there 👈
-
@@ -262,29 +280,50 @@ exports[`PluginConfigPage OnCallApiUrl is set, and checkApiTokenSyncData does no
Connected to OnCall (v1.2.3, OpenSource)
-
+
+
+ Open Grafana OnCall
+
+
+
+
+
+
+
`;
-exports[`PluginConfigPage OnCallApiUrl is set, and checkApiTokenSyncData does not return an error. It displays properly the plugin connected items based on the license - License: some-other-license 1`] = `
+exports[`PluginConfigPage OnCallApiUrl is set, and checkTokenAndIfPluginIsConnected does not return an error. It displays properly the plugin connected items based on the license - License: some-other-license 1`] = `
Configure Grafana OnCall
-
- Plugin is connected! Continue to Grafana OnCall by clicking OnCall under Alerts & IRM in the navigation over there 👈
-
@@ -295,20 +334,44 @@ exports[`PluginConfigPage OnCallApiUrl is set, and checkApiTokenSyncData does no
-
`;
-exports[`PluginConfigPage OnCallApiUrl is set, and checkApiTokenSyncData returns an error 1`] = `
+exports[`PluginConfigPage OnCallApiUrl is set, and checkTokenAndIfPluginIsConnected returns an error 1`] = `
{
};
export const Root = observer((props: AppRootProps) => {
- const [didFinishLoading, setDidFinishLoading] = useState(false);
-
const store = useStore();
useEffect(() => {
@@ -106,13 +104,8 @@ export const Root = observer((props: AppRootProps) => {
const updateBasicData = async () => {
await store.updateBasicData();
await store.alertGroupStore.fetchIRMPlan();
- setDidFinishLoading(true);
};
- if (!didFinishLoading) {
- return null;
- }
-
const location = useLocation();
const page = getMatchedPage(location.pathname);
diff --git a/grafana-plugin/src/plugin/PluginSetup/PluginSetup.test.tsx b/grafana-plugin/src/plugin/PluginSetup/PluginSetup.test.tsx
index 7e75a5b9e5..517ffe313e 100644
--- a/grafana-plugin/src/plugin/PluginSetup/PluginSetup.test.tsx
+++ b/grafana-plugin/src/plugin/PluginSetup/PluginSetup.test.tsx
@@ -70,20 +70,17 @@ describe('PluginSetup', () => {
test('app is loading', async () => {
const rootBaseStore = new RootBaseStore();
- rootBaseStore.appLoading = true;
await createComponentAndMakeAssertions(rootBaseStore);
});
test('there is an error message', async () => {
const rootBaseStore = new RootBaseStore();
- rootBaseStore.appLoading = false;
rootBaseStore.initializationError = 'ohhhh noo';
await createComponentAndMakeAssertions(rootBaseStore);
});
test('there is an error message - retry setup', async () => {
const rootBaseStore = new RootBaseStore();
- rootBaseStore.appLoading = false;
rootBaseStore.initializationError = 'ohhhh noo';
const mockedSetupPlugin = await createComponentAndMakeAssertions(rootBaseStore);
@@ -95,7 +92,6 @@ describe('PluginSetup', () => {
test('currently undergoing maintenance', async () => {
const rootBaseStore = new RootBaseStore();
- rootBaseStore.appLoading = false;
rootBaseStore.currentlyUndergoingMaintenance = true;
rootBaseStore.initializationError = 'there is some sort of maintenance';
await createComponentAndMakeAssertions(rootBaseStore);
@@ -103,7 +99,6 @@ describe('PluginSetup', () => {
test('app successfully initialized', async () => {
const rootBaseStore = new RootBaseStore();
- rootBaseStore.appLoading = false;
rootBaseStore.initializationError = null;
await createComponentAndMakeAssertions(rootBaseStore);
});
@@ -112,7 +107,6 @@ describe('PluginSetup', () => {
runtime.config.featureToggles.topnav = isTopNavBar;
const rootBaseStore = new RootBaseStore();
- rootBaseStore.appLoading = true;
await createComponentAndMakeAssertions(rootBaseStore);
});
});
diff --git a/grafana-plugin/src/plugin/PluginSetup/__snapshots__/PluginSetup.test.tsx.snap b/grafana-plugin/src/plugin/PluginSetup/__snapshots__/PluginSetup.test.tsx.snap
index 04eb5aa280..02800aa02f 100644
--- a/grafana-plugin/src/plugin/PluginSetup/__snapshots__/PluginSetup.test.tsx.snap
+++ b/grafana-plugin/src/plugin/PluginSetup/__snapshots__/PluginSetup.test.tsx.snap
@@ -2,54 +2,24 @@
exports[`PluginSetup app initialized with topnavbar = false 1`] = `
-
-
-
- Initializing plugin...
-
+
+ hello
`;
exports[`PluginSetup app initialized with topnavbar = true 1`] = `
-
-
-
- Initializing plugin...
-
+
+ hello
`;
exports[`PluginSetup app is loading 1`] = `
-
-
-
- Initializing plugin...
-
+
+ hello
`;
diff --git a/grafana-plugin/src/plugin/PluginSetup/index.tsx b/grafana-plugin/src/plugin/PluginSetup/index.tsx
index 18ae2ffa03..da485b4049 100644
--- a/grafana-plugin/src/plugin/PluginSetup/index.tsx
+++ b/grafana-plugin/src/plugin/PluginSetup/index.tsx
@@ -35,15 +35,10 @@ const PluginSetupWrapper: FC
= ({ text, children }) =>
const PluginSetup: FC = observer(({ InitializedComponent, ...props }) => {
const store = useStore();
const setupPlugin = useCallback(() => store.setupPlugin(props.meta), [props.meta]);
-
useEffect(() => {
setupPlugin();
}, [setupPlugin]);
- if (store.appLoading) {
- return ;
- }
-
if (store.initializationError) {
return (
@@ -62,7 +57,6 @@ const PluginSetup: FC = observer(({ InitializedComponent, ...p
);
}
-
return ;
});
diff --git a/grafana-plugin/src/state/plugin/__snapshots__/plugin.test.ts.snap b/grafana-plugin/src/state/plugin/__snapshots__/plugin.test.ts.snap
index 329fd8fce6..8152d352b8 100644
--- a/grafana-plugin/src/state/plugin/__snapshots__/plugin.test.ts.snap
+++ b/grafana-plugin/src/state/plugin/__snapshots__/plugin.test.ts.snap
@@ -55,8 +55,3 @@ exports[`PluginState.getHumanReadableErrorFromOnCallError it handles an unknown
"An unknown error occurred when trying to install the plugin. Verify OnCall API URL, http://hello.com, is correct (NOTE: OnCall API URL is currently being taken from process.env of your UI)?
Refresh your page and try again, or try removing your plugin configuration and reconfiguring."
`;
-
-exports[`PluginState.pollOnCallDataSyncStatus it returns an error message if the pollCount is greater than 10 1`] = `
-"There was an issue while synchronizing data required for the plugin.
-Verify your OnCall backend setup (ie. that Celery workers are launched and properly configured)"
-`;
diff --git a/grafana-plugin/src/state/plugin/index.ts b/grafana-plugin/src/state/plugin/index.ts
index c7e7cf8022..1e2f7deb93 100644
--- a/grafana-plugin/src/state/plugin/index.ts
+++ b/grafana-plugin/src/state/plugin/index.ts
@@ -2,7 +2,6 @@ import { getBackendSrv } from '@grafana/runtime';
import { OnCallAppPluginMeta, OnCallPluginMetaJSONData, OnCallPluginMetaSecureJSONData } from 'types';
import { makeRequest, isNetworkError } from 'network';
-import FaroHelper from 'utils/faro';
export type UpdateGrafanaPluginSettingsProps = {
jsonData?: Partial;
@@ -11,6 +10,8 @@ export type UpdateGrafanaPluginSettingsProps = {
export type PluginStatusResponseBase = Pick & {
version: string;
+ recaptcha_site_key: string;
+ currently_undergoing_maintenance_message: string;
};
export type PluginSyncStatusResponse = PluginStatusResponseBase & {
@@ -25,10 +26,6 @@ type PluginConnectedStatusResponse = PluginStatusResponseBase & {
is_user_anonymous: boolean;
};
-type PluginIsInMaintenanceModeResponse = {
- currently_undergoing_maintenance_message: string;
-};
-
type CloudProvisioningConfigResponse = null;
type SelfHostedProvisioningConfigResponse = Omit & {
@@ -44,7 +41,6 @@ export type InstallationVerb = 'install' | 'sync';
class PluginState {
static ONCALL_BASE_URL = '/plugin';
static GRAFANA_PLUGIN_SETTINGS_URL = '/api/plugins/grafana-oncall-app/settings';
- static SYNC_STATUS_POLLING_RETRY_LIMIT = 10;
static grafanaBackend = getBackendSrv();
static generateOnCallApiUrlConfiguredThroughEnvVarMsg = (isConfiguredThroughEnvVar: boolean): string =>
@@ -208,75 +204,9 @@ class PluginState {
});
};
- static getPluginSyncStatus = (): Promise =>
- makeRequest(`${this.ONCALL_BASE_URL}/sync`, { method: 'GET' });
-
- static timeout = (pollCount: number) => new Promise((resolve) => setTimeout(resolve, 10 * 2 ** pollCount));
-
- /**
- * DON'T CALL THIS METHOD DIRECTLY
- * This really only exists to properly test the recursive nature of pollOnCallDataSyncStatus
- * Without this it is impossible (or very hacky) to mock the recursive calls
- */
- static _pollOnCallDataSyncStatus = (
- onCallApiUrl: string,
- onCallApiUrlIsConfiguredThroughEnvVar: boolean,
- pollCount: number
- ) => this.pollOnCallDataSyncStatus(onCallApiUrl, onCallApiUrlIsConfiguredThroughEnvVar, pollCount);
-
- /**
- * Poll, for a configured amount of time, the status of the OnCall backend data sync
- * Returns a PluginSyncStatusResponse if the sync was successful (ie. token_ok is true), otherwise null
- */
- static pollOnCallDataSyncStatus = async (
- onCallApiUrl: string,
- onCallApiUrlIsConfiguredThroughEnvVar: boolean,
- pollCount = 0
- ): Promise => {
- if (pollCount > this.SYNC_STATUS_POLLING_RETRY_LIMIT) {
- return `There was an issue while synchronizing data required for the plugin.\nVerify your OnCall backend setup (ie. that Celery workers are launched and properly configured)`;
- }
-
- try {
- const syncResponse = await this.getPluginSyncStatus();
- if (syncResponse?.token_ok) {
- return syncResponse;
- }
-
- await this.timeout(pollCount);
- return await this._pollOnCallDataSyncStatus(onCallApiUrl, onCallApiUrlIsConfiguredThroughEnvVar, pollCount + 1);
- } catch (e) {
- return this.getHumanReadableErrorFromOnCallError(e, onCallApiUrl, 'sync', onCallApiUrlIsConfiguredThroughEnvVar);
- }
- };
-
- /**
- * Trigger a data sync with the OnCall backend AND then poll, for a configured amount of time, the status of that sync
- * If the
- * Returns a PluginSyncStatusResponse if the sync was succesful, otherwise null
- */
- static syncDataWithOnCall = async (
- onCallApiUrl: string,
- onCallApiUrlIsConfiguredThroughEnvVar = false
+ static checkTokenAndIfPluginIsConnected = async (
+ onCallApiUrl: string
): Promise => {
- try {
- const startSyncResponse = await makeRequest(`${this.ONCALL_BASE_URL}/sync`, { method: 'POST' });
- if (typeof startSyncResponse === 'string') {
- // an error occurred trying to initiate the sync
- return startSyncResponse;
- }
-
- if (!FaroHelper.faro) {
- FaroHelper.initializeFaro(onCallApiUrl);
- }
-
- return await this.pollOnCallDataSyncStatus(onCallApiUrl, onCallApiUrlIsConfiguredThroughEnvVar);
- } catch (e) {
- return this.getHumanReadableErrorFromOnCallError(e, onCallApiUrl, 'sync', onCallApiUrlIsConfiguredThroughEnvVar);
- }
- };
-
- static checkTokenAndSyncDataWithOncall = async (onCallApiUrl: string): Promise => {
/**
* Allows the plugin config page to repair settings like the app initialization screen if a user deletes
* an API key on accident but leaves the plugin settings intact.
@@ -290,7 +220,7 @@ class PluginState {
}
}
- return await PluginState.syncDataWithOnCall(onCallApiUrl);
+ return await PluginState.updatePluginStatus(onCallApiUrl);
};
static installPlugin = async