mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
fix(dashboard): Allow selecting text in cells in Table and PivotTable without triggering cross filters (#23283)
This commit is contained in:
parent
1b139d0748
commit
d16512b775
@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
export const getSelectedText = () => window.getSelection()?.toString();
|
@ -27,6 +27,7 @@ export { default as promiseTimeout } from './promiseTimeout';
|
|||||||
export { default as logging } from './logging';
|
export { default as logging } from './logging';
|
||||||
export { default as removeDuplicates } from './removeDuplicates';
|
export { default as removeDuplicates } from './removeDuplicates';
|
||||||
export { lruCache } from './lruCache';
|
export { lruCache } from './lruCache';
|
||||||
|
export { getSelectedText } from './getSelectedText';
|
||||||
export * from './featureFlags';
|
export * from './featureFlags';
|
||||||
export * from './random';
|
export * from './random';
|
||||||
export * from './typedMemo';
|
export * from './typedMemo';
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
import { getSelectedText } from '@superset-ui/core';
|
||||||
|
|
||||||
|
test('Returns null if Selection object is null', () => {
|
||||||
|
jest.spyOn(window, 'getSelection').mockImplementationOnce(() => null);
|
||||||
|
expect(getSelectedText()).toEqual(undefined);
|
||||||
|
jest.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Returns selection text if Selection object is not null', () => {
|
||||||
|
jest
|
||||||
|
.spyOn(window, 'getSelection')
|
||||||
|
// @ts-ignore
|
||||||
|
.mockImplementationOnce(() => ({ toString: () => 'test string' }));
|
||||||
|
expect(getSelectedText()).toEqual('test string');
|
||||||
|
jest.restoreAllMocks();
|
||||||
|
});
|
@ -30,6 +30,7 @@ import {
|
|||||||
isAdhocColumn,
|
isAdhocColumn,
|
||||||
BinaryQueryObjectFilterClause,
|
BinaryQueryObjectFilterClause,
|
||||||
t,
|
t,
|
||||||
|
getSelectedText,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { PivotTable, sortAs, aggregatorTemplates } from './react-pivottable';
|
import { PivotTable, sortAs, aggregatorTemplates } from './react-pivottable';
|
||||||
import {
|
import {
|
||||||
@ -356,6 +357,11 @@ export default function PivotTableChart(props: PivotTableProps) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// allow selecting text in a cell
|
||||||
|
if (getSelectedText()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const isActiveFilterValue = (key: string, val: DataRecordValue) =>
|
const isActiveFilterValue = (key: string, val: DataRecordValue) =>
|
||||||
!!selectedFilters && selectedFilters[key]?.includes(val);
|
!!selectedFilters && selectedFilters[key]?.includes(val);
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ import {
|
|||||||
DTTM_ALIAS,
|
DTTM_ALIAS,
|
||||||
ensureIsArray,
|
ensureIsArray,
|
||||||
GenericDataType,
|
GenericDataType,
|
||||||
|
getSelectedText,
|
||||||
getTimeFormatterForGranularity,
|
getTimeFormatterForGranularity,
|
||||||
BinaryQueryObjectFilterClause,
|
BinaryQueryObjectFilterClause,
|
||||||
styled,
|
styled,
|
||||||
@ -493,7 +494,12 @@ export default function TableChart<D extends DataRecord = DataRecord>(
|
|||||||
title: typeof value === 'number' ? String(value) : undefined,
|
title: typeof value === 'number' ? String(value) : undefined,
|
||||||
onClick:
|
onClick:
|
||||||
emitCrossFilters && !valueRange && !isMetric
|
emitCrossFilters && !valueRange && !isMetric
|
||||||
? () => toggleFilter(key, value)
|
? () => {
|
||||||
|
// allow selecting text in a cell
|
||||||
|
if (!getSelectedText()) {
|
||||||
|
toggleFilter(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
onContextMenu: (e: MouseEvent) => {
|
onContextMenu: (e: MouseEvent) => {
|
||||||
if (handleContextMenu) {
|
if (handleContextMenu) {
|
||||||
|
Loading…
Reference in New Issue
Block a user