Skip to content

Conversation

abdimo101
Copy link
Member

@abdimo101 abdimo101 commented Aug 1, 2025

Description

This PR implements limited units in the unit dropdown within the condition panel when unit options are provided in frontend-config.json.
Ex.
unitsoptions

Motivation

Some users that provide pre-configured conditions want to only show the units they provided, instead of displaying all available units.

Fixes:

Please provide a list of the fixes implemented in this PR

  • Items added

Changes:

Please provide a list of the changes implemented by this PR

  • changes made

Tests included

  • Included for each change/fix?
  • Passing? (Merge will not be approved unless this is checked)

Documentation

  • swagger documentation updated [required]
  • official documentation updated [nice-to-have]

official documentation info

If you have updated the official documentation, please provide PR # and URL of the pages where the updates are included

Backend version

  • Does it require a specific version of the backend
  • which version of the backend is required:

Summary by Sourcery

Allow datasets filter conditions to restrict available unit options based on pre-configured settings.

New Features:

  • Support specifying a unitsOptions array in pre-configured conditions to limit dropdown choices
  • Introduce UnitsOptionsService to persist and retrieve unit options per parameter

Enhancements:

  • Extend ScientificCondition model with optional unitsOptions field
  • Update SearchParametersDialogComponent to apply configured unit options when opening the dialog
  • Add data-cy attributes to condition dialog elements for reliable end-to-end testing

Tests:

  • Add Cypress e2e test to verify that the units dropdown displays only the configured unit options

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @abdimo101 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/app/shared/modules/search-parameters-dialog/search-parameters-dialog.component.ts:86` </location>
<code_context>
+    const unitsOptions = this.data.condition?.unitsOptions;
+
+    // if pre-configured condition has unitsOptions, store and use them.
+    if (lhs && unitsOptions?.length) {
+      this.unitsOptionsService.setUnitsOptions(lhs, unitsOptions);
+      this.units = unitsOptions;
</code_context>

<issue_to_address>
unitsOptions may contain duplicates; consider deduplication.

If duplicates are unnecessary, deduplicate unitsOptions before storing or displaying.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    if (lhs && unitsOptions?.length) {
      this.unitsOptionsService.setUnitsOptions(lhs, unitsOptions);
      this.units = unitsOptions;
=======
    if (lhs && unitsOptions?.length) {
      const dedupedUnitsOptions = Array.from(new Set(unitsOptions));
      this.unitsOptionsService.setUnitsOptions(lhs, dedupedUnitsOptions);
      this.units = dedupedUnitsOptions;
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `src/app/shared/modules/search-parameters-dialog/search-parameters-dialog.component.ts:98` </location>
<code_context>
   getUnits = (parameterKey: string): void => {
-    this.units = this.unitsService.getUnits(parameterKey);
+    const stored = this.unitsOptionsService.getUnitsOptions(parameterKey);
+    if (stored?.length) {
+      this.units = stored;
+    } else if (this.data.condition?.unitsOptions?.length) {
</code_context>

<issue_to_address>
getUnits may return undefined; ensure downstream code handles this.

If both stored and data.condition.unitsOptions are missing, this.units could be undefined. Make sure this.units is always set to an array to prevent template errors.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@abdimo101 abdimo101 requested a review from yoganandaness August 1, 2025 12:02
@Junjiequan Junjiequan requested a review from nitrosx August 1, 2025 12:36
@yoganandaness yoganandaness requested review from martin-trajanovski and removed request for nitrosx August 21, 2025 08:06
Copy link
Collaborator

@martin-trajanovski martin-trajanovski left a comment

Choose a reason for hiding this comment

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

There are some AI review comments already that might be worth checking. But other than that I don't have anything more. It looks fine.

@abdimo101 abdimo101 merged commit b3b73f7 into master Aug 21, 2025
8 checks passed
@abdimo101 abdimo101 deleted the units-options-dropdown branch August 21, 2025 10:40
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