Skip to content

Commit 0ad2f4e

Browse files
committed
add method to remove features from the upload wizard
1 parent 64294e6 commit 0ad2f4e

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/pages/upload/MapPreview.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const MapPreview: React.FC<{
2727
fetchCache: FetchCache | undefined;
2828
bboxFromOsmPatch: Bbox | undefined;
2929
setFocusedFeatureId(id: string | number): void;
30+
removeFeatureFromPatch(id: string | number): Promise<void>;
3031
moveNode:
3132
| ((feature: OsmPatchFeature, lat: number, lng: number) => void)
3233
| false;
@@ -36,6 +37,7 @@ export const MapPreview: React.FC<{
3637
fetchCache,
3738
bboxFromOsmPatch,
3839
setFocusedFeatureId,
40+
removeFeatureFromPatch,
3941
moveNode,
4042
}) => {
4143
const allowEdit = !!moveNode;
@@ -104,6 +106,15 @@ export const MapPreview: React.FC<{
104106
click: () => setFocusedFeatureId(feature.id!),
105107
dragstart: () => setFocusedFeatureId(feature.id!),
106108
dragend: (event) => onDragEnd(event, feature),
109+
dblclick: async () => {
110+
if (
111+
// this is not for end users, so the UX can be a bit crude
112+
// eslint-disable-next-line no-restricted-globals, no-alert
113+
confirm('u want to remove this feature from the diff?')
114+
) {
115+
await removeFeatureFromPatch(feature.id!);
116+
}
117+
},
107118
}}
108119
draggable={allowEdit && !feature.properties.__action}
109120
/>

src/pages/upload/Upload.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ const UploadInner: React.FC = () => {
8989
}
9090
}
9191

92+
async function removeFeatureFromPatch(id: string) {
93+
await rebuildOsmChange({
94+
...osmPatch!,
95+
features: osmPatch!.features.filter((feature) => feature.id !== id),
96+
});
97+
}
98+
9299
async function onFileUpload(files: FileList | null) {
93100
if (!files?.length) {
94101
// the user unselected the current file, so reset
@@ -313,6 +320,7 @@ const UploadInner: React.FC = () => {
313320
osmPatch={osmPatch}
314321
bboxFromOsmPatch={bboxFromOsmPatch}
315322
setFocusedFeatureId={setFocusedFeatureId}
323+
removeFeatureFromPatch={removeFeatureFromPatch}
316324
moveNode={allowEdit && moveNode}
317325
/>
318326
</div>
@@ -321,6 +329,7 @@ const UploadInner: React.FC = () => {
321329
<DiffForFeature
322330
feature={focusedFeature}
323331
original={fetchCache?.[`${focusedFeature.id}`]}
332+
removeFeatureFromPatch={removeFeatureFromPatch}
324333
/>
325334
) : (
326335
<em>Select a feature to view more details</em>

src/pages/upload/components/DiffForFeature.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const EMPTY_CELL = <td>&nbsp;</td>;
1515
export const DiffForFeature: React.FC<{
1616
feature: OsmPatchFeature;
1717
original: OsmFeature | undefined;
18-
}> = ({ feature, original }) => {
18+
removeFeatureFromPatch(id: string | number): Promise<void>;
19+
}> = ({ feature, original, removeFeatureFromPatch }) => {
1920
const tag2link = useTag2link();
2021
const { user: me } = useContext(AuthContext);
2122

@@ -42,7 +43,14 @@ export const DiffForFeature: React.FC<{
4243
<header style={{ textTransform: 'capitalize' }}>
4344
{action ? (
4445
<>
45-
{type} {id}<OpenInLinks type={type} id={id} />
46+
{type} {id}{' '}
47+
<button
48+
type="button"
49+
onClick={() => removeFeatureFromPatch(feature.id!)}
50+
>
51+
Remove
52+
</button>{' '}
53+
<OpenInLinks type={type} id={id} />
4654
</>
4755
) : (
4856
<>🆕 {feature.id}</>

0 commit comments

Comments
 (0)