Skip to content

Commit

Permalink
ESCKAN-54 chore: Apply formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed May 31, 2024
2 parents 5b86df9 + e0a02f6 commit a44cf9a
Show file tree
Hide file tree
Showing 65 changed files with 8,464 additions and 7,098 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ module.exports = {
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
'plugin:prettier/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
plugins: ['react-refresh', 'prettier'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'prettier/prettier': 'error',
},
}
};
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"format": "prettier --write 'src/**/*.{ts,tsx,js,jsx,json,css,scss,md}'",
"test": "vitest run",
"preview": "vite preview"
},
Expand Down Expand Up @@ -34,10 +35,13 @@
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"file-saver": "^2.0.5",
"prettier": "^3.2.5",
"sass": "^1.70.0",
"typescript": "^5.2.2",
"vite": "^5.1.0",
Expand Down
284 changes: 161 additions & 123 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,123 +1,161 @@
import React, {useEffect, useState} from 'react';
import {useDispatch, useStore} from 'react-redux';
import { Box } from "@mui/material";
import {getLayoutManagerInstance} from "@metacell/geppetto-meta-client/common/layout/LayoutManager";
import {addWidget} from '@metacell/geppetto-meta-client/common/layout/actions';
import {connectionsWidget, connectivityGridWidget} from "./layout-manager/widgets.ts";
import '@metacell/geppetto-meta-ui/flex-layout/style/light.scss';
import theme from './theme/index.tsx';
import {ThemeProvider} from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import Header from './components/common/Header.tsx';
import {BrowserRouter as Router, Routes, Route} from 'react-router-dom';
import SummaryPage from "./components/SummaryPage.tsx";
import Loader from './components/common/Loader.tsx';
import {DataContextProvider} from './context/DataContextProvider.tsx';
import {fetchJSON, fetchKnowledgeStatements, fetchMajorNerves} from "./services/fetchService.ts";
import {getUniqueMajorNerves} from "./services/filterValuesService.ts";
import {HierarchicalNode, KnowledgeStatement, Organ} from "./models/explorer.ts";
import {getHierarchicalNodes, getOrgans} from "./services/hierarchyService.ts";

const App = () => {
const store = useStore();
const dispatch = useDispatch();
const [LayoutComponent, setLayoutComponent] = useState<React.ComponentType | undefined>(undefined);
const [hierarchicalNodes, setHierarchicalNodes] = useState<Record<string, HierarchicalNode>>({});
const [organs, setOrgans] = useState<Record<string, Organ>>({});
const [majorNerves, setMajorNerves] = useState<Set<string>>();
const [knowledgeStatements, setKnowledgeStatements] = useState<Record<string, KnowledgeStatement>>({});

useEffect(() => {
if (LayoutComponent === undefined) {
const myManager = getLayoutManagerInstance();
if (myManager) {
setLayoutComponent(myManager.getComponent());
}
}
}, [store, dispatch, LayoutComponent])

useEffect(() => {
dispatch(addWidget(connectivityGridWidget()));
dispatch(addWidget(connectionsWidget()));
}, [LayoutComponent, dispatch])

useEffect(() => {
fetchJSON().then(data => {
setHierarchicalNodes(getHierarchicalNodes(data));
setOrgans(getOrgans(data))
}).catch(error => {
// TODO: We should give feedback to the user
console.error("Failed to fetch JSON data:", error);
});

fetchMajorNerves().then(data => {
setMajorNerves(getUniqueMajorNerves(data));
}).catch(error => {
// TODO: We should give feedback to the user
console.error("Failed to fetch major nerves data:", error);
setMajorNerves(undefined);
});
}, []);

useEffect(() => {
if (Object.keys(hierarchicalNodes).length > 0) {
const neuronIDsSet = new Set<string>();

// Loop through each node's connectionDetails and add all ids to the neuronIDsSet
Object.values(hierarchicalNodes).forEach(node => {
if (node.connectionDetails) {
Object.values(node.connectionDetails).forEach(ksIds => {
ksIds.forEach(id => neuronIDsSet.add(id));
});
}
});

fetchKnowledgeStatements(Array.from(neuronIDsSet))
.then(statements => {
// Convert array to a map by ID for easy access
const ksMap = statements.reduce<Record<string, KnowledgeStatement>>((acc, ks) => {
acc[ks.id] = ks;
return acc;
}, {});
setKnowledgeStatements(ksMap)
}).catch(error => {
// TODO: We should give feedback to the user
console.error("Failed to fetch knowledge statements data:", error);
})
}
}, [hierarchicalNodes]);

const isLoading = LayoutComponent === undefined || Object.keys(hierarchicalNodes).length === 0
|| majorNerves === undefined || Object.keys(organs).length == 0 || Object.keys(knowledgeStatements).length == 0

return (
<>
<ThemeProvider theme={theme}>
<CssBaseline/>
<Router>
<Box>
<Header/>
<Box className="MuiContainer">
<Routes>
<Route path="/summary" element={<SummaryPage/>}/>
<Route path="/" element={isLoading ? <Loader /> :
<DataContextProvider
majorNerves={majorNerves}
hierarchicalNodes={hierarchicalNodes}
organs={organs}
knowledgeStatements={knowledgeStatements}
>
<LayoutComponent/>
</DataContextProvider>
}
/>
</Routes>
</Box>
</Box>
</Router>
</ThemeProvider>
</>
);
}

export default App;
import React, { useEffect, useState } from 'react';
import { useDispatch, useStore } from 'react-redux';
import { Box } from '@mui/material';
import { getLayoutManagerInstance } from '@metacell/geppetto-meta-client/common/layout/LayoutManager';
import { addWidget } from '@metacell/geppetto-meta-client/common/layout/actions';
import {
connectionsWidget,
connectivityGridWidget,
} from './layout-manager/widgets.ts';
import '@metacell/geppetto-meta-ui/flex-layout/style/light.scss';
import theme from './theme/index.tsx';
import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import Header from './components/common/Header.tsx';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import SummaryPage from './components/SummaryPage.tsx';
import Loader from './components/common/Loader.tsx';
import { DataContextProvider } from './context/DataContextProvider.tsx';
import {
fetchJSON,
fetchKnowledgeStatements,
fetchMajorNerves,
} from './services/fetchService.ts';
import { getUniqueMajorNerves } from './services/filterValuesService.ts';
import {
HierarchicalNode,
KnowledgeStatement,
Organ,
} from './models/explorer.ts';
import {
getHierarchicalNodes,
getOrgans,
} from './services/hierarchyService.ts';

const App = () => {
const store = useStore();
const dispatch = useDispatch();
const [LayoutComponent, setLayoutComponent] = useState<
React.ComponentType | undefined
>(undefined);
const [hierarchicalNodes, setHierarchicalNodes] = useState<
Record<string, HierarchicalNode>
>({});
const [organs, setOrgans] = useState<Record<string, Organ>>({});
const [majorNerves, setMajorNerves] = useState<Set<string>>();
const [knowledgeStatements, setKnowledgeStatements] = useState<
Record<string, KnowledgeStatement>
>({});

useEffect(() => {
if (LayoutComponent === undefined) {
const myManager = getLayoutManagerInstance();
if (myManager) {
setLayoutComponent(myManager.getComponent());
}
}
}, [store, dispatch, LayoutComponent]);

useEffect(() => {
dispatch(addWidget(connectivityGridWidget()));
dispatch(addWidget(connectionsWidget()));
}, [LayoutComponent, dispatch]);

useEffect(() => {
fetchJSON()
.then((data) => {
setHierarchicalNodes(getHierarchicalNodes(data));
setOrgans(getOrgans(data));
})
.catch((error) => {
// TODO: We should give feedback to the user
console.error('Failed to fetch JSON data:', error);
});

fetchMajorNerves()
.then((data) => {
setMajorNerves(getUniqueMajorNerves(data));
})
.catch((error) => {
// TODO: We should give feedback to the user
console.error('Failed to fetch major nerves data:', error);
setMajorNerves(undefined);
});
}, []);

useEffect(() => {
if (Object.keys(hierarchicalNodes).length > 0) {
const neuronIDsSet = new Set<string>();

// Loop through each node's connectionDetails and add all ids to the neuronIDsSet
Object.values(hierarchicalNodes).forEach((node) => {
if (node.connectionDetails) {
Object.values(node.connectionDetails).forEach((ksIds) => {
ksIds.forEach((id) => neuronIDsSet.add(id));
});
}
});

fetchKnowledgeStatements(Array.from(neuronIDsSet))
.then((statements) => {
// Convert array to a map by ID for easy access
const ksMap = statements.reduce<Record<string, KnowledgeStatement>>(
(acc, ks) => {
acc[ks.id] = ks;
return acc;
},
{},
);
setKnowledgeStatements(ksMap);
})
.catch((error) => {
// TODO: We should give feedback to the user
console.error('Failed to fetch knowledge statements data:', error);
});
}
}, [hierarchicalNodes]);

const isLoading =
LayoutComponent === undefined ||
Object.keys(hierarchicalNodes).length === 0 ||
majorNerves === undefined ||
Object.keys(organs).length == 0 ||
Object.keys(knowledgeStatements).length == 0;

return (
<>
<ThemeProvider theme={theme}>
<CssBaseline />
<Router>
<Box>
<Header />
<Box className="MuiContainer">
<Routes>
<Route path="/summary" element={<SummaryPage />} />
<Route
path="/"
element={
isLoading ? (
<Loader />
) : (
<DataContextProvider
majorNerves={majorNerves}
hierarchicalNodes={hierarchicalNodes}
organs={organs}
knowledgeStatements={knowledgeStatements}
>
<LayoutComponent />
</DataContextProvider>
)
}
/>
</Routes>
</Box>
</Box>
</Router>
</ThemeProvider>
</>
);
};

export default App;
Loading

0 comments on commit a44cf9a

Please sign in to comment.