Skip to content

Feeds filters controlled by Formik state. Closes #889#894

Merged
regulartim merged 4 commits intoGreedyBear-Project:developfrom
UsamaElareeny:fix-feeds
Mar 2, 2026
Merged

Feeds filters controlled by Formik state. Closes #889#894
regulartim merged 4 commits intoGreedyBear-Project:developfrom
UsamaElareeny:fix-feeds

Conversation

@UsamaElareeny
Copy link
Copy Markdown
Contributor

Description

This PR fixes the Feeds filters not being properly controlled by Formik state. Previously, I noticed that the <Select> components relied on a mutable module-level initialValues object. This caused inconsistencies between the UI and formik.values, and introduced shared mutable state across renders.

To summarize, in this PR:

  • I replaced the mutable initialValues with an immutable default values object
  • I made all <Select> components controlled via formik.values
  • I removed shared mutable state
  • I updated sorting logic to rely on local state instead of mutating values

The filters are now fully synchronized with Formik state and behave consistently.

Related issues

Closes #889

Type of change

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).
  • Chore (refactoring, dependency updates, CI/CD changes, code cleanup, docs-only changes).

Checklist

Formalities

  • I have read and understood the rules about how to Contribute to this project.
  • I chose an appropriate title for the pull request in the form: <feature name>. Closes #999
  • My branch is based on develop.
  • The pull request is for the branch develop.
  • I have reviewed and verified any LLM-generated code included in this PR.

Docs and tests

  • I documented my code changes with docstrings and/or comments.
  • I have checked if my changes affect user-facing behavior that is described in the docs. If so, I also created a pull request in the docs repository.
  • Linter (Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.
  • I have added tests for the feature/bug I solved.
  • All the tests gave 0 errors.

Note for reviewers: This PR fixes internal state handling for the Feeds filters. There are no changes to the user interface or visible behavior. All changes made are internal to ensure Formik values and UI are fully synchronized.

Copilot AI review requested due to automatic review settings February 26, 2026 20:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Feeds filter <Select> controls so they no longer rely on a mutable module-level initialValues, and instead stay synchronized with component/Formik state (issue #889).

Changes:

  • Replaced mutable initialValues with immutable DEFAULT_VALUES and introduced local filters state.
  • Updated Feeds filter <Select> values to be controlled via formik.values.
  • Expanded/adjusted Feeds component tests to assert controlled select values and ordering/prioritize interactions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
frontend/src/components/feeds/Feeds.jsx Reworks filter state management and wiring of <Select> controls to avoid shared mutable state.
frontend/tests/components/feeds/Feeds.test.jsx Adds assertions and a new test to validate controlled filter behavior and ordering/prioritize interaction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/src/components/feeds/Feeds.jsx Outdated
Comment thread frontend/src/components/feeds/Feeds.jsx Outdated
Comment thread frontend/src/components/feeds/Feeds.jsx Outdated
Comment thread frontend/src/components/feeds/Feeds.jsx Outdated
Comment thread frontend/src/components/feeds/Feeds.jsx Outdated
Comment thread frontend/src/components/feeds/Feeds.jsx Outdated
Copy link
Copy Markdown
Collaborator

@regulartim regulartim left a comment

Choose a reason for hiding this comment

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

Hey @UsamaElareeny ! Could you please react to copilot's suggestions? There not always helpful, I know, but I think it has at least one good point here: on some occasions you just bypass Formik. I think we should either use Formik as source of truth or remove it entirely. What do you think?

@UsamaElareeny
Copy link
Copy Markdown
Contributor Author

@regulartim Thanks for pointing this out! Yes, your're aboslutely right.

I decided to go with this change though because it combine the filters state with Formik, so I'd be able to to update the state all the over the file programmatically, for example, at handleSortChange() to set prioritize to "recent", and also to pass its values to outside components like FeedTable, and no need to worries about value mismatching thanks to enableRenitialize prop in Formik which keeps the Formik and state in sync. Reason I went with that as it introduces the most minimal change.

However, I agree it's bit of a hybrid and mixing two sources. I would ref the Formik form as the single source of truth and removing filters state. I guess this way would keep Formik in full control while still allowing some programmatic updates.

I'll work on it right away and push shortly.

@UsamaElareeny
Copy link
Copy Markdown
Contributor Author

Hi @regulartim, I refactored the component so that Formik is now the single source of truth.

  • Removed the separate filters state
  • All Select components now update via setFieldValue + submitForm
  • Programmatically editing prioritize to "recent" now uses Formik ref

The two versions are good, but this should address the concern about bypassing Formik.

Could you please take another look and tell me if there is something else I need to do?

Thanks!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/src/components/feeds/Feeds.jsx Outdated
Comment thread frontend/src/components/feeds/Feeds.jsx
Comment thread frontend/src/components/feeds/Feeds.jsx
Comment thread frontend/src/components/feeds/Feeds.jsx Outdated
Comment on lines +106 to +109
// I batched url, tableParams, and tableKey into a single state object so that
// all three update atomically in one render cycle. Previously, having
// them as separate state variables caused multiple redundent api request before
// the state fully settled
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's fine, but please remove that comment. It does not belong in the code IMO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, I’ll remove it. I grouped the state variables to avoid the previous redundant API requests, but I agree the explanation doesn’t need to stay in the code.

Comment on lines +152 to +169
// callbacks
const onSubmit = React.useCallback((values) => {
try {
setFeedsState((prev) => ({
url: `${FEEDS_BASE_URI}/${values.feeds_type}/${values.attack_type}/${values.prioritize}.json?ioc_type=${values.ioc_type}`,
tableParams: {
feed_type: values.feeds_type,
attack_type: values.attack_type,
ioc_type: values.ioc_type,
prioritize: values.prioritize,
},

// force remount FeedsTable
setTableKey((prev) => prev + 1);
} catch (e) {
console.debug(e);
}
},
[setUrl, navigate],
);
tableKey: prev.tableKey + 1,
}));
} catch (e) {
console.debug(e);
}
}, []);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You removed navigate({ search: "" }, { replace: true }); . Isn't that necessary to do what the comment says? Clear ordering and query params? (Just a question)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@regulartim Thanks for taking the time to review. I strongly believe it's better this way since the user can remove the filters as he wants without programmatically removing it for him. Additionally, it keeps applying the filters, while enabling the user to change select values. Also helps with keeping formik as the single source of truth by not interfering in its re-render cycle.

Copy link
Copy Markdown
Collaborator

@regulartim regulartim 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! Thanks for your work! 👍

@regulartim regulartim merged commit ef8421c into GreedyBear-Project:develop Mar 2, 2026
5 checks passed
cclts pushed a commit to cclts/GreedyBear that referenced this pull request Mar 11, 2026
… (GreedyBear-Project#894)

* Fix: Feeds Select controlled by Formik values

* test: add coverage for Formik-controlled Feeds filters

* refactor: made Formik the single source of truth instead of filters/Formik

* review: remove unnecessary explanatory comment
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