2021-02-03 11:49:51 -08:00
|
|
|
import React, { useMemo } from 'react';
|
2021-01-17 12:54:49 -08:00
|
|
|
import { BrowserRouter as Router } from 'react-router-dom';
|
|
|
|
import { ApolloClient, ApolloProvider, InMemoryCache } from '@apollo/client';
|
|
|
|
import { MockedProvider } from '@apollo/client/testing';
|
|
|
|
import './App.css';
|
2021-02-12 13:57:38 -08:00
|
|
|
import { Routes } from './app/Routes';
|
2021-01-17 12:54:49 -08:00
|
|
|
import { mocks } from './Mocks';
|
2021-02-12 13:57:38 -08:00
|
|
|
import EntityRegistry from './app/entity/EntityRegistry';
|
|
|
|
import { DatasetEntity } from './app/entity/dataset/DatasetEntity';
|
|
|
|
import { UserEntity } from './app/entity/user/User';
|
2021-02-03 11:49:51 -08:00
|
|
|
import { EntityRegistryContext } from './entityRegistryContext';
|
2021-02-18 12:33:17 -08:00
|
|
|
import { DashboardEntity } from './app/entity/dashboard/DashboardEntity';
|
|
|
|
import { ChartEntity } from './app/entity/chart/ChartEntity';
|
2021-01-17 12:54:49 -08:00
|
|
|
|
|
|
|
// Enable to use the Apollo MockProvider instead of a real HTTP client
|
2021-02-09 14:30:23 -08:00
|
|
|
const MOCK_MODE = false;
|
2021-01-17 12:54:49 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
Construct Apollo Client
|
|
|
|
*/
|
|
|
|
const client = new ApolloClient({
|
2021-02-10 16:10:08 -08:00
|
|
|
uri: '/api/v2/graphql',
|
2021-01-17 12:54:49 -08:00
|
|
|
cache: new InMemoryCache({
|
|
|
|
typePolicies: {
|
|
|
|
Dataset: {
|
2021-02-09 14:30:23 -08:00
|
|
|
keyFields: ['urn'],
|
|
|
|
},
|
|
|
|
CorpUser: {
|
|
|
|
keyFields: ['urn'],
|
2021-01-17 12:54:49 -08:00
|
|
|
},
|
2021-02-18 12:33:17 -08:00
|
|
|
Dashboard: {
|
|
|
|
keyFields: ['urn'],
|
|
|
|
},
|
|
|
|
Chart: {
|
|
|
|
keyFields: ['urn'],
|
|
|
|
},
|
2021-01-17 12:54:49 -08:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
credentials: 'include',
|
|
|
|
});
|
|
|
|
|
|
|
|
const App: React.VFC = () => {
|
2021-02-03 11:49:51 -08:00
|
|
|
const entityRegistry = useMemo(() => {
|
|
|
|
const register = new EntityRegistry();
|
|
|
|
register.register(new DatasetEntity());
|
2021-02-18 12:33:17 -08:00
|
|
|
register.register(new DashboardEntity());
|
|
|
|
register.register(new ChartEntity());
|
2021-02-25 15:27:58 -08:00
|
|
|
register.register(new UserEntity());
|
2021-02-03 11:49:51 -08:00
|
|
|
return register;
|
|
|
|
}, []);
|
2021-01-17 12:54:49 -08:00
|
|
|
return (
|
|
|
|
<Router>
|
2021-02-03 11:49:51 -08:00
|
|
|
<EntityRegistryContext.Provider value={entityRegistry}>
|
|
|
|
{/* Temporary: For local testing during development. */}
|
|
|
|
{MOCK_MODE ? (
|
|
|
|
<MockedProvider mocks={mocks} addTypename={false}>
|
|
|
|
<Routes />
|
|
|
|
</MockedProvider>
|
|
|
|
) : (
|
|
|
|
<ApolloProvider client={client}>
|
|
|
|
<Routes />
|
|
|
|
</ApolloProvider>
|
|
|
|
)}
|
|
|
|
</EntityRegistryContext.Provider>
|
2021-01-17 12:54:49 -08:00
|
|
|
</Router>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|