Skip to content
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

Merged
merged 3 commits into from
Nov 22, 2024
Merged

Conversation

foysalit
Copy link
Contributor

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.

@arcalinea arcalinea temporarily deployed to fix-appeal-filter - ozone-staging PR #245 November 21, 2024 12:38 — with Render Destroyed
@@ -10,7 +10,7 @@ const EMPTY_ARR = []
export const LabelSelector = (props: LabelsProps) => {
const {
id,
formId,
form,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just cleaning these up.

Copy link
Contributor

@matthieusieben matthieusieben left a 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. 👍

Comment on lines 376 to 389
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)
}
}
})
Copy link
Contributor

@matthieusieben matthieusieben Nov 22, 2024

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:

Suggested change
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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice thanks!

Comment on lines +358 to +369
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: '',
},
}
Copy link
Contributor

@matthieusieben matthieusieben Nov 22, 2024

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):

Suggested change
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: '',
},
}

Copy link
Contributor Author

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.

Comment on lines 231 to 233
if (!queryParams.reportTypes) {
queryParams.reportTypes = []
}
Copy link
Contributor

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.

Suggested change
if (!queryParams.reportTypes) {
queryParams.reportTypes = []
}
queryParams.reportTypes ||= []

Comment on lines +242 to +246
if (queryParams.addedTags) {
queryParams.addedTags.push(...add)
} else {
queryParams.addedTags = add
}
Copy link
Contributor

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

Suggested change
if (queryParams.addedTags) {
queryParams.addedTags.push(...add)
} else {
queryParams.addedTags = add
}
queryParams.addedTags ||= []
queryParams.addedTags.push(...add)

@matthieusieben
Copy link
Contributor

There seems to be an issue here https://github.com/bluesky-social/ozone/pull/245/files/c097b03a05ffabc6531e0dc252d9ca8ae5d60fe0#file-app-actions-modactionpanel-quickaction-tsx-L667

@arcalinea arcalinea temporarily deployed to fix-appeal-filter - ozone-staging PR #245 November 22, 2024 12:10 — with Render Destroyed
@foysalit foysalit merged commit c419db8 into main Nov 22, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants