refactor(explore): improve typing for Dnd controls#16362
Conversation
|
[HOLD] The UX for overriding single select MetricControl is quite confusing. While Drag & Drop, There is no clear indication that a control will only accept one metric. |
There was a problem hiding this comment.
Is there a reason why you changed the order here? According to https://dmitripavlutin.com/react-throttle-debounce/ useCallback should go first (although it seems that what we had here wasn't fully correct as we should wrap debounce function in useMemo...)
There was a problem hiding this comment.
ESLint react-hook plugin will complain not being able to detect exhaustive deps and suggests making the callback inline.
There was a problem hiding this comment.
I've just verified - simply replacing useCallback with useMemo solves the eslint problem
const search = useMemo(
() =>
debounce((value: string) => {
...
We indicate that a control accepts only 1 value by not displaying ghost button when a value is added. However, I do agree that we don't communicate clearly that dropping another value will replace the first one... |
|
thanks this is awesome! @ktmud do you mind splitting this pr into 2 one for improving typing one for logging? |
| datasourceType?: DatasourceType; | ||
| }; | ||
|
|
||
| export const DndMetricSelect = (props: any) => { |
There was a problem hiding this comment.
TODO: get rid of this any. Currently DndMetricSelectProps will conflict with too many things within this function. This file needs a bigger overhaul.
|
@kgabryje do you mind taking another look? |
Codecov Report
@@ Coverage Diff @@
## master #16362 +/- ##
==========================================
+ Coverage 76.64% 76.66% +0.01%
==========================================
Files 1000 1000
Lines 53486 53488 +2
Branches 6815 6816 +1
==========================================
+ Hits 40995 41004 +9
+ Misses 12255 12248 -7
Partials 236 236
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
| */ | ||
| import React, { ReactNode, useCallback, useState } from 'react'; | ||
| import { ControlType } from '@superset-ui/chart-controls'; | ||
| import { ControlComponentProps as BaseControlComponentProps } from '@superset-ui/chart-controls/lib/shared-controls/components/types'; |
There was a problem hiding this comment.
Non-blocking - should we export that from chart-controls in the next release of superset-ui, so that we can import from '@superset-ui/chart-controls'?
There was a problem hiding this comment.
Agreed. I'll do that the next time I touch superset-ui.
kgabryje
left a comment
There was a problem hiding this comment.
That's a HUGE improvement, thanks!
* upstream/master: (25 commits) chore(ci): bump pylint to 2.10.2 (apache#16463) fix: prevent page crash when chart can't render (apache#16464) chore: fixed slack invite link (apache#16466) fix(native-filters): handle null values in value filter (apache#16460) feat: add function list to auto-complete to Clickhouse datasource (apache#16234) refactor(explore): improve typing for Dnd controls (apache#16362) fix(explore): update overwrite button on perm change (apache#16437) feat: Draggable and Resizable Modal (apache#16394) refactor: sql_json view endpoint (apache#16441) fix(dashboard): undo and redo buttons weird alignment (apache#16417) fix: setupPlugin in chart list page (apache#16413) fix: Disable Slack notification method if no api token (apache#16367) feat: add Shillelagh DB engine spec (apache#16416) fix: copy to Clipboard order (apache#16299) docs: make FEATURE_FLAGS.md reference a link (apache#16415) chore(viz): bump superset-ui to 0.17.87 (apache#16420) feat: add activate command (apache#16404) Revert "fix(explore): let admin overwrite slice (apache#16290)" (apache#16408) fix(explore): retain chart ownership on query context update (apache#16419) chore: Removes the TODOs and uses the default page size (apache#16422) ...
| const newValue = props.multi ? [...value, newMetric] : [newMetric]; | ||
| const newValue = props.multi | ||
| ? [...value, newMetric.metric_name] | ||
| : [newMetric.metric_name]; |
There was a problem hiding this comment.
@ktmud I believe this introduced a bug with dragging columns into the metrics section and creating a SIMPLE expression for the column. When you drag a column into the metrics section the data looks like the data listed below and does not have a metric_name. This leads to an undefined option being returned and later errors:
aggregate: "COUNT_DISTINCT"
column: {column_name: "target"}
expressionType: "SIMPLE"
hasCustomLabel: false
isNew: false
label: "COUNT_DISTINCT(target)"
optionName: "metric_1vo4t2m2tjl_0nhrga77x9pf"
sqlExpression: null
There was a problem hiding this comment.
Got it. Thanks for the testing and pointing this out!
SUMMARY
Improve typing for Explore Dnd controls. Some principles:
ControlPropsto get a more complete shared props propagated from parent.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION