Add global edit history page

This commit is contained in:
Maciej Ziarkowski 2019-11-14 15:28:12 +00:00
parent 91270ff6a0
commit 70fa8725b4
3 changed files with 46 additions and 1 deletions

View File

@ -6,7 +6,9 @@ import * as editHistoryService from '../services/editHistory';
const getGlobalEditHistory = asyncController(async (req: express.Request, res: express.Response) => {
try {
const result = await editHistoryService.getGlobalEditHistory();
res.send(result);
res.send({
history: result
});
} catch(error) {
console.error(error);
res.send({ error: 'Database error' });

View File

@ -9,6 +9,7 @@ import MapApp from './map-app';
import { Building } from './models/building';
import { User } from './models/user';
import AboutPage from './pages/about';
import ChangesPage from './pages/changes';
import ContactPage from './pages/contact';
import ContributorAgreementPage from './pages/contributor-agreement';
import DataAccuracyPage from './pages/data-accuracy';
@ -112,6 +113,7 @@ class App extends React.Component<AppProps, AppState> {
<Route exact path="/data-accuracy.html" component={DataAccuracyPage} />
<Route exact path="/data-extracts.html" component={DataExtracts} />
<Route exact path="/contact.html" component={ContactPage} />
<Route exact path="/history.html" component={ChangesPage} />
<Route exact path={App.mapAppPaths} render={(props) => (
<MapApp
{...props}

View File

@ -0,0 +1,41 @@
import React, { useEffect, useState } from 'react';
import { BuildingEditSummary } from '../building/edit-history/building-edit-summary';
import { EditHistoryEntry } from '../models/edit-history-entry';
const ChangesPage = () => {
const [history, setHistory] = useState<EditHistoryEntry[]>(undefined);
useEffect(() => {
const fetchData = async () => {
const res = await fetch(`/api/history`);
const data = await res.json();
setHistory(data.history);
};
fetchData();
}, []);
return (
<article>
<section className="main-col">
<h1>Global edit history</h1>
<ul className="edit-history-list">
{history && history.map(entry => (
<li key={`${entry.revision_id}`} className="edit-history-list-element">
<BuildingEditSummary
historyEntry={entry}
showBuildingId={true}
hyperlinkCategories={true}
/>
</li>
))}
</ul>
</section>
</article>
);
};
export default ChangesPage;