Compare commits

...

2 Commits

Author SHA1 Message Date
Ville Brofeldt
7d35a91642 fix(dnd): make clicked dnd metrics unique (#16632)
(cherry picked from commit 9dfa33fedf)
2021-09-10 16:31:04 -07:00
Elizabeth Thompson
cc821bb747 fix: params in sql lab are jumpy in the ace editor (#16536)
* fix jumpy params

* remove cypress tests

(cherry picked from commit 519baa6f00)
2021-09-10 16:30:33 -07:00
4 changed files with 34 additions and 25 deletions

View File

@@ -613,7 +613,7 @@ describe('async actions', () => {
describe('queryEditorSetSql', () => {
describe('with backend persistence flag on', () => {
it('does not update the tab state in the backend', () => {
it('updates the tab state in the backend', () => {
expect.assertions(2);
const sql = 'SELECT * ';
@@ -629,7 +629,7 @@ describe('async actions', () => {
});
});
describe('with backend persistence flag off', () => {
it('updates the tab state in the backend', () => {
it('does not update the tab state in the backend', () => {
const backendPersistenceOffMock = jest
.spyOn(featureFlags, 'isFeatureEnabled')
.mockImplementation(

View File

@@ -949,6 +949,11 @@ export function queryEditorSetQueryLimit(queryEditor, queryLimit) {
export function queryEditorSetTemplateParams(queryEditor, templateParams) {
return function (dispatch) {
dispatch({
type: QUERY_EDITOR_SET_TEMPLATE_PARAMS,
queryEditor,
templateParams,
});
const sync = isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)
? SupersetClient.put({
endpoint: encodeURI(`/tabstateview/${queryEditor.id}`),
@@ -956,24 +961,16 @@ export function queryEditorSetTemplateParams(queryEditor, templateParams) {
})
: Promise.resolve();
return sync
.then(() =>
dispatch({
type: QUERY_EDITOR_SET_TEMPLATE_PARAMS,
queryEditor,
templateParams,
}),
)
.catch(() =>
dispatch(
addDangerToast(
t(
'An error occurred while setting the tab template parameters. ' +
'Please contact your administrator.',
),
return sync.catch(() =>
dispatch(
addDangerToast(
t(
'An error occurred while setting the tab template parameters. ' +
'Please contact your administrator.',
),
),
);
),
);
};
}

View File

@@ -25,3 +25,9 @@ export interface DatasourcePanelDndItem {
value: DndItemValue;
type: DndItemType;
}
export function isDatasourcePanelDndItem(
item: any,
): item is DatasourcePanelDndItem {
return item?.value && item?.type;
}

View File

@@ -34,7 +34,10 @@ import { usePrevious } from 'src/common/hooks/usePrevious';
import AdhocMetric from 'src/explore/components/controls/MetricControl/AdhocMetric';
import AdhocMetricPopoverTrigger from 'src/explore/components/controls/MetricControl/AdhocMetricPopoverTrigger';
import MetricDefinitionValue from 'src/explore/components/controls/MetricControl/MetricDefinitionValue';
import { DatasourcePanelDndItem } from 'src/explore/components/DatasourcePanel/types';
import {
DatasourcePanelDndItem,
isDatasourcePanelDndItem,
} from 'src/explore/components/DatasourcePanel/types';
import { DndItemType } from 'src/explore/components/DndItemType';
import DndSelectLabel from 'src/explore/components/controls/DndColumnSelectControl/DndSelectLabel';
import { savedMetricType } from 'src/explore/components/controls/MetricControl/types';
@@ -143,9 +146,9 @@ export const DndMetricSelect = (props: any) => {
const [value, setValue] = useState<ValueType[]>(
coerceAdhocMetrics(props.value),
);
const [droppedItem, setDroppedItem] = useState<DatasourcePanelDndItem | null>(
null,
);
const [droppedItem, setDroppedItem] = useState<
DatasourcePanelDndItem | typeof EMPTY_OBJECT
>({});
const [newMetricPopoverVisible, setNewMetricPopoverVisible] = useState(false);
const prevColumns = usePrevious(columns);
const prevSavedMetrics = usePrevious(savedMetrics);
@@ -323,13 +326,16 @@ export const DndMetricSelect = (props: any) => {
);
const handleClickGhostButton = useCallback(() => {
setDroppedItem(null);
setDroppedItem({});
togglePopover(true);
}, [togglePopover]);
const adhocMetric = useMemo(() => {
if (droppedItem?.type === DndItemType.Column) {
const itemValue = droppedItem?.value as ColumnMeta;
if (
isDatasourcePanelDndItem(droppedItem) &&
droppedItem.type === DndItemType.Column
) {
const itemValue = droppedItem.value as ColumnMeta;
const config: Partial<AdhocMetric> = {
column: { column_name: itemValue?.column_name },
};