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

fix: update the auto-complete API reading logic #7254

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ahmadshaheer
Copy link
Collaborator

@ahmadshaheer ahmadshaheer commented Mar 10, 2025

Summary

Related Issues / PR's

Screenshots

NA

Affected Areas and Manually Tested Areas


Important

Updates auto-complete API logic by mapping data types to attribute values, affecting result processing in multiple files.

  • Behavior:
    • Introduces DATA_TYPE_VS_ATTRIBUTE_VALUES_KEY in queryBuilder.ts to map DataTypes to IAttributeValuesResponse keys.
    • Updates useFetchKeysAndValues in useFetchKeysAndValues.ts to use the new mapping for setting results based on data type.
    • Modifies useGetAllConfigOptions in useGetAllConfigOptions.ts to directly use stringAttributeValues.
    • Updates useGetAggregateValues in filterUtils.ts to use the new mapping for setting results based on data type.
  • Functions:
    • Adds isAttributeValuesResponse function in useFetchKeysAndValues.ts to check payload structure.
  • Misc:
    • Minor refactoring in useGetAllConfigOptions.ts and filterUtils.ts to align with new logic.

This description was created by Ellipsis for cc2fa31. It will automatically update as commits are pushed.

@ahmadshaheer ahmadshaheer requested a review from YounixM as a code owner March 10, 2025 12:43
@github-actions github-actions bot added the bug Something isn't working label Mar 10, 2025
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to 5770e9d in 2 minutes and 51 seconds

More details
  • Looked at 116 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 7 drafted comments based on config settings.
1. frontend/src/constants/queryBuilder.ts:422
  • Draft comment:
    Good use of a mapping constant. Ensure consistency by using design tokens if applicable.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
2. frontend/src/pages/MessagingQueues/MQGraph/useGetAllConfigOptions.ts:37
  • Draft comment:
    Consider using the DATA_TYPE_VS_ATTRIBUTE_VALUES_KEY mapping instead of Object.values to improve clarity and consistency.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
3. frontend/src/pages/TracesExplorer/Filter/filterUtils.ts:331
  • Draft comment:
    Good update using DATA_TYPE_VS_ATTRIBUTE_VALUES_KEY; ensure the cast on keyData.dataType is safe.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
4. frontend/src/hooks/queryBuilder/useFetchKeysAndValues.ts:240
  • Draft comment:
    The specific setResults call using DATA_TYPE_VS_ATTRIBUTE_VALUES_KEY is immediately overwritten by a generic setResults call. Use an else clause so the specialized results aren’t lost.
  • Reason this comment was not posted:
    Marked as duplicate.
5. frontend/src/pages/MessagingQueues/MQGraph/useGetAllConfigOptions.ts:37
  • Draft comment:
    Using a hardcoded 'stringAttributeValues' here; ensure this is intentional. For consistency, consider using the DATA_TYPE_VS_ATTRIBUTE_VALUES_KEY mapping if multiple data types are supported.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
6. frontend/src/pages/TracesExplorer/Filter/filterUtils.ts:332
  • Draft comment:
    Casting keyData.dataType as Partial may hide potential type issues if keyData.dataType is missing or unexpected. Ensure it’s always valid before using the mapping.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50%
    The comment suggests there could be type issues, but examining the code shows keyData.dataType is already strictly typed through the traceFilterKeys const object. The cast seems unnecessary but not harmful. The comment is speculative about potential issues rather than pointing out a concrete problem.
    I could be wrong about the type safety - there might be places where traceFilterKeys is modified at runtime. The DataTypes enum might be extended elsewhere.
    The traceFilterKeys is defined as a const object with explicit types, and TypeScript would catch any type mismatches at compile time. Runtime modifications would be caught by TypeScript's type system.
    The comment should be deleted as it's speculative about potential issues rather than identifying a concrete problem, and the existing type system already provides the safety being discussed.
7. frontend/src/pages/TracesExplorer/Filter/filterUtils.ts:346
  • Draft comment:
    Calling setFetching during render (in the if(!value) branch) is a side effect. Move this logic into a useEffect to avoid state updates during render.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_8cC8wXTKjrCW4fqV


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

const dataType = filterAttributeKey?.dataType ?? DataTypes.String;
const key = DATA_TYPE_VS_ATTRIBUTE_VALUES_KEY[dataType];
setResults(key ? payload[key] || [] : []);
}
const values = Object.values(payload).find((el) => !!el) || [];
setResults(values);
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate setResults call: the conditional branch sets results and then it's immediately overwritten. Consider using if/else to avoid overriding the value.

@srikanthccv srikanthccv self-requested a review March 10, 2025 12:50
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot 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 to me! Incremental review on cc2fa31 in 1 minute and 8 seconds

More details
  • Looked at 12 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. frontend/src/hooks/queryBuilder/useFetchKeysAndValues.ts:245
  • Draft comment:
    Adding the early return after setting results prevents the fallback logic from running. This ensures that when payload is recognized as an attribute value response, the state is updated only once.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50%
    This comment is purely informative, explaining the effect of an early return in the code. It doesn't suggest any changes or ask for confirmation of intent, which violates the rules.
2. frontend/src/hooks/queryBuilder/useFetchKeysAndValues.ts:245
  • Draft comment:
    Early return here prevents the fallback logic from running when the payload matches the expected IAttributeValuesResponse structure. Consider adding an inline comment to clarify why this early exit is necessary.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50%
    The early return's purpose is fairly clear from the context - it's part of a type-specific handling branch. The code is already well-structured with the isAttributeValuesResponse type guard. Adding a comment here would be stating the obvious. The logic flow is straightforward enough that a developer can understand it without additional documentation.
    I could be underestimating the complexity for future maintainers. Some developers might find the dual-path logic confusing without explicit documentation.
    The code structure itself documents the intent - there's a clear type check and type-specific handling followed by fallback logic. Additional comments would be redundant.
    This comment should be deleted as it requests documentation for something that is already clear from the code structure and context.

Workflow ID: wflow_brH6YuQzraJzH3Ev


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Comment on lines 247 to 248
const values = Object.values(payload).find((el) => !!el) || [];
setResults(values);
Copy link
Member

Choose a reason for hiding this comment

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

@ahmadshaheer we should get rid of this generic Object.values(payload) and handle it for different responses types (not just for IAttributeValuesResponse) by accessing the object keys instead.

@srikanthccv
Copy link
Member

srikanthccv commented Mar 11, 2025

@ahmadshaheer not handled here

({ payload }) => Object.values(payload || {}).find((el) => !!el) || [],

const attributeValues: string[] = useMemo(
() =>
((Object.values(data?.payload || {}).find((el) => !!el) ||
[]) as string[]).filter((val) => !isEmpty(val)),
[data?.payload],
);

Is there a better way to identify where IAttributeValuesResponse is used in codebase? I was trying with global search on Object.values(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants