Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
347e040
disable data selection from results table
MialLewis Jul 17, 2024
879ac45
disable selection from chart table
MialLewis Jul 17, 2024
bd8771d
disable pivot chart select
MialLewis Jul 17, 2024
e4b3960
add user select to permissions model
MialLewis Jul 22, 2024
1ddcb5f
change perms to can_export_csv
MialLewis Jul 22, 2024
9bd7c36
pass dataSelectionMode prop to plugin
MialLewis Jul 29, 2024
7396fd0
remove unneeded prop
MialLewis Jul 29, 2024
750ddd8
get permissions from role TableChart
MialLewis Jul 30, 2024
cf5bfc0
add user permissions to pivot table
MialLewis Jul 31, 2024
1a709ed
apply linter and fix compiler errors
MialLewis Jul 31, 2024
3b8a822
update permissions to inline with previous features
MialLewis Jul 31, 2024
783795b
apply unsaved changes
MialLewis Aug 2, 2024
e82967b
fix filterable table test
MialLewis Aug 2, 2024
8dadd6e
move access to redux state outside of filterable table comp
MialLewis Sep 9, 2024
15865af
move state query to DashboardBuilder
MialLewis Sep 9, 2024
b71fcd3
revert redundant changes to filt table test
MialLewis Sep 9, 2024
e52fe25
ammend transform props test
MialLewis Sep 9, 2024
c734c4c
remove unneeded import
MialLewis Sep 9, 2024
8920bcf
access state from explorechartpanel
MialLewis Sep 10, 2024
b101378
correct chart props
MialLewis Sep 10, 2024
1651a73
remove canExportData from DashboardBuilder and component, pass in fro…
MialLewis Sep 11, 2024
3aefbab
run prettier
MialLewis Sep 11, 2024
8e95100
remove unneeded test change
MialLewis Sep 11, 2024
8f3ac01
remove redundant filt table test var
MialLewis Sep 11, 2024
e7e8710
update buildQuery test with DataSelectionMode
MialLewis Sep 24, 2024
abe0518
correct import order
MialLewis Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export interface ChartPropsConfig {
inputRef?: RefObject<any>;
/** Theme object */
theme: SupersetTheme;
/** User able to export data */
canExportData?: string;
}

const DEFAULT_WIDTH = 800;
Expand Down Expand Up @@ -155,6 +157,8 @@ export default class ChartProps<FormData extends RawFormData = RawFormData> {

theme: SupersetTheme;

canExportData?: string;

constructor(config: ChartPropsConfig & { formData?: FormData } = {}) {
const {
annotationData = {},
Expand All @@ -176,6 +180,7 @@ export default class ChartProps<FormData extends RawFormData = RawFormData> {
inContextMenu = false,
emitCrossFilters = false,
theme,
canExportData,
} = config;
this.width = width;
this.height = height;
Expand All @@ -198,6 +203,7 @@ export default class ChartProps<FormData extends RawFormData = RawFormData> {
this.inContextMenu = inContextMenu;
this.emitCrossFilters = emitCrossFilters;
this.theme = theme;
this.canExportData = canExportData;
}
}

Expand All @@ -223,6 +229,7 @@ ChartProps.createSelector = function create(): ChartPropsSelector {
input => input.inContextMenu,
input => input.emitCrossFilters,
input => input.theme,
input => input.canExportData,
(
annotationData,
datasource,
Expand All @@ -243,6 +250,7 @@ ChartProps.createSelector = function create(): ChartPropsSelector {
inContextMenu,
emitCrossFilters,
theme,
canExportData,
) =>
new ChartProps({
annotationData,
Expand All @@ -264,6 +272,7 @@ ChartProps.createSelector = function create(): ChartPropsSelector {
inContextMenu,
emitCrossFilters,
theme,
canExportData,
}),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export default function PivotTableChart(props: PivotTableProps) {
onContextMenu,
timeGrainSqla,
allowRenderHtml,
dataSelectionMode,
} = props;

const theme = useTheme();
Expand Down Expand Up @@ -557,6 +558,7 @@ export default function PivotTableChart(props: PivotTableProps) {
namesMapping={verboseMap}
onContextMenu={handleContextMenu}
allowRenderHtml={allowRenderHtml}
dataSelectionMode={dataSelectionMode}
/>
</PivotTableWrapper>
</Styles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
filterState,
datasource: { verboseMap = {}, columnFormats = {}, currencyFormats = {} },
emitCrossFilters,
canExportData,
} = chartProps;
const { data, colnames, coltypes } = queriesData[0];
const {
Expand Down Expand Up @@ -176,5 +177,6 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
onContextMenu,
timeGrainSqla,
allowRenderHtml,
dataSelectionMode: canExportData ? 'auto' : 'none',
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { css, styled } from '@superset-ui/core';

export const Styles = styled.div`
${({ theme, isDashboardEditMode }) => css`
${({ theme, isDashboardEditMode, dataSelectionMode }) => css`
table.pvtTable {
position: ${isDashboardEditMode ? 'inherit' : 'relative'};
width: calc(100% - ${theme.gridUnit}px);
Expand All @@ -30,6 +30,7 @@ export const Styles = styled.div`
border-collapse: separate;
font-family: ${theme.typography.families.sansSerif};
line-height: 1.4;
user-select: ${dataSelectionMode};
}

table thead {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,10 @@ export class TableRenderer extends Component {
};

return (
<Styles isDashboardEditMode={this.isDashboardEditMode()}>
<Styles
isDashboardEditMode={this.isDashboardEditMode()}
dataSelectionMode={this.props.dataSelectionMode}
>
<table className="pvtTable" role="grid">
<thead>
{colAttrs.map((c, j) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ interface PivotTableCustomizeProps {
dateFormatters: Record<string, DateFormatter | undefined>;
legacy_order_by: QueryFormMetric[] | QueryFormMetric | null;
order_desc: boolean;
dataSelectionMode: string;
onContextMenu?: (
clientX: number,
clientY: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const formData: PivotTableQueryFormData = {
time_grain_sqla: TimeGranularity.MONTH,
temporal_columns_lookup: { col1: true },
currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' },
dataSelectionMode: 'auto',
};

test('should build groupby with series in form data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('PivotTableChart transformProps', () => {
columnFormats: {},
currencyFormats: {},
currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' },
dataSelectionMode: 'none',
});
});
});
3 changes: 3 additions & 0 deletions superset-frontend/plugins/plugin-chart-table/src/Styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,8 @@ export default styled.div`
table .right-border-only:last-child {
border-right: none;
}
.no-select {
user-select: none;
}
`}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export default function TableChart<D extends DataRecord = DataRecord>(
isUsingTimeComparison,
basicColorFormatters,
basicColorColumnFormatters,
dataSelectionMode,
} = props;
const comparisonColumns = [
{ key: 'all', label: t('Display all') },
Expand Down Expand Up @@ -736,6 +737,10 @@ export default function TableChart<D extends DataRecord = DataRecord>(
}
}

if (dataSelectionMode === 'none') {
className += ' no-select';
}

return {
id: String(i), // to allow duplicate column keys
// must use custom accessor to allow `.` in column names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ const transformProps = (
onContextMenu,
},
emitCrossFilters,
canExportData,
} = chartProps;

const {
Expand Down Expand Up @@ -706,6 +707,7 @@ const transformProps = (
basicColorFormatters,
startDateOffset,
basicColorColumnFormatters,
dataSelectionMode: canExportData ? 'auto' : 'none',
};
};

Expand Down
1 change: 1 addition & 0 deletions superset-frontend/plugins/plugin-chart-table/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export interface TableChartTransformedProps<D extends DataRecord = DataRecord> {
basicColorFormatters?: { [Key: string]: BasicColorFormatterType }[];
basicColorColumnFormatters?: { [Key: string]: BasicColorFormatterType }[];
startDateOffset?: string;
dataSelectionMode: string;
}

export enum ColorSchemeEnum {
Expand Down
10 changes: 3 additions & 7 deletions superset-frontend/src/SqlLab/components/ResultSet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ const ResultSet = ({
setSearchText(event.target.value);
};

const canExportData = findPermission('can_export_csv', 'SQLLab', user?.roles);

const createExploreResultsOnClick = async (clickEvent: MouseEvent) => {
const { results } = query;

Expand Down Expand Up @@ -309,13 +311,6 @@ const ResultSet = ({
templateParams: query?.templateParams,
schema: query?.schema,
};

const canExportData = findPermission(
'can_export_csv',
'SQLLab',
user?.roles,
);

return (
<ResultSetControls>
<SaveDatasetModal
Expand Down Expand Up @@ -668,6 +663,7 @@ const ResultSet = ({
filterText={searchText}
expandedColumns={expandedColumns}
allowHTML={allowHTML}
disableTextSelection={canExportData}
/>
</ResultContainer>
);
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/components/Chart/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const propTypes = {
datasetsStatus: PropTypes.oneOf(['loading', 'error', 'complete']),
isInView: PropTypes.bool,
emitCrossFilters: PropTypes.bool,
canExportData: PropTypes.bool,
};

const BLANK = {};
Expand Down Expand Up @@ -271,6 +272,7 @@ class Chart extends PureComponent {
{...this.props}
source={this.props.dashboardId ? 'dashboard' : 'explore'}
data-test={this.props.vizType}
canExportData={this.props.canExportData}
/>
) : (
<Loading />
Expand Down
4 changes: 3 additions & 1 deletion superset-frontend/src/components/Chart/ChartRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const propTypes = {
setControlValue: PropTypes.func,
vizType: PropTypes.string.isRequired,
triggerRender: PropTypes.bool,
// state
chartAlert: PropTypes.string,
chartStatus: PropTypes.string,
queriesResponse: PropTypes.arrayOf(PropTypes.object),
Expand All @@ -63,6 +62,7 @@ const propTypes = {
postTransformProps: PropTypes.func,
source: PropTypes.oneOf([ChartSource.Dashboard, ChartSource.Explore]),
emitCrossFilters: PropTypes.bool,
canExportData: PropTypes.bool,
};

const BLANK = {};
Expand Down Expand Up @@ -264,6 +264,7 @@ class ChartRenderer extends Component {
formData,
latestQueryFormData,
postTransformProps,
canExportData,
} = this.props;

const currentFormData =
Expand Down Expand Up @@ -362,6 +363,7 @@ class ChartRenderer extends Component {
postTransformProps={postTransformProps}
emitCrossFilters={emitCrossFilters}
legendState={this.state.legendState}
canExportData={canExportData}
{...drillToDetailProps}
/>
</div>
Expand Down
12 changes: 10 additions & 2 deletions superset-frontend/src/components/FilterableTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ const SCROLL_BAR_HEIGHT = 15;
// See https://stackoverflow.com/a/30987109 for more details
const ONLY_NUMBER_REGEX = /^(NaN|-?((\d*\.\d+|\d+)([Ee][+-]?\d+)?|Infinity))$/;

const StyledFilterableTable = styled.div`
${({ theme }) => `
interface StyledFilterableTableProps {
disableTextSelection?: boolean;
}

const StyledFilterableTable = styled.div<StyledFilterableTableProps>`
${({ theme, disableTextSelection }) => `
height: 100%;
overflow: hidden;

Expand All @@ -50,6 +54,7 @@ const StyledFilterableTable = styled.div`
min-width: 0px;
align-self: center;
font-size: ${theme.typography.sizes.s}px;
user-select: ${disableTextSelection ? 'auto' : 'none'};
}

.even-row {
Expand Down Expand Up @@ -83,6 +88,7 @@ export interface FilterableTableProps {
striped?: boolean;
expandedColumns?: string[];
allowHTML?: boolean;
disableTextSelection?: boolean;
}

const FilterableTable = ({
Expand All @@ -92,6 +98,7 @@ const FilterableTable = ({
filterText = '',
expandedColumns = [],
allowHTML = true,
disableTextSelection,
}: FilterableTableProps) => {
const formatTableData = (data: Record<string, unknown>[]): Datum[] =>
data.map(row => {
Expand Down Expand Up @@ -254,6 +261,7 @@ const FilterableTable = ({
className="filterable-table-container"
data-test="table-container"
ref={container}
disableTextSelection={disableTextSelection}
>
{fitted && (
<Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ class Chart extends Component {
datasetsStatus={datasetsStatus}
isInView={isInView}
emitCrossFilters={emitCrossFilters}
canExportData={supersetCanCSV}
/>
</ChartWrapper>
</SliceContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import { useState, useEffect, useCallback, useMemo } from 'react';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import Split from 'react-split';
import {
Expand All @@ -43,6 +44,7 @@ import { SaveDatasetModal } from 'src/SqlLab/components/SaveDatasetModal';
import { getDatasourceAsSaveableDataset } from 'src/utils/datasourceUtils';
import { buildV1ChartDataPayload } from 'src/explore/exploreUtils';
import { getChartRequiredFieldsMissingMessage } from 'src/utils/getChartRequiredFieldsMissingMessage';
import { findPermission } from 'src/utils/findPermission';
import { DataTablesPane } from '../DataTablesPane';
import { ChartPills } from '../ChartPills';
import { ExploreAlert } from '../ExploreAlert';
Expand Down Expand Up @@ -71,6 +73,7 @@ const propTypes = {
chart: chartPropShape,
errorMessage: PropTypes.node,
triggerRender: PropTypes.bool,
canExportData: PropTypes.bool,
};

const GUTTER_SIZE_FACTOR = 1.25;
Expand Down Expand Up @@ -237,6 +240,10 @@ const ExploreChartPanel = ({
setShowSplit(isOpen);
}, []);

const canExportData = useSelector(state =>
findPermission('can_csv', 'Superset', state.user?.roles),
);

const renderChart = useCallback(
() => (
<div
Expand Down Expand Up @@ -270,6 +277,7 @@ const ExploreChartPanel = ({
timeout={timeout}
triggerQuery={chart.triggerQuery}
vizType={vizType}
canExportData={canExportData}
/>
)}
</div>
Expand Down
Loading