-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Build correct event filter for appeal and tags #245
Conversation
@@ -10,7 +10,7 @@ const EMPTY_ARR = [] | |||
export const LabelSelector = (props: LabelsProps) => { | |||
const { | |||
id, | |||
formId, | |||
form, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just cleaning these up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Only stylistic comments. 👍
if (!tagTypes.includes(type)) { | ||
return { add, remove } | ||
} | ||
|
||
tagTypes.forEach((key) => { | ||
if (type === key) { | ||
if (TagBasedTypeFilters[key].add) { | ||
add.push(TagBasedTypeFilters[key].add) | ||
} | ||
if (TagBasedTypeFilters[key].remove) { | ||
remove.push(TagBasedTypeFilters[key].remove) | ||
} | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like that iteration is not really needed:
if (!tagTypes.includes(type)) { | |
return { add, remove } | |
} | |
tagTypes.forEach((key) => { | |
if (type === key) { | |
if (TagBasedTypeFilters[key].add) { | |
add.push(TagBasedTypeFilters[key].add) | |
} | |
if (TagBasedTypeFilters[key].remove) { | |
remove.push(TagBasedTypeFilters[key].remove) | |
} | |
} | |
}) | |
if (type in tagTypes && Object.hasOwn(tagTypes, type)) { | |
if (TagBasedTypeFilters[type].add) { | |
add.push(TagBasedTypeFilters[type].add) | |
} | |
if (TagBasedTypeFilters[type].remove) { | |
remove.push(TagBasedTypeFilters[type].remove) | |
} | |
} |
Note that Object.hasOwn
is not needed if the object is created using __proto__: null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice thanks!
const TagBasedTypeFilters = { | ||
[MOD_EVENTS.DISABLE_DMS]: { add: DM_DISABLE_TAG, remove: '' }, | ||
[MOD_EVENTS.ENABLE_DMS]: { remove: DM_DISABLE_TAG, add: '' }, | ||
[MOD_EVENTS.DISABLE_VIDEO_UPLOAD]: { | ||
add: VIDEO_UPLOAD_DISABLE_TAG, | ||
remove: '', | ||
}, | ||
[MOD_EVENTS.ENABLE_VIDEO_UPLOAD]: { | ||
remove: VIDEO_UPLOAD_DISABLE_TAG, | ||
add: '', | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using objects as a map is not ideal in javascript (because TagBasedTypeFilters['toString']
will be there and might cause abuse). You can make it safer by using a Map
(best) or by removing the inheritance of Object.prototype
like so (technically safe but funkier in terms of maintainability):
const TagBasedTypeFilters = { | |
[MOD_EVENTS.DISABLE_DMS]: { add: DM_DISABLE_TAG, remove: '' }, | |
[MOD_EVENTS.ENABLE_DMS]: { remove: DM_DISABLE_TAG, add: '' }, | |
[MOD_EVENTS.DISABLE_VIDEO_UPLOAD]: { | |
add: VIDEO_UPLOAD_DISABLE_TAG, | |
remove: '', | |
}, | |
[MOD_EVENTS.ENABLE_VIDEO_UPLOAD]: { | |
remove: VIDEO_UPLOAD_DISABLE_TAG, | |
add: '', | |
}, | |
} | |
const TagBasedTypeFilters = { | |
__proto__: null, // Allows safely using this as a "hashmap" | |
[MOD_EVENTS.DISABLE_DMS]: { add: DM_DISABLE_TAG, remove: '' }, | |
[MOD_EVENTS.ENABLE_DMS]: { remove: DM_DISABLE_TAG, add: '' }, | |
[MOD_EVENTS.DISABLE_VIDEO_UPLOAD]: { | |
add: VIDEO_UPLOAD_DISABLE_TAG, | |
remove: '', | |
}, | |
[MOD_EVENTS.ENABLE_VIDEO_UPLOAD]: { | |
remove: VIDEO_UPLOAD_DISABLE_TAG, | |
add: '', | |
}, | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... agreed maps are better but not convinced we should be worried about this type of "abuse" in this context.
if (!queryParams.reportTypes) { | ||
queryParams.reportTypes = [] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I personnaly like using the following notation.
if (!queryParams.reportTypes) { | |
queryParams.reportTypes = [] | |
} | |
queryParams.reportTypes ||= [] |
if (queryParams.addedTags) { | ||
queryParams.addedTags.push(...add) | ||
} else { | ||
queryParams.addedTags = add | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the ||=
notation make things easier to read imo
if (queryParams.addedTags) { | |
queryParams.addedTags.push(...add) | |
} else { | |
queryParams.addedTags = add | |
} | |
queryParams.addedTags ||= [] | |
queryParams.addedTags.push(...add) |
This PR fixed event filters so that tag based events and appeal event filter work correctly. These are pseudo event types so there's no 1-to-1 mapping for these and the actual filter need to be built manually.