Skip to content

Commit

Permalink
feat: Tabs in column (apache#16593)
Browse files Browse the repository at this point in the history
* fix:fix get permission function

* feat: add tabs inside column

* lint: fix lint

* test: fix test

* test: fix tests

* test: fix tests

* fix: pass onChangeTab function through layout
  • Loading branch information
simcha90 authored and Emmanuel Bavoux committed Nov 14, 2021
1 parent d2adaa7 commit cc9c821
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe('isValidChild', () => {
[ROOT, TABS, TAB, ROW, COLUMN, ROW, COLUMN, CHART],
[ROOT, TABS, TAB, ROW, COLUMN, ROW, COLUMN, MARKDOWN],
[ROOT, TABS, TAB, TABS, TAB, ROW, COLUMN, ROW, COLUMN, MARKDOWN],
[ROOT, GRID, ROW, COLUMN, TABS],
];

validExamples.forEach((example, exampleIdx) => {
Expand Down Expand Up @@ -127,7 +128,6 @@ describe('isValidChild', () => {
[ROOT, GRID, ROW, [TABS]],
[ROOT, GRID, ROW, [TAB]],
[ROOT, GRID, ROW, [DIVIDER]],
[ROOT, GRID, ROW, COLUMN, [TABS]],
[ROOT, GRID, ROW, COLUMN, [TAB]],
[ROOT, GRID, ROW, COLUMN, ROW, [DIVIDER]],
[ROOT, GRID, ROW, COLUMN, ROW, COLUMN, [ROW]], // too nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const propTypes = {
dashboardId: PropTypes.number.isRequired,
component: componentShape.isRequired,
parentComponent: componentShape.isRequired,
getComponentById: PropTypes.func.isRequired,
index: PropTypes.number.isRequired,
depth: PropTypes.number.isRequired,
editMode: PropTypes.bool.isRequired,
Expand Down Expand Up @@ -268,16 +269,22 @@ class ChartHolder extends React.Component {
isComponentVisible,
dashboardId,
fullSizeChartId,
getComponentById = () => undefined,
} = this.props;

const { chartId } = component.meta;
const isFullSize = fullSizeChartId === chartId;

// inherit the size of parent columns
const widthMultiple =
parentComponent.type === COLUMN_TYPE
? parentComponent.meta.width || GRID_MIN_COLUMN_COUNT
: component.meta.width || GRID_MIN_COLUMN_COUNT;
const columnParentWidth = getComponentById(
parentComponent.parents?.find(parent => parent.startsWith(COLUMN_TYPE)),
)?.meta?.width;
let widthMultiple = component.meta.width || GRID_MIN_COLUMN_COUNT;
if (parentComponent.type === COLUMN_TYPE) {
widthMultiple = parentComponent.meta.width || GRID_MIN_COLUMN_COUNT;
} else if (columnParentWidth && widthMultiple > columnParentWidth) {
widthMultiple = columnParentWidth;
}

let chartWidth = 0;
let chartHeight = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Column extends React.PureComponent {
onResizeStop,
handleComponentDrop,
editMode,
onChangeTab,
isComponentVisible,
} = this.props;

Expand Down Expand Up @@ -191,6 +192,7 @@ class Column extends React.PureComponent {
onResize={onResize}
onResizeStop={onResizeStop}
isComponentVisible={isComponentVisible}
onChangeTab={onChangeTab}
/>
))}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Row extends React.PureComponent {
onResizeStop,
handleComponentDrop,
editMode,
onChangeTab,
isComponentVisible,
} = this.props;

Expand Down Expand Up @@ -176,6 +177,7 @@ class Row extends React.PureComponent {
onResize={onResize}
onResizeStop={onResizeStop}
isComponentVisible={isComponentVisible}
onChangeTab={onChangeTab}
/>
))}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function mapStateToProps(
const component = dashboardLayout[id];
const props = {
component,
getComponentById: id => dashboardLayout[id],
parentComponent: dashboardLayout[parentId],
editMode: dashboardState.editMode,
filters: getActiveFilters(),
Expand Down
19 changes: 10 additions & 9 deletions superset-frontend/src/dashboard/util/isValidChild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
import { DASHBOARD_ROOT_DEPTH as rootDepth } from './constants';

const depthOne = rootDepth + 1;
const depthTwo = rootDepth + 2;
// const depthTwo = rootDepth + 2; // Meantime no need
const depthThree = rootDepth + 3;
const depthFour = rootDepth + 4;
const depthFive = rootDepth + 5;
Expand Down Expand Up @@ -77,17 +77,17 @@ const parentMaxDepthLookup = {
},

[TABS_TYPE]: {
[TAB_TYPE]: depthTwo,
[TAB_TYPE]: depthThree,
},

[TAB_TYPE]: {
[CHART_TYPE]: depthTwo,
[MARKDOWN_TYPE]: depthTwo,
[COLUMN_TYPE]: depthTwo,
[DIVIDER_TYPE]: depthTwo,
[HEADER_TYPE]: depthTwo,
[ROW_TYPE]: depthTwo,
[TABS_TYPE]: depthTwo,
[CHART_TYPE]: depthFive,
[MARKDOWN_TYPE]: depthFive,
[COLUMN_TYPE]: depthThree,
[DIVIDER_TYPE]: depthFive,
[HEADER_TYPE]: depthFive,
[ROW_TYPE]: depthThree,
[TABS_TYPE]: depthThree,
},

[COLUMN_TYPE]: {
Expand All @@ -96,6 +96,7 @@ const parentMaxDepthLookup = {
[MARKDOWN_TYPE]: depthFive,
[ROW_TYPE]: depthThree,
[DIVIDER_TYPE]: depthThree,
[TABS_TYPE]: depthThree,
},

// these have no valid children
Expand Down

0 comments on commit cc9c821

Please sign in to comment.