Add edit history frontend routing

This commit is contained in:
Maciej Ziarkowski 2019-10-24 12:20:48 +01:00
parent 2e47d85faa
commit 8bc56fbbe2
3 changed files with 10 additions and 3 deletions

View File

@ -105,7 +105,7 @@ class App extends React.Component<AppProps, any> { // TODO: add proper types
<Route exact path="/data-accuracy.html" component={DataAccuracyPage} /> <Route exact path="/data-accuracy.html" component={DataAccuracyPage} />
<Route exact path="/data-extracts.html" component={DataExtracts} /> <Route exact path="/data-extracts.html" component={DataExtracts} />
<Route exact path="/contact.html" component={ContactPage} /> <Route exact path="/contact.html" component={ContactPage} />
<Route exact path={["/", "/:mode(view|edit|multi-edit)/:category/:building(\\d+)?"]} render={(props) => ( <Route exact path={["/", "/:mode(view|edit|multi-edit)/:category?/:building(\\d+)?/(history)?"]} render={(props) => (
<MapApp <MapApp
{...props} {...props}
building={this.props.building} building={this.props.building}

View File

@ -9,6 +9,8 @@ import MultiEdit from './building/multi-edit';
import BuildingView from './building/building-view'; import BuildingView from './building/building-view';
import ColouringMap from './map/map'; import ColouringMap from './map/map';
import { parse } from 'query-string'; import { parse } from 'query-string';
import { EditHistory } from './building/edit-history/edit-history';
import { Building } from './models/building';
interface MapAppRouteParams { interface MapAppRouteParams {
mode: 'view' | 'edit' | 'multi-edit'; mode: 'view' | 'edit' | 'multi-edit';
@ -25,7 +27,7 @@ interface MapAppProps extends RouteComponentProps<MapAppRouteParams> {
interface MapAppState { interface MapAppState {
category: string; category: string;
revision_id: number; revision_id: number;
building: any; building: Building;
building_like: boolean; building_like: boolean;
} }
@ -234,6 +236,11 @@ class MapApp extends React.Component<MapAppProps, MapAppState> {
/> />
</Sidebar> </Sidebar>
</Route> </Route>
<Route exact path="/:mode/:cat/:building/history">
<Sidebar>
<EditHistory building={this.state.building} />
</Sidebar>
</Route>
<Route exact path="/(view|edit|multi-edit)"> <Route exact path="/(view|edit|multi-edit)">
<Redirect to="/view/categories" /> <Redirect to="/view/categories" />
</Route> </Route>

View File

@ -23,7 +23,7 @@ function strictParseInt(value) {
* @returns {number|undefined} * @returns {number|undefined}
*/ */
function parseBuildingURL(url) { function parseBuildingURL(url) {
const re = /\/(\d+)$/; const re = /\/(\d+)(\/history)?$/;
const matches = re.exec(url); const matches = re.exec(url);
if (matches && matches.length >= 2) { if (matches && matches.length >= 2) {