Skip to content

Commit cc30fdd

Browse files
committed
Merge branch 'feature/fetch-replay-tool-status' into develop
2 parents ffe1188 + d342e2c commit cc30fdd

File tree

21 files changed

+3097
-977
lines changed

21 files changed

+3097
-977
lines changed

config/webpack.dev.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ module.exports = (env) => {
8383
host: '0.0.0.0',
8484
port: 3050,
8585
overlay: true,
86+
disableHostCheck: true,
8687
watchOptions: {
8788
ignored: /node_modules/,
8889
},

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@
150150
"@togglecorp/fujs": "^1.8.0",
151151
"@togglecorp/ravl": "^1.2.3",
152152
"@togglecorp/react-rest-request": "^2.5.0-beta.2",
153+
"@turf/nearest-point-to-line": "^6.0.0",
154+
"@turf/point-to-line-distance": "^6.0.0",
155+
"@turf/turf": "^5.1.6",
153156
"core-js": "3",
154157
"hoist-non-react-statics": "^3.3.0",
155158
"immer": "^3.2.0",

src/Root/App/Multiplexer/styles.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,17 @@
2020

2121
.button-primary {
2222
background-color: var(--color-primary)!important;
23-
color: var(--color-text-on-primary)!important;
2423
padding: var(--spacing-small) var(--spacing-medium)!important;
24+
color: var(--color-text-on-primary)!important;
25+
26+
.tc-v2-button-spinner {
27+
color: var(--color-text-on-primary)!important;
28+
}
29+
30+
&:disabled {
31+
background-color: var(--color-background-disabled)!important;
32+
color: var(--color-text-disabled)!important;
33+
}
2534
}
2635
}
2736

src/components/TextOutput/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ interface Props {
1313
}
1414

1515
class TextOutput extends React.PureComponent<Props> {
16+
static defaultProps = {
17+
value: '-',
18+
};
19+
1620
public render() {
1721
const {
1822
className,

src/constants/routeSettings.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ const routeSettings: SomeRoute[] = [
4242
load: () => import('../views/ConflictResolution'),
4343
navbar: true,
4444
},
45-
4645
{
4746
name: 'fourHundredThree',
4847
title: '403',
4948
path: '/403/',
5049
load: () => import('../views/FourHundredThree'),
5150
},
52-
5351
{
5452
name: 'fourHundredFour',
5553
title: '404',

src/constants/types.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
export type ResolutionStatus = 'conflicted' | 'resolved' | 'partially-resolved';
2-
export type ElementType = 'point' | 'line' | 'area';
1+
import { Feature, Geometry } from '@turf/turf';
2+
3+
export type ResolutionStatus = 'unresolved' | 'resolved' | 'partially_resolved';
4+
export type ElementType = 'node' | 'way' | 'relation';
5+
export type ShapeType = 'point' | 'line' | 'area';
36
export type Bounds = [number, number, number, number];
47

8+
interface ElementProperties {
9+
id: number;
10+
version: number;
11+
tags: Tags;
12+
location?: unknown;
13+
conflictingNodes?: unknown;
14+
}
15+
16+
export type ElementGeoJSON = GeoJSON.Feature<GeoJSON.Geometry, ElementProperties>;
17+
// | GeoJSON.FeatureCollection<GeoJSON.Geometry, ElementProperties>;
18+
519
interface Meta {
620
id: number;
721
version: number;
@@ -16,22 +30,34 @@ export interface Tags {
1630
[key: string]: string | undefined;
1731
}
1832

33+
/*
1934
export interface Content {
2035
meta: Meta;
2136
tags: Tags;
2237
bounds: Bounds;
23-
geoJSON?: GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry>;
38+
geoJSON?: ElementGeoJSON;
2439
}
40+
*/
2541

26-
export interface ConflictElement {
27-
id: string;
28-
title: string;
29-
resolutionStatus: ResolutionStatus;
42+
export interface BasicConflictElement {
43+
elementId: number;
44+
id: number;
45+
name: string;
3046
type: ElementType; // IDK about this
47+
status: ResolutionStatus;
48+
}
3149

32-
original: Content;
33-
theirs?: Content;
34-
ours?: Content;
50+
export interface ConflictElement extends BasicConflictElement {
51+
originalGeojson: ElementGeoJSON;
52+
localGeojson?: ElementGeoJSON;
53+
upstreamGeojson?: ElementGeoJSON;
54+
resolvedData: {
55+
id: number;
56+
tags?: Tags;
57+
location?: unknown;
58+
conflictingNodes?: unknown;
59+
};
60+
resolvedFrom: 'theirs' | 'ours' | 'custom' | null;
3561
}
3662

3763
// For nodes:

src/declarations/png.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.png' {
2+
const value: any;
3+
export = value;
4+
}

src/request.ts

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,34 @@ import {
33
methods,
44
CoordinatorAttributes,
55
} from '@togglecorp/react-rest-request';
6-
// import { AppState } from '#store/types';
76

8-
// import store from '#store';
97
import schema from '#schema';
108
import { sanitizeResponse } from '#utils/common';
119

1210
const wsEndpoint = process.env.REACT_APP_API_SERVER_URL;
1311

14-
// FIXME: don't know why eslint disable is required right now
15-
// eslint-disable-next-line arrow-parens
16-
export const createConnectedRequestCoordinator = <OwnProps>() => {
12+
const disableSchemaError = true;
13+
14+
export const getCookie = (name: string) => {
15+
const value = `; ${document.cookie}`;
16+
const parts = value.split(`; ${name}=`);
17+
18+
if (parts.length === 2) {
19+
const part = parts.pop();
20+
return part && part.split(';').shift();
21+
}
22+
return undefined;
23+
};
24+
25+
interface Error {
26+
errors?: {
27+
nonFieldErrors?: string[];
28+
internalNonFieldErrors?: string[];
29+
[key: string]: string[] | undefined;
30+
};
31+
}
32+
33+
export function createConnectedRequestCoordinator<OwnProps>() {
1734
type Props = OwnProps;
1835

1936
const requestor = createRequestCoordinator({
@@ -22,23 +39,21 @@ export const createConnectedRequestCoordinator = <OwnProps>() => {
2239
body,
2340
method,
2441
} = data;
42+
43+
const csrftoken = getCookie('csrftoken');
2544
return {
2645
method: method || methods.GET,
2746
body: JSON.stringify(body),
2847
headers: {
2948
Accept: 'application/json',
3049
'Content-Type': 'application/json; charset=utf-8',
50+
'X-CSRFToken': csrftoken,
3151
},
52+
credentials: 'include',
3253
};
3354
},
55+
// NOTE: we can inject props here
3456
transformProps: (props: Props) => props,
35-
/*
36-
transformProps: (props: Props) => {
37-
const mapStyle = mapStyleSelector(store.getState() as AppState);
38-
// console.warn('Map style is', mapStyle);
39-
return props;
40-
},
41-
*/
4257

4358
transformUrl: (url: string) => {
4459
if (/^https?:\/\//i.test(url)) {
@@ -59,7 +74,7 @@ export const createConnectedRequestCoordinator = <OwnProps>() => {
5974
const extras = requestOptions as { schemaName?: string };
6075
if (!extras || extras.schemaName === undefined) {
6176
// NOTE: usually there is no response body for DELETE
62-
if (method !== methods.DELETE) {
77+
if (method !== methods.DELETE && !disableSchemaError) {
6378
console.error(`Schema is not defined for ${url} ${method}`);
6479
}
6580
} else {
@@ -74,16 +89,21 @@ export const createConnectedRequestCoordinator = <OwnProps>() => {
7489
return sanitizedResponse;
7590
},
7691

77-
transformErrors: (response: { errors: string[] }) => {
78-
const faramErrors = response.errors;
92+
transformErrors: (response: Error) => {
93+
// eslint-disable-next-line @typescript-eslint/camelcase
94+
const { non_field_errors, ...faramErrors } = response.errors || {};
95+
// eslint-disable-next-line @typescript-eslint/camelcase
96+
const nonFieldErrors = non_field_errors ? non_field_errors.join(' ') : undefined;
97+
7998
return {
8099
response,
81100
faramErrors,
101+
nonFieldErrors,
82102
};
83103
},
84104
});
85105

86106
return requestor;
87-
};
107+
}
88108

89109
export * from '@togglecorp/react-rest-request';

src/utils/common.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ export const forEach = (obj: object, func: (key: string, val: unknown) => void)
1313

1414
export const sanitizeResponse = (data: unknown): any => {
1515
if (data === null || data === undefined) {
16-
return undefined;
16+
return data;
1717
}
1818
if (isList(data)) {
19-
return data.map(sanitizeResponse).filter(isDefined);
19+
return data
20+
.map(sanitizeResponse)
21+
.filter(item => item !== undefined);
2022
}
2123
if (isObject(data)) {
2224
let newData = {};
2325
forEach(data, (k, val) => {
2426
const newEntry = sanitizeResponse(val);
25-
if (newEntry) {
27+
if (newEntry !== undefined) {
2628
newData = {
2729
...newData,
2830
[k]: newEntry,

0 commit comments

Comments
 (0)