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-09-02 19:05:13 -07:00
|
|
|
import { message } from 'antd';
|
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';
|
2023-05-09 15:16:11 -07:00
|
|
|
import { Helmet, HelmetProvider } from 'react-helmet-async';
|
2021-03-09 23:14:52 -08:00
|
|
|
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-08-16 20:47:18 -07:00
|
|
|
import { GroupEntity } from './app/entity/group/Group';
|
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';
|
2022-01-27 22:02:41 -08:00
|
|
|
import { DomainEntity } from './app/entity/domain/DomainEntity';
|
2022-02-02 13:51:39 -08:00
|
|
|
import { ContainerEntity } from './app/entity/container/ContainerEntity';
|
2022-05-30 00:26:07 -04:00
|
|
|
import GlossaryNodeEntity from './app/entity/glossaryNode/GlossaryNodeEntity';
|
2022-09-26 08:55:03 -07:00
|
|
|
import { DataPlatformEntity } from './app/entity/dataPlatform/DataPlatformEntity';
|
2023-05-17 00:17:25 -07:00
|
|
|
import { DataProductEntity } from './app/entity/dataProduct/DataProductEntity';
|
2023-07-26 10:56:07 -04:00
|
|
|
import { DataPlatformInstanceEntity } from './app/entity/dataPlatformInstance/DataPlatformInstanceEntity';
|
2023-09-08 23:10:49 +05:30
|
|
|
import { RoleEntity } from './app/entity/Access/RoleEntity';
|
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' });
|
|
|
|
|
2022-08-28 20:08:25 -07:00
|
|
|
const errorLink = onError((error) => {
|
|
|
|
const { networkError, graphQLErrors } = error;
|
2021-03-11 13:38:35 -08:00
|
|
|
if (networkError) {
|
|
|
|
const serverError = networkError as ServerError;
|
|
|
|
if (serverError.statusCode === 401) {
|
|
|
|
isLoggedInVar(false);
|
|
|
|
Cookies.remove(GlobalCfg.CLIENT_AUTH_COOKIE);
|
2023-07-31 09:57:49 +05:30
|
|
|
const currentPath = window.location.pathname + window.location.search;
|
|
|
|
window.location.replace(`${PageRoutes.AUTHENTICATE}?redirect_uri=${encodeURIComponent(currentPath)}`);
|
2021-03-11 13:38:35 -08:00
|
|
|
}
|
|
|
|
}
|
2021-09-02 19:05:13 -07:00
|
|
|
if (graphQLErrors && graphQLErrors.length) {
|
|
|
|
const firstError = graphQLErrors[0];
|
|
|
|
const { extensions } = firstError;
|
|
|
|
const errorCode = extensions && (extensions.code as number);
|
|
|
|
// Fallback in case the calling component does not handle.
|
|
|
|
message.error(`${firstError.message} (code ${errorCode})`, 3);
|
|
|
|
}
|
2021-03-11 13:38:35 -08:00
|
|
|
});
|
|
|
|
|
2021-01-17 12:54:49 -08:00
|
|
|
const client = new ApolloClient({
|
2021-07-30 17:41:03 -07:00
|
|
|
connectToDevTools: true,
|
2021-03-11 13:38:35 -08:00
|
|
|
link: errorLink.concat(httpLink),
|
2023-03-21 18:36:21 -07:00
|
|
|
cache: new InMemoryCache({
|
|
|
|
typePolicies: {
|
|
|
|
Query: {
|
|
|
|
fields: {
|
|
|
|
dataset: {
|
|
|
|
merge: (oldObj, newObj) => {
|
|
|
|
return { ...oldObj, ...newObj };
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2021-01-17 12:54:49 -08:00
|
|
|
credentials: 'include',
|
2021-07-08 03:54:16 +08:00
|
|
|
defaultOptions: {
|
|
|
|
watchQuery: {
|
2021-08-02 17:49:57 -07:00
|
|
|
fetchPolicy: 'no-cache',
|
2021-07-08 03:54:16 +08:00
|
|
|
},
|
|
|
|
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-08-16 20:47:18 -07:00
|
|
|
register.register(new GroupEntity());
|
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());
|
2022-01-27 22:02:41 -08:00
|
|
|
register.register(new DomainEntity());
|
2022-02-02 13:51:39 -08:00
|
|
|
register.register(new ContainerEntity());
|
2022-05-30 00:26:07 -04:00
|
|
|
register.register(new GlossaryNodeEntity());
|
2023-09-08 23:10:49 +05:30
|
|
|
register.register(new RoleEntity());
|
2022-09-26 08:55:03 -07:00
|
|
|
register.register(new DataPlatformEntity());
|
2023-05-17 00:17:25 -07:00
|
|
|
register.register(new DataProductEntity());
|
2023-07-26 10:56:07 -04:00
|
|
|
register.register(new DataPlatformInstanceEntity());
|
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 (
|
2023-05-09 15:16:11 -07:00
|
|
|
<HelmetProvider>
|
|
|
|
<ThemeProvider theme={dynamicThemeConfig}>
|
|
|
|
<Router>
|
|
|
|
<Helmet>
|
|
|
|
<title>{dynamicThemeConfig.content.title}</title>
|
|
|
|
</Helmet>
|
|
|
|
<EntityRegistryContext.Provider value={entityRegistry}>
|
|
|
|
<ApolloProvider client={client}>
|
|
|
|
<Routes />
|
|
|
|
</ApolloProvider>
|
|
|
|
</EntityRegistryContext.Provider>
|
|
|
|
</Router>
|
|
|
|
</ThemeProvider>
|
|
|
|
</HelmetProvider>
|
2021-01-17 12:54:49 -08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|