mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
refactor(explore): improve typing for Dnd controls (#16362)
This commit is contained in:
@@ -45,7 +45,7 @@ const datasource = {
|
||||
datasource_name: 'table1',
|
||||
description: 'desc',
|
||||
};
|
||||
const props = {
|
||||
const props: DatasourcePanelProps = {
|
||||
datasource,
|
||||
controls: {
|
||||
datasource: {
|
||||
@@ -57,12 +57,7 @@ const props = {
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setControlValue: () => ({
|
||||
type: 'type',
|
||||
controlName: 'control',
|
||||
value: 'val',
|
||||
validationErrors: [],
|
||||
}),
|
||||
setControlValue: jest.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -16,13 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import React, {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { ControlConfig, DatasourceMeta } from '@superset-ui/chart-controls';
|
||||
import { debounce } from 'lodash';
|
||||
import { matchSorter, rankings } from 'match-sorter';
|
||||
@@ -193,60 +187,61 @@ export default function DataSourcePanel({
|
||||
const DEFAULT_MAX_COLUMNS_LENGTH = 50;
|
||||
const DEFAULT_MAX_METRICS_LENGTH = 50;
|
||||
|
||||
const search = useCallback(
|
||||
debounce((value: string) => {
|
||||
if (value === '') {
|
||||
setList({ columns, metrics });
|
||||
return;
|
||||
}
|
||||
setList({
|
||||
columns: matchSorter(columns, value, {
|
||||
keys: [
|
||||
{
|
||||
key: 'verbose_name',
|
||||
threshold: rankings.CONTAINS,
|
||||
},
|
||||
{
|
||||
key: 'column_name',
|
||||
threshold: rankings.CONTAINS,
|
||||
},
|
||||
{
|
||||
key: item =>
|
||||
[item.description, item.expression].map(
|
||||
x => x?.replace(/[_\n\s]+/g, ' ') || '',
|
||||
),
|
||||
threshold: rankings.CONTAINS,
|
||||
maxRanking: rankings.CONTAINS,
|
||||
},
|
||||
],
|
||||
keepDiacritics: true,
|
||||
}),
|
||||
metrics: matchSorter(metrics, value, {
|
||||
keys: [
|
||||
{
|
||||
key: 'verbose_name',
|
||||
threshold: rankings.CONTAINS,
|
||||
},
|
||||
{
|
||||
key: 'metric_name',
|
||||
threshold: rankings.CONTAINS,
|
||||
},
|
||||
{
|
||||
key: item =>
|
||||
[item.description, item.expression].map(
|
||||
x => x?.replace(/[_\n\s]+/g, ' ') || '',
|
||||
),
|
||||
threshold: rankings.CONTAINS,
|
||||
maxRanking: rankings.CONTAINS,
|
||||
},
|
||||
],
|
||||
keepDiacritics: true,
|
||||
baseSort: (a, b) =>
|
||||
Number(b.item.is_certified) - Number(a.item.is_certified) ||
|
||||
String(a.rankedValue).localeCompare(b.rankedValue),
|
||||
}),
|
||||
});
|
||||
}, FAST_DEBOUNCE),
|
||||
const search = useMemo(
|
||||
() =>
|
||||
debounce((value: string) => {
|
||||
if (value === '') {
|
||||
setList({ columns, metrics });
|
||||
return;
|
||||
}
|
||||
setList({
|
||||
columns: matchSorter(columns, value, {
|
||||
keys: [
|
||||
{
|
||||
key: 'verbose_name',
|
||||
threshold: rankings.CONTAINS,
|
||||
},
|
||||
{
|
||||
key: 'column_name',
|
||||
threshold: rankings.CONTAINS,
|
||||
},
|
||||
{
|
||||
key: item =>
|
||||
[item.description, item.expression].map(
|
||||
x => x?.replace(/[_\n\s]+/g, ' ') || '',
|
||||
),
|
||||
threshold: rankings.CONTAINS,
|
||||
maxRanking: rankings.CONTAINS,
|
||||
},
|
||||
],
|
||||
keepDiacritics: true,
|
||||
}),
|
||||
metrics: matchSorter(metrics, value, {
|
||||
keys: [
|
||||
{
|
||||
key: 'verbose_name',
|
||||
threshold: rankings.CONTAINS,
|
||||
},
|
||||
{
|
||||
key: 'metric_name',
|
||||
threshold: rankings.CONTAINS,
|
||||
},
|
||||
{
|
||||
key: item =>
|
||||
[item.description, item.expression].map(
|
||||
x => x?.replace(/[_\n\s]+/g, ' ') || '',
|
||||
),
|
||||
threshold: rankings.CONTAINS,
|
||||
maxRanking: rankings.CONTAINS,
|
||||
},
|
||||
],
|
||||
keepDiacritics: true,
|
||||
baseSort: (a, b) =>
|
||||
Number(b.item.is_certified) - Number(a.item.is_certified) ||
|
||||
String(a.rankedValue).localeCompare(b.rankedValue),
|
||||
}),
|
||||
});
|
||||
}, FAST_DEBOUNCE),
|
||||
[columns, metrics],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user