2021-03-09 23:14:52 -08:00
|
|
|
import React, { useEffect, useMemo, useState } from 'react';
|
2021-03-11 13:38:35 -08:00
|
|
|
import Cookies from 'js-cookie';
|
2021-01-17 12:54:49 -08:00
|
|
|
import { BrowserRouter as Router } from 'react-router-dom';
|
2021-03-11 13:38:35 -08:00
|
|
|
import { ApolloClient, ApolloProvider, createHttpLink, InMemoryCache, ServerError } from '@apollo/client';
|
|
|
|
import { onError } from '@apollo/client/link/error';
|
2021-03-09 23:14:52 -08:00
|
|
|
import { ThemeProvider } from 'styled-components';
|
|
|
|
|
|
|
|
import './App.less';
|
2021-02-12 13:57:38 -08:00
|
|
|
import { Routes } from './app/Routes';
|
2021-03-11 13:38:35 -08:00
|
|
|
import EntityRegistry from './app/entity/EntityRegistry';
|
2021-02-18 12:33:17 -08:00
|
|
|
import { DashboardEntity } from './app/entity/dashboard/DashboardEntity';
|
|
|
|
import { ChartEntity } from './app/entity/chart/ChartEntity';
|
2021-03-07 11:26:47 -08:00
|
|
|
import { UserEntity } from './app/entity/user/User';
|
2021-05-11 17:55:45 -07:00
|
|
|
import { UserGroupEntity } from './app/entity/userGroup/UserGroup';
|
2021-03-07 11:26:47 -08:00
|
|
|
import { DatasetEntity } from './app/entity/dataset/DatasetEntity';
|
2021-04-21 12:06:31 -07:00
|
|
|
import { DataFlowEntity } from './app/entity/dataFlow/DataFlowEntity';
|
|
|
|
import { DataJobEntity } from './app/entity/dataJob/DataJobEntity';
|
2021-03-07 11:26:47 -08:00
|
|
|
import { TagEntity } from './app/entity/tag/Tag';
|
|
|
|
import { EntityRegistryContext } from './entityRegistryContext';
|
2021-03-09 23:14:52 -08:00
|
|
|
import { Theme } from './conf/theme/types';
|
|
|
|
import defaultThemeConfig from './conf/theme/theme_light.config.json';
|
2021-03-11 13:38:35 -08:00
|
|
|
import { PageRoutes } from './conf/Global';
|
|
|
|
import { isLoggedInVar } from './app/auth/checkAuthStatus';
|
|
|
|
import { GlobalCfg } from './conf';
|
2021-05-13 09:18:49 +05:30
|
|
|
import { GlossaryTermEntity } from './app/entity/glossaryTerm/GlossaryTermEntity';
|
2021-07-21 02:42:21 +08:00
|
|
|
import { MLFeatureEntity } from './app/entity/mlFeature/MLFeatureEntity';
|
|
|
|
import { MLPrimaryKeyEntity } from './app/entity/mlPrimaryKey/MLPrimaryKeyEntity';
|
|
|
|
import { MLFeatureTableEntity } from './app/entity/mlFeatureTable/MLFeatureTableEntity';
|
2021-07-28 20:39:05 -07:00
|
|
|
import { MLModelEntity } from './app/entity/mlModel/MLModelEntity';
|
|
|
|
import { MLModelGroupEntity } from './app/entity/mlModelGroup/MLModelGroupEntity';
|
2021-01-17 12:54:49 -08:00
|
|
|
|
|
|
|
/*
|
2021-07-17 04:56:50 +10:00
|
|
|
Construct Apollo Client
|
2021-01-17 12:54:49 -08:00
|
|
|
*/
|
2021-03-11 13:38:35 -08:00
|
|
|
const httpLink = createHttpLink({ uri: '/api/v2/graphql' });
|
|
|
|
|
|
|
|
const errorLink = onError(({ networkError }) => {
|
|
|
|
if (networkError) {
|
|
|
|
const serverError = networkError as ServerError;
|
|
|
|
if (serverError.statusCode === 401) {
|
|
|
|
isLoggedInVar(false);
|
|
|
|
Cookies.remove(GlobalCfg.CLIENT_AUTH_COOKIE);
|
|
|
|
window.location.replace(PageRoutes.AUTHENTICATE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-17 12:54:49 -08:00
|
|
|
const client = new ApolloClient({
|
2021-03-11 13:38:35 -08:00
|
|
|
link: errorLink.concat(httpLink),
|
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-04-23 00:18:39 -07:00
|
|
|
DataFlow: {
|
|
|
|
keyFields: ['urn'],
|
|
|
|
},
|
|
|
|
DataJob: {
|
|
|
|
keyFields: ['urn'],
|
|
|
|
},
|
2021-07-21 02:42:21 +08:00
|
|
|
MLFeatureTable: {
|
|
|
|
keyFields: ['urn'],
|
|
|
|
},
|
2021-07-28 20:39:05 -07:00
|
|
|
MLModel: {
|
|
|
|
keyFields: ['urn'],
|
|
|
|
},
|
|
|
|
MLModelGroup: {
|
|
|
|
keyFields: ['urn'],
|
|
|
|
},
|
2021-04-23 00:18:39 -07:00
|
|
|
},
|
|
|
|
possibleTypes: {
|
2021-07-28 20:39:05 -07:00
|
|
|
EntityWithRelationships: [
|
|
|
|
'Dataset',
|
|
|
|
'Chart',
|
|
|
|
'Dashboard',
|
|
|
|
'DataJob',
|
|
|
|
'MLFeature',
|
|
|
|
'MLPrimaryKey',
|
|
|
|
'MLModel',
|
|
|
|
'MLModelGroup',
|
|
|
|
],
|
2021-01-17 12:54:49 -08:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
credentials: 'include',
|
2021-07-08 03:54:16 +08:00
|
|
|
defaultOptions: {
|
|
|
|
watchQuery: {
|
|
|
|
fetchPolicy: 'cache-and-network',
|
|
|
|
nextFetchPolicy: 'cache-first',
|
|
|
|
},
|
|
|
|
query: {
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
},
|
|
|
|
},
|
2021-01-17 12:54:49 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
const App: React.VFC = () => {
|
2021-03-11 10:06:48 -08:00
|
|
|
const [dynamicThemeConfig, setDynamicThemeConfig] = useState<Theme>(defaultThemeConfig);
|
2021-03-09 23:14:52 -08:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
import(`./conf/theme/${process.env.REACT_APP_THEME_CONFIG}`).then((theme) => {
|
|
|
|
setDynamicThemeConfig(theme);
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
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-05-11 17:55:45 -07:00
|
|
|
register.register(new UserGroupEntity());
|
2021-03-07 11:26:47 -08:00
|
|
|
register.register(new TagEntity());
|
2021-04-21 12:06:31 -07:00
|
|
|
register.register(new DataFlowEntity());
|
|
|
|
register.register(new DataJobEntity());
|
2021-05-13 09:18:49 +05:30
|
|
|
register.register(new GlossaryTermEntity());
|
2021-07-21 02:42:21 +08:00
|
|
|
register.register(new MLFeatureEntity());
|
|
|
|
register.register(new MLPrimaryKeyEntity());
|
|
|
|
register.register(new MLFeatureTableEntity());
|
2021-07-28 20:39:05 -07:00
|
|
|
register.register(new MLModelEntity());
|
|
|
|
register.register(new MLModelGroupEntity());
|
2021-02-03 11:49:51 -08:00
|
|
|
return register;
|
|
|
|
}, []);
|
2021-03-09 23:14:52 -08:00
|
|
|
|
2021-01-17 12:54:49 -08:00
|
|
|
return (
|
2021-03-11 10:06:48 -08:00
|
|
|
<ThemeProvider theme={dynamicThemeConfig}>
|
2021-03-09 23:14:52 -08:00
|
|
|
<Router>
|
|
|
|
<EntityRegistryContext.Provider value={entityRegistry}>
|
2021-07-17 04:56:50 +10:00
|
|
|
<ApolloProvider client={client}>
|
|
|
|
<Routes />
|
|
|
|
</ApolloProvider>
|
2021-03-09 23:14:52 -08:00
|
|
|
</EntityRegistryContext.Provider>
|
|
|
|
</Router>
|
|
|
|
</ThemeProvider>
|
2021-01-17 12:54:49 -08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|