Skip to content

Commit

Permalink
FeaturePanel: remove pointless fields (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbycz authored Feb 6, 2025
1 parent 0aebc65 commit 0ee087b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/services/tagging/__tests__/idTaggingScheme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ describe('idTaggingScheme', () => {

expect(schema.label).toBe('Fountain');
expect(schema.featuredTags).toEqual([['wikidata', 'Q94435643']]);
expect(schema.matchedFields.map((x: any) => x.field.fieldKey)).toEqual([
'wikimedia_commons',
]);
expect(schema.matchedFields.map((x: any) => x.field.fieldKey)).toEqual([]);
expect(schema.tagsWithFields.map((x: any) => x.field.fieldKey)).toEqual([
'natural',
'source',
Expand Down
21 changes: 14 additions & 7 deletions src/services/tagging/idTaggingScheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,28 @@ const matchRestToFields = (keysTodo: KeysTodo, feature: Feature): UiField[] =>
type KeysTodo = typeof keysTodo;
const keysTodo = {
state: [] as string[],
init(feature) {
init(feature: Feature) {
this.state = Object.keys(feature.tags);
},
resolveTags(tags) {
resolveTags(tags: FeatureTags) {
Object.keys(tags).forEach((key) => this.remove(key));
},
has(key) {
has(key: string) {
return this.state.includes(key);
},
hasAny(keys) {
hasAny(keys: string[]) {
return keys?.some((key) => this.state.includes(key));
},
remove(key) {
remove(key: string) {
const index = this.state.indexOf(key);
if (index > -1) {
this.state.splice(index, 1);
}
},
resolveFields(fieldsArray) {
removeByRegexp(regexp: RegExp) {
this.state = this.state.filter((key: string) => !regexp.test(key));
},
resolveFields(fieldsArray: UiField[]) {
fieldsArray.forEach((field) => {
if (field?.field?.key) {
this.remove(field.field.key);
Expand Down Expand Up @@ -164,8 +167,12 @@ export const getSchemaForFeature = (feature: Feature) => {
keysTodo.init(feature);
keysTodo.resolveTags(preset.tags); // remove tags which are already covered by Preset
keysTodo.remove('name'); // always rendered by FeaturePanel
keysTodo.removeByRegexp(/^(image$|type$|wikimedia_commons)/); // images are rendered in FeatureImages
if (feature.tags.climbing) {
keysTodo.removeByRegexp(/^(sport|type|site)$/);
}

const featuredTags = feature.deleted ? [] : getFeaturedTags(feature);
const featuredTags = feature.deleted ? {} : getFeaturedTags(feature);
keysTodo.resolveTags(featuredTags);

const matchedFields = matchFieldsFromPreset(preset, keysTodo, feature);
Expand Down

0 comments on commit 0ee087b

Please sign in to comment.