Skip to content

Commit

Permalink
Merge pull request #39 from maastrichtlawtech/optimisation
Browse files Browse the repository at this point in the history
Optimisation to dev merge
  • Loading branch information
shashankmc authored Oct 26, 2023
2 parents db1ca7e + 02763d9 commit 47cff00
Show file tree
Hide file tree
Showing 153 changed files with 2,765 additions and 6,995 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
rules: {
"@typescript-eslint/no-explicit-any": "off"
},
};
26 changes: 13 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ dist
# TernJS port file
.tern-port

# macOS DS_Store files
.DS_Store

# Ignore vim swap files
.*.swp

.expo

# yarn.lock
Expand All @@ -116,13 +122,16 @@ generated/

amplify copy/

#amplify
functions/layout-calculator-express
amplify/team-provider-info.json

#amplify-do-not-edit-begin
amplify/\#current-cloud-backend
amplify/.config/local-*
amplify/logs
amplify/mock-data
amplify/mock-api-resources
amplify/backend/amplify-meta.json
amplify/backend/awscloudformation
amplify/backend/.temp
build/
dist/
Expand All @@ -135,14 +144,5 @@ amplify-build-config.json
amplify-gradle-config.json
amplifytools.xcconfig
.secret-*
amplify/backend/function/networkstatistics/edges.json
amplify/backend/function/networkstatistics/nodes.json
amplify/backend/function/networkstatistics/subNodes.json
amplify/backend/function/queryhandler/edges.json
amplify/backend/function/queryhandler/nodes.json
amplify/backend/function/queryhandler/subNodes.json
amplify/backend/function/caseexploreruidynamodbaccess/lib/python/lib
amplify/backend/function/caseexploreruiopensearchaccess/lib/python/lib
amplify/backend/function/caseexploreruiutils/lib/python/lib

functions/layout-calculator-express
**.sample
#amplify-do-not-edit-end
130 changes: 38 additions & 92 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { AuthState,onAuthUIStateChange, } from '@aws-amplify/ui-components';
import { AuthState, onAuthUIStateChange, } from '@aws-amplify/ui-components';
import { CognitoUser } from '@aws-amplify/auth';
import { Button, CircularProgress } from "@mui/material";
import Amplify, { Auth, Hub, } from "aws-amplify";
import React from 'react';
// @ts-ignore
import cytoscape from 'cytoscape'
// @ts-ignore
import euler from 'cytoscape-euler'
// @ts-ignore
import cola from 'cytoscape-cola'
// @ts-ignore
import dagre from 'cytoscape-dagre'
// @ts-ignore
import spread from 'cytoscape-spread'
import GraphEditor, {
ACTIONS
Expand All @@ -22,10 +28,24 @@ cytoscape.use(dagre)
cytoscape.use(euler)
cytoscape.use(cola)

export interface UserAttributes {
sub : string;
email : string;
email_verified : boolean;
'custom:isOldUser' : "yes" | null;
}

// 2022-11-10
// The aws-auth library is exporting incorrect type signatures for CognitoUser
// (missing an attributes member), leading to type errors. Manually extend it
// here and use the extended type to eliminate the errors until aws-auth is
// fixed.
interface CognitoUserExt extends CognitoUser {
attributes: UserAttributes;
}

function getUser() {
function getUser() : Promise<CognitoUserExt> {
return Auth.currentAuthenticatedUser()
.then(userData => userData)
.catch(() => console.log('Not signed in'));
}

Expand All @@ -42,14 +62,14 @@ const App = () => {
case ACTIONS.TEST_API:
runQuery()
break;

default:
break;
}
}, [])
const [containerRef, { width, height, initialized }] = useMeasure()
return (
<View
<View
ref={containerRef}
style={{
width: '100%', height: '100%'
Expand All @@ -70,7 +90,7 @@ const App = () => {
const AppContainer = () => {
const [authState, setAuthState] = React.useState();
const [state, setState] = React.useState({
user: null,
user: null as CognitoUserExt | null,
isLoading: true
})
const [termsOfServiceUser, setTermsOfServiceUser] = React.useState(null)
Expand All @@ -90,7 +110,7 @@ const AppContainer = () => {
});
break;
}

case 'signOut':
setState({
...state,
Expand Down Expand Up @@ -128,23 +148,21 @@ const AppContainer = () => {
return <>
{
state.user ? (
state.user?.attributes?.['custom:isOldUser'] !== 'yes'
state.user.attributes['custom:isOldUser'] !== 'yes'
? (
<TermsOfService
<TermsOfService
user={state.user}
onAgree={async () => {
await Auth.updateUserAttributes(state.user, {
'custom:isOldUser': 'yes'
})
});
// Due to being in an async, the type checker complains that user
// might be null, despite the null check above. Using state.user!
// to silence this warning.
state.user!.attributes['custom:isOldUser'] = 'yes';
setState({
...state,
user: {
...state.user,
attributes: {
...(state.user?.attributes ?? {}),
'custom:isOldUser': 'yes'
}
},
user: state.user
})
}}
onDisagree={() => {
Expand All @@ -158,7 +176,7 @@ const AppContainer = () => {
onSignin={async () => {
await Auth.federatedSignIn(
// undefined,
// {
// {
// expires_at: new Date().getTime() + 1000 * 60 * 60 * 12 * 3 ,

// }
Expand Down Expand Up @@ -196,80 +214,8 @@ const AppContainer = () => {
// />
)
}

</>
}

// const AppContainer = () => {
// React.useEffect(() => {
// const index = detectBrowser() === 'Firefox' ? 1 : 0
// setTimeout(()=>{
// const call = async ()=> {
// try {
// const authUser = await Auth.currentAuthenticatedUser()
// console.log('auth', authUser)
// } catch (error) {
// console.log( 'er', error)
// try {
// const el1 = document.getElementsByTagName('amplify-authenticator')[0]
// .shadowRoot?.children
// const el2 = [...el1].filter(el => el.tagName !== 'STYLE')[0].getElementsByTagName('amplify-sign-in')[0]
// .shadowRoot?.children
// const el3 = [...el2].filter(el => el.tagName !== 'STYLE')[0].getElementsByTagName('amplify-federated-buttons')[0]
// .shadowRoot?.children
// const el4 = [...el3].filter(el => el.tagName !== 'STYLE')[0].getElementsByTagName('amplify-oauth-button')[0]
// .shadowRoot?.children
// const button = [...el4].filter(el => el.tagName !== 'STYLE')[0].getElementsByTagName('button')[0]
// button.click()
// // const button = document.getElementsByTagName('amplify-authenticator')[0]
// // .shadowRoot?.lastChild.getElementsByTagName('amplify-sign-in')[0]
// // .shadowRoot?.lastChild.getElementsByTagName('amplify-federated-buttons')[0]
// // ?.shadowRoot//?.lastChild//.getElementsByTagName('amplify-oauth-button')[0]
// // // .shadowRoot?.lastChild.getElementsByTagName('button')[0]
// // // .click()
// } catch (error) {

// }
// }

// }
// call()
// }, 500 )
// }, [])
// return (
// <AppContent />
// )
// }

export default AppContainer // App
// export default () => {
// const xStateRef = React.useRef({
// nodes: [{ name: '2' }],
// edges: [{ source: '1', target: '2' }, { source: '2', target: '3' }],
// })
// const [xstate, updateXstate] = useImmer(xStateRef.current)
// console.log('xstate', xstate.nodes === xStateRef.current.nodes)
// React.useEffect(() => {
// updateXstate(draft => {
// // draft.nodes
// draft.nodes.push({ name: '3' })
// })
// }, [])
// return <View></View>
// }

function detectBrowser() {
if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 ) {
return 'Opera';
} else if(navigator.userAgent.indexOf("Chrome") != -1 ) {
return 'Chrome';
} else if(navigator.userAgent.indexOf("Safari") != -1) {
return 'Safari';
} else if(navigator.userAgent.indexOf("Firefox") != -1 ){
return 'Firefox';
} else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) {
return 'IE';//crap
} else {
return 'Unknown';
}
}
export default AppContainer
10 changes: 5 additions & 5 deletions amplify/.config/project-config.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"providers": [
"awscloudformation"
],
"projectName": "caseexplorerui",
"version": "3.1",
"frontend": "javascript",
"javascript": {
"framework": "react-native",
"config": {
"SourceDir": "./",
"SourceDir": "src",
"DistributionDir": "/",
"BuildCommand": "npm run-script build",
"StartCommand": "npm run-script start"
}
},
"providers": [
"awscloudformation"
]
}
}
8 changes: 0 additions & 8 deletions amplify/README.md

This file was deleted.

19 changes: 3 additions & 16 deletions amplify/backend/api/caseexplorerui/cli-inputs.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
{
"version": 1,
"serviceConfiguration": {
"apiName": "caseexplorerui",
"serviceName": "AppSync",
"defaultAuthType": {
"mode": "AMAZON_COGNITO_USER_POOLS",
"cognitoUserPoolId": "authcaseexploreruiauth"
"cognitoUserPoolId": "authcaseexploreruib94ade50"
},
"additionalAuthTypes": [
{
"mode": "AWS_IAM"
},
{
"mode": "OPENID_CONNECT",
"openIDProviderName": "SURFconext",
"openIDIssuerURL": "https://connect.test.surfconext.nl/",
"openIDClientID": "dev.d11iy22xsphp3a.amplifyapp.com",
"openIDAuthTTL": "100",
"openIDIatTTL": "100"
}
],
"conflictResolution": {},
"apiName": "caseexplorerui",
"gqlSchemaPath": "/home/maxine/Documents/Law+Tech/Comenius/case-explorer-ui/amplify/backend/api/caseexplorerui/schema.graphql"
"additionalAuthTypes": []
}
}
4 changes: 2 additions & 2 deletions amplify/backend/api/caseexplorerui/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"DynamoDBEnableServerSideEncryption": false,
"AuthCognitoUserPoolId": {
"Fn::GetAtt": [
"authcaseexploreruiauth",
"authcaseexploreruib94ade50",
"Outputs.UserPoolId"
]
},
"AuthModeLastUpdated": "2021-12-13T12:13:45.922Z"
"AuthModeLastUpdated": "2023-04-04T15:19:47.886Z"
}
2 changes: 1 addition & 1 deletion amplify/backend/api/caseexplorerui/schema/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Query {
computeNetworkStatistics(
nodes: [NodeInput!]!,
edges: [EdgeInput!]!
): AWSJSON @function(name: "networkstatistics-${env}")
): AWSJSON @function(name: "networkstatistics")
fetchNodeData(
node: NodeInput!
attributesToFetch: NodeAttributes
Expand Down
2 changes: 1 addition & 1 deletion amplify/backend/api/caseexplorerui/schema/table.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Caselaw @model
type Caselaw @model @auth(rules: [{ allow: private, operations: [read] }])
@key(fields: ["ecli", "ItemType"])
@key(name: "GSI-ItemType", fields: ["ItemType", "SourceDocDate"], queryField: "queryByItemType")
@key(name: "GSI-instance", fields: ["instance", "SourceDocDate"], queryField: "queryByInstance")
Expand Down
Loading

0 comments on commit 47cff00

Please sign in to comment.