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

[D&D] Persists index field on agg type change if possible #2227

Merged
merged 2 commits into from
Sep 6, 2022

Conversation

ashwin-pc
Copy link
Member

@ashwin-pc ashwin-pc commented Aug 31, 2022

Signed-off-by: Ashwin Pc [email protected]

Description

[Describe what this change achieves]

Issues Resolved

#2221

Check List

  • New functionality includes testing.
    • All tests pass
      • yarn test:jest
      • yarn test:jest_integration
      • yarn test:ftr
  • New functionality has been documented.
  • Commits are signed per the DCO using --signoff

@ashwin-pc ashwin-pc self-assigned this Aug 31, 2022
@ashwin-pc ashwin-pc requested a review from a team as a code owner August 31, 2022 00:14
@codecov-commenter
Copy link

codecov-commenter commented Aug 31, 2022

Codecov Report

Merging #2227 (38e7c2c) into main (428e832) will decrease coverage by 0.00%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main    #2227      +/-   ##
==========================================
- Coverage   66.78%   66.77%   -0.01%     
==========================================
  Files        3133     3133              
  Lines       60079    60086       +7     
  Branches     9153     9155       +2     
==========================================
  Hits        40121    40121              
- Misses      17767    17774       +7     
  Partials     2191     2191              
Impacted Files Coverage Δ
...pplication/components/data_tab/secondary_panel.tsx 2.56% <0.00%> (-0.57%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

joshuarrrr
joshuarrrr previously approved these changes Aug 31, 2022
Copy link
Member

@joshuarrrr joshuarrrr left a comment

Choose a reason for hiding this comment

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

Thanks, I'm excited to have this fix! I didn't pull this down to validate that it works, but I'll trust that it does.

My only concern is that it seems like we'd prefer to solve some of the type issues at the root rather than casting, but I understand the pragmatic approach for now.

@@ -4,15 +4,15 @@
*/

import React, { useCallback, useMemo, useState } from 'react';
import { cloneDeep } from 'lodash';
import { cloneDeep, get } from 'lodash';
Copy link
Member

Choose a reason for hiding this comment

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

boo to lodash methods 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

I blame typescript. I gave into this after fighting with typescript to get the same behavior for this:

const indexField = availableFields.find(
  ({ name }) => name === get(draftAgg, 'params.field')
);

@@ -109,6 +109,20 @@ export function SecondaryPanel() {
}}
onAggTypeChange={function (aggId: string, aggType: IAggType): void {
aggConfig.type = aggType;

// Persist field if the new agg type supports the existing field
const fieldParam = (aggType.params as AggParam[]).find(({ type }) => type === 'field');
Copy link
Member

Choose a reason for hiding this comment

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

do we need the cast because the agg service doesn't give us suitable types?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll be honest, that service has some seriously confusing typing going on that seems to confuse typescript a lot. Here the issue was that the line below where i try to getAvailableFields has a type error that only goes away when I cast these types. And these are valid types for those objects. Its just the unions and the parent child relationships between these types that is confusing the typescript compiler

@ashwin-pc
Copy link
Member Author

I agree. The only reason i chose to do it this way was because I didnt want to modify the behavior of the underlying component because it was shared with the Visualize app too. Since we'll likely change this entire component to be more user friendly, I wanted to limit the blast radius for this fix.

Copy link
Member

@ananzh ananzh left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@joshuarrrr joshuarrrr left a comment

Choose a reason for hiding this comment

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

shipit

@joshuarrrr joshuarrrr merged commit 4a06f5a into opensearch-project:main Sep 6, 2022
opensearch-trigger-bot bot pushed a commit that referenced this pull request Sep 6, 2022
Signed-off-by: Ashwin Pc <[email protected]>
(cherry picked from commit 4a06f5a)
ashwin-pc added a commit that referenced this pull request Sep 7, 2022
Signed-off-by: Ashwin Pc <[email protected]>
(cherry picked from commit 4a06f5a)

Co-authored-by: Ashwin P Chandran <[email protected]>
sipopo pushed a commit to sipopo/OpenSearch-Dashboards that referenced this pull request Sep 14, 2022
sipopo pushed a commit to sipopo/OpenSearch-Dashboards that referenced this pull request Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants