Skip to content

Commit

Permalink
refactor error=deleted to prop
Browse files Browse the repository at this point in the history
  • Loading branch information
zbycz committed Oct 27, 2023
1 parent f66f6d1 commit d925e62
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 29 deletions.
5 changes: 2 additions & 3 deletions src/components/FeaturePanel/FeaturePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ export const FeaturePanel = () => {
const [showAround, toggleShowAround] = useToggleState(false);
const [showTags, toggleShowTags] = useToggleState(false);

const { point, tags, osmMeta, skeleton, error } = feature;
const deleted = error === 'deleted';
const editEnabled = !skeleton && (!error || deleted);
const { point, tags, osmMeta, skeleton, deleted } = feature;
const editEnabled = !skeleton;
const showTagsTable = deleted || showTags;

const osmappLink = getFullOsmappLink(feature);
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeaturePanel/OsmError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const OsmError = () => {
const { feature } = useFeatureContext();
const code = feature.error;

if (code === 'deleted') {
if (feature.deleted) {
return (
<Box mb={3} clone>
<Alert variant="outlined" severity="warning">
Expand Down
11 changes: 6 additions & 5 deletions src/components/FeaturePanel/Properties/IdSchemeFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@ const addUnits = (label, value: string | ReactNode) => {
return `${value}${unit ? ` (${unit[1]})` : ''}`;
};

const getTooltip = (field: Field, key: string, value: string) =>
const getTooltip = (field: Field, key: string) =>
`field: ${field.fieldKey}${key === field.fieldKey ? '' : `, key: ${key}`}`;

export const IdSchemeFields = () => {
const { openWithTag } = useEditDialogContext();
const [otherTagsShown, toggleOtherTagsShown] = useToggleState(false);
const { feature } = useFeatureContext();
const deleted = feature.error === 'deleted';
const featuredTags = deleted ? [] : feature.schema?.featuredTags ?? [];
const featuredTags = feature.deleted
? []
: feature.schema?.featuredTags ?? [];
const { schema } = feature;

if (!schema) return null;
Expand Down Expand Up @@ -119,7 +120,7 @@ export const IdSchemeFields = () => {
{schema.matchedFields.map(
({ key, value, label, field, fieldTranslation, tagsForField }) => (
<tr key={key}>
<th title={getTooltip(field, key, value)}>
<th title={getTooltip(field, key)}>
{removeUnits(label)}
</th>
<td>
Expand Down Expand Up @@ -167,7 +168,7 @@ export const IdSchemeFields = () => {
tagsForField,
}) => (
<tr key={key}>
<th title={getTooltip(field, key, value)}>
<th title={getTooltip(field, key)}>
{removeUnits(label)}
</th>
<td>
Expand Down
5 changes: 3 additions & 2 deletions src/components/FeaturePanel/Properties/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { Subheading } from '../helpers/Subheading';

export const Properties = ({ showTags }) => {
const { feature } = useFeatureContext();
const deleted = feature.error === 'deleted';

return (
<>
{!showTags && (
<>
<FeaturedTags
featuredTags={deleted ? [] : feature.schema?.featuredTags ?? []}
featuredTags={
feature.deleted ? [] : feature.schema?.featuredTags ?? []
}
/>
<IdSchemeFields />
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeaturePanel/Properties/helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import styled from 'styled-components';
import Button from '@material-ui/core/Button';
import { t } from '../../../services/intl';
import ChevronRight from '@material-ui/icons/ChevronRight';
import ExpandLessIcon from '@material-ui/icons/ExpandLess';
import React from 'react';
import { t } from '../../../services/intl';

const StyledToggleButton = styled(Button)`
svg {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/TitleAndMetaTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const OpenGraphTags = ({

const getTitle = (feature: Feature) => {
const label = getLabel(feature);
return feature.error === 'deleted' ? getUtfStrikethrough(label) : label;
return feature.deleted ? getUtfStrikethrough(label) : label;
};

export const TitleAndMetaTags = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/osmApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const osmToFeature = (element): Feature => {
tags,
members,
properties: getPoiClass(tags),
error: osmappDeletedMarker ? 'deleted' : undefined,
deleted: osmappDeletedMarker,
};
};

Expand Down
18 changes: 9 additions & 9 deletions src/services/osmApiAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,20 @@ const getItemOrLastHistoric = async (apiId: OsmApiId) => {
}
};

const getDescription = (isDelete, feature) => {
const undelete = feature.error === 'deleted';
const action = undelete ? 'Undeleted' : isDelete ? 'Deleted' : 'Edited';
const getDescription = (isCancelled, feature) => {
const undelete = feature.deleted;
const action = undelete ? 'Undeleted' : isCancelled ? 'Deleted' : 'Edited';
const { subclass } = feature.properties;
const name = feature.tags.name || subclass || getUrlOsmId(feature.osmMeta);
return `${action} ${name}`;
};

const getChangesetComment = (
comment: string,
isDelete: boolean,
isCancelled: boolean,
feature: Feature,
) => {
const description = getDescription(isDelete, feature);
const description = getDescription(isCancelled, feature);
return join(comment, ' • ', `${description} #osmapp`);
};

Expand Down Expand Up @@ -208,10 +208,10 @@ export const editOsmFeature = async (
feature: Feature,
comment: string,
newTags: FeatureTags,
isDelete: boolean,
isCancelled: boolean,
) => {
const apiId = prod ? feature.osmMeta : TEST_OSM_ID;
const changesetComment = getChangesetComment(comment, isDelete, feature);
const changesetComment = getChangesetComment(comment, isCancelled, feature);
const changesetXml = getChangesetXml({ changesetComment, feature });

const changesetId = await putChangeset(changesetXml);
Expand All @@ -224,10 +224,10 @@ export const editOsmFeature = async (
apiId,
changesetId,
newTags,
isDelete,
isCancelled,
);

await putOrDeleteItem(isDelete, apiId, newItem);
await putOrDeleteItem(isCancelled, apiId, newItem);
await putChangesetClose(changesetId);

clearFeatureCache(feature.osmMeta);
Expand Down
10 changes: 5 additions & 5 deletions src/services/tagging/idTaggingScheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const matchFieldsFromPreset = (
preset: Preset,
keysTodo: any,
feature: Feature,
) => {
): any => {
const computedAllFieldKeys = computeAllFieldKeys(preset);
publishDbgObject('computedAllFieldKeys', computedAllFieldKeys);

Expand All @@ -38,11 +38,11 @@ const matchFieldsFromPreset = (
const shouldWeIncludeThisField =
keysTodo.has(key) || keysTodo.hasAny(keys);
if (!shouldWeIncludeThisField) {
return {};
return undefined;
}
if (field.type === 'typeCombo') {
keysTodo.remove(field.key); // ignores eg. railway=tram_stop on public_transport=stop_position
return {};
return undefined;
}

const value = feature.tags[key];
Expand Down Expand Up @@ -98,11 +98,11 @@ const matchRestToFields = (keysTodo: KeysTodo, feature: Feature) =>
}

if (!field) {
return false;
return undefined;
}
if (field.type === 'typeCombo') {
keysTodo.remove(field.key); // ignores eg. railway=tram_stop on public_transport=stop_position
return false;
return undefined;
}

const value = feature.tags[key];
Expand Down
3 changes: 2 additions & 1 deletion src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export interface Feature {
center: Position;
roundedCenter?: LonLatRounded;
ssrFeatureImage?: Image;
error?: 'deleted' | 'network' | 'unknown' | '404' | '500'; // etc.
error?: 'network' | 'unknown' | '404' | '500'; // etc.
deleted?: boolean;
schema?: ReturnType<typeof getSchemaForFeature>;

// skeleton
Expand Down

0 comments on commit d925e62

Please sign in to comment.