Skip to content

Commit

Permalink
#16 scrap tree structure, tables rule!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
albertus-andito committed May 30, 2021
1 parent 7cc5dea commit 0ed6d62
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 61 deletions.
27 changes: 26 additions & 1 deletion src/views/thesis-bank/components/ThesesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Table } from 'antd';
import { getColumnSearchProps } from '../../member-database/ColumnSearchProps';
import { Link } from 'react-router-dom';

export default function ThesesTable({ theses }) {
export default function ThesesTable({ theses, isPublic }) {
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(10);
const [searchText, setSearchText] = useState('');
Expand All @@ -19,12 +19,25 @@ export default function ThesesTable({ theses }) {
setSearchedColumn,
];

const url = isPublic ? '/thesis/' : '/app/thesis-bank/';

const cols = [
{
title: 'No',
key: 'index',
render: (value, item, index) => (page - 1) * pageSize + index + 1,
},
{
title: 'Year',
dataIndex: 'year',
key: 'year',
defaultSortOrder: 'descend',
sorter: {
compare: (a, b) =>
a.year > b.year ? 1 : a.year < b.year ? -1 : 0,
},
...getColumnSearchProps('year', ...colSearchParams),
},
{
title: 'Type',
dataIndex: 'itemType',
Expand All @@ -43,6 +56,8 @@ export default function ThesesTable({ theses }) {
compare: (a, b) => (a.title || '').localeCompare(b.title || ''),
},
...getColumnSearchProps('title', ...colSearchParams),
// eslint-disable-next-line react/display-name
render: (title, row) => <Link to={url + row._id}>{title}</Link>,
},
{
title: 'Corresponding Author',
Expand All @@ -63,6 +78,16 @@ export default function ThesesTable({ theses }) {
<Link to={`/app/profile/${author.id}`}>{author.name}</Link>
),
},
{
title: 'University',
dataIndex: 'university',
key: 'university',
sorter: {
compare: (a, b) =>
(a.university || '').localeCompare(b.university || ''),
},
...getColumnSearchProps('university', ...colSearchParams),
},
];
return (
<Table
Expand Down
15 changes: 15 additions & 0 deletions src/views/thesis-bank/components/Thesis.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ export default function Thesis({ id }) {
<Typography>{thesis.abstract}</Typography>
<br />
<Typography>Item type: {thesis.itemType}</Typography>
<Typography>Year: {thesis.year}</Typography>
<Typography>
Authors:{' '}
{thesis.authors
.map((author) => {
return author._id === undefined ? (
author.fullName
) : (
<Link to={`/app/profile/${author._id}`}>
{author.fullName}
</Link>
);
})
.reduce((prev, curr) => [prev, ', ', curr])}
</Typography>
<Typography>
Contributor/Contact Person:{' '}
{thesis.correspondingAuthor._id === undefined ? (
Expand Down
179 changes: 119 additions & 60 deletions src/views/thesis-bank/public-root/index.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,139 @@
import React, { useEffect, useState } from 'react';

import axios from 'axios';
import { Tree } from 'antd';
import { Link } from 'react-router-dom';
import { Collapse, Typography } from 'antd';
import ThesesTable from '../components/ThesesTable';

const { Panel } = Collapse;

export default function PublicThesesView() {
const initTreeData = [
const initData = [
{
cluster: 'Economics and Business',
},
{
cluster: 'Education',
},
{
cluster: 'Energy',
},
{
cluster: 'Health',
},
{
title: 'Clusters',
key: 'clusters',
children: [
{
title: 'Economics and Business',
key: 'Economics and Business',
},
{
title: 'Education',
key: 'Education',
},
{
title: 'Energy',
key: 'Energy',
},
{
title: 'Health',
key: 'Health',
},
{
title: 'Infrastructure and Built Environment',
key: 'Infrastructure and Built Environment',
},
{
title: 'Politics and Law',
key: 'Politics and Law',
},
{
title: 'Social Development, Arts and Humanity',
key: 'Social Development, Arts and Humanity',
},
{
title: 'STEM',
key: 'STEM',
},
],
cluster: 'Infrastructure and Built Environment',
},
{
cluster: 'Politics and Law',
},
{
cluster: 'Social Development, Arts and Humanity',
},
{
cluster: 'STEM',
},
];

const [theses, setTheses] = useState(initTreeData);
const [theses, setTheses] = useState(null);

useEffect(() => {
axios.get('/api/thesis/').then((res) => {
let clusters = theses.find((item) => {
return item.key === 'clusters';
});
for (const cluster of clusters.children) {
let clusteredTheses = res.data.theses.filter((item) => {
return item.cluster === cluster.key;
});
cluster.children = clusteredTheses.map((item) => {
return {
title: (
<Link to={`/thesis/${item._id}`}>{item.title}</Link>
),
key: item._id,
};
for (const cluster of initData) {
cluster.theses = res.data.theses.filter((item) => {
return item.cluster === cluster.cluster;
});
}
setTheses([clusters]);
setTheses(initData);
});
}, []);

const selectCluster = (name) => {
return theses.find((item) => item.cluster === name).theses;
};

return (
<Tree
defaultExpandedKeys={['clusters']}
selectable={false}
treeData={theses}
/>
<div>
<Typography.Title level={3}>Clusters</Typography.Title>

<Collapse>
<Panel
header="Economics and Business"
key="Economics and Business"
>
{theses && (
<ThesesTable
theses={selectCluster('Economics and Business')}
isPublic={true}
/>
)}
</Panel>
<Panel header="Education" key="Education">
{theses && (
<ThesesTable
theses={selectCluster('Education')}
isPublic={true}
/>
)}
</Panel>
<Panel header="Energy" key="Energy">
{theses && (
<ThesesTable
theses={selectCluster('Energy')}
isPublic={true}
/>
)}
</Panel>
<Panel header="Health" key="Health">
{theses && (
<ThesesTable
theses={selectCluster('Health')}
isPublic={true}
/>
)}
</Panel>
<Panel
header="Infrastructure and Built Environment"
key="Infrastructure and Built Environment"
>
{theses && (
<ThesesTable
theses={selectCluster(
'Infrastructure and Built Environment'
)}
isPublic={true}
/>
)}
</Panel>
<Panel header="Politics and Law" key="Politics and Law">
{theses && (
<ThesesTable
theses={selectCluster('Politics and Law')}
isPublic={true}
/>
)}
</Panel>
<Panel
header="Social Development, Arts and Humanity"
key="Social Development, Arts and Humanity"
>
{theses && (
<ThesesTable
theses={selectCluster(
'Social Development, Arts and Humanity'
)}
isPublic={true}
/>
)}
</Panel>
<Panel header="STEM" key="STEM">
{theses && (
<ThesesTable
theses={selectCluster('STEM')}
isPublic={true}
/>
)}
</Panel>
</Collapse>
</div>
);
}

0 comments on commit 0ed6d62

Please sign in to comment.