The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/mock-api-utils.ts

39 lines
1.2 KiB

import store from 'app/core/store';
import { sendAppNotification } from './core/copy/appNotification';
import { AppNotificationSeverity } from './types';
export const STORAGE_MOCK_API_KEY = 'grafana.dev.mockApi';
export const currentMockApiState = () => {
return store.getBool(STORAGE_MOCK_API_KEY, false);
};
export const toggleMockApiAndReload = () => {
const currentState = currentMockApiState();
store.set(STORAGE_MOCK_API_KEY, String(!currentState));
const action = currentState ? 'Disabling' : 'Enabling';
sendAppNotification(`${action} Mock API`, 'Reloading...', AppNotificationSeverity.Info);
setTimeout(() => {
window.location.reload();
}, 200);
};
export const potentiallySetupMockApi = async () => {
const mockApiEnabled = currentMockApiState();
if (process.env.NODE_ENV === 'development' && mockApiEnabled) {
const { default: worker } = await import('test/mock-api/worker');
worker.start({ onUnhandledRequest: 'bypass' });
}
};
export const notifyIfMockApiEnabled = () => {
if (process.env.NODE_ENV === 'development' && currentMockApiState()) {
sendAppNotification(
'Mock API currently enabled',
'Some network requests will be intercepted',
AppNotificationSeverity.Info
);
}
};