From 6eb04b1c4f5cc4a0ea8d9e72f7272d30a12392d9 Mon Sep 17 00:00:00 2001 From: Simcha Shats Date: Tue, 13 Apr 2021 16:04:01 +0300 Subject: [PATCH 1/7] fix:fix get permission function --- .../src/dashboard/util/getPermissions.ts | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/superset-frontend/src/dashboard/util/getPermissions.ts b/superset-frontend/src/dashboard/util/getPermissions.ts index 3e7cb19765dd..0208fd68fd65 100644 --- a/superset-frontend/src/dashboard/util/getPermissions.ts +++ b/superset-frontend/src/dashboard/util/getPermissions.ts @@ -18,25 +18,22 @@ */ import memoizeOne from 'memoize-one'; -export default function getPermissions( - perm: string, - view: string, - roles: object, -) { - return memoizeOne(() => { - const roleList = Object.entries(roles); - if (roleList.length === 0) return false; - let bool; +const findPermissions = (perm: string, view: string, roles: object) => { + const roleList = Object.entries(roles); + if (roleList.length === 0) return false; + let bool; - roleList.forEach(([role, permissions]) => { - bool = Boolean( - permissions.find( - (permission: Array) => - permission[0] === perm && permission[1] === view, - ), - ); - }); - console.log('bool', bool); - return bool; + roleList.forEach(([role, permissions]) => { + bool = Boolean( + permissions.find( + (permission: Array) => + permission[0] === perm && permission[1] === view, + ), + ); }); -} + return bool; +}; + +const getPermissions = memoizeOne(findPermissions); + +export default getPermissions; From f36add0e2e06fc27ab52b6effe6ff49e8a061ef1 Mon Sep 17 00:00:00 2001 From: Simcha Shats Date: Sun, 5 Sep 2021 00:19:55 +0300 Subject: [PATCH 2/7] feat: add tabs inside column --- .../components/gridComponents/ChartHolder.jsx | 15 +++++++++++---- .../dashboard/containers/DashboardComponent.jsx | 1 + .../src/dashboard/util/isValidChild.ts | 17 +++++++++-------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx b/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx index 87f1cbc78de4..1f76aafd5ce6 100644 --- a/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx +++ b/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx @@ -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, @@ -268,16 +269,22 @@ class ChartHolder extends React.Component { isComponentVisible, dashboardId, fullSizeChartId, + getComponentById, } = 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; diff --git a/superset-frontend/src/dashboard/containers/DashboardComponent.jsx b/superset-frontend/src/dashboard/containers/DashboardComponent.jsx index 50497152f850..12397eaae5e6 100644 --- a/superset-frontend/src/dashboard/containers/DashboardComponent.jsx +++ b/superset-frontend/src/dashboard/containers/DashboardComponent.jsx @@ -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(), diff --git a/superset-frontend/src/dashboard/util/isValidChild.ts b/superset-frontend/src/dashboard/util/isValidChild.ts index 70ec4d0a697f..ee946203cb53 100644 --- a/superset-frontend/src/dashboard/util/isValidChild.ts +++ b/superset-frontend/src/dashboard/util/isValidChild.ts @@ -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]: { @@ -96,6 +96,7 @@ const parentMaxDepthLookup = { [MARKDOWN_TYPE]: depthFive, [ROW_TYPE]: depthThree, [DIVIDER_TYPE]: depthThree, + [TABS_TYPE]: depthThree, }, // these have no valid children From e8d870c686c9bafa479fd7460a5325190783c1ef Mon Sep 17 00:00:00 2001 From: Simcha Shats Date: Sun, 5 Sep 2021 08:38:16 +0300 Subject: [PATCH 3/7] lint: fix lint --- superset-frontend/src/dashboard/util/isValidChild.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/dashboard/util/isValidChild.ts b/superset-frontend/src/dashboard/util/isValidChild.ts index ee946203cb53..78d8984bc50a 100644 --- a/superset-frontend/src/dashboard/util/isValidChild.ts +++ b/superset-frontend/src/dashboard/util/isValidChild.ts @@ -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; From a6fca501a4b38781b547206413c088d48ddd2d22 Mon Sep 17 00:00:00 2001 From: Simcha Shats Date: Sun, 5 Sep 2021 09:19:25 +0300 Subject: [PATCH 4/7] test: fix test --- .../src/dashboard/components/gridComponents/ChartHolder.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx b/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx index 1f76aafd5ce6..9d447674d1a1 100644 --- a/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx +++ b/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx @@ -269,7 +269,7 @@ class ChartHolder extends React.Component { isComponentVisible, dashboardId, fullSizeChartId, - getComponentById, + getComponentById = () => undefined, } = this.props; const { chartId } = component.meta; From b2d3a1a2e2b3302c841f98b7be92e15c1fb9cdbe Mon Sep 17 00:00:00 2001 From: Simcha Shats Date: Sun, 5 Sep 2021 10:38:00 +0300 Subject: [PATCH 5/7] test: fix tests --- .../spec/javascripts/dashboard/util/isValidChild_spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/spec/javascripts/dashboard/util/isValidChild_spec.ts b/superset-frontend/spec/javascripts/dashboard/util/isValidChild_spec.ts index d689f1ea7642..b3031ff62a93 100644 --- a/superset-frontend/spec/javascripts/dashboard/util/isValidChild_spec.ts +++ b/superset-frontend/spec/javascripts/dashboard/util/isValidChild_spec.ts @@ -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) => { @@ -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 From bd06c981d77f0f1ae8f54cb188f36ff36d1ee9fe Mon Sep 17 00:00:00 2001 From: Simcha Shats Date: Sun, 5 Sep 2021 11:02:35 +0300 Subject: [PATCH 6/7] test: fix tests --- .../spec/javascripts/dashboard/util/isValidChild_spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/spec/javascripts/dashboard/util/isValidChild_spec.ts b/superset-frontend/spec/javascripts/dashboard/util/isValidChild_spec.ts index b3031ff62a93..6ff56b85820f 100644 --- a/superset-frontend/spec/javascripts/dashboard/util/isValidChild_spec.ts +++ b/superset-frontend/spec/javascripts/dashboard/util/isValidChild_spec.ts @@ -83,7 +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]], + [ROOT, GRID, ROW, COLUMN, TABS], ]; validExamples.forEach((example, exampleIdx) => { From 39568850edf7547e6d28664237bdf813af32cca3 Mon Sep 17 00:00:00 2001 From: Simcha Shats Date: Sun, 12 Sep 2021 15:42:31 +0300 Subject: [PATCH 7/7] fix: pass onChangeTab function through layout --- .../src/dashboard/components/gridComponents/Column.jsx | 2 ++ .../src/dashboard/components/gridComponents/Row.jsx | 2 ++ 2 files changed, 4 insertions(+) diff --git a/superset-frontend/src/dashboard/components/gridComponents/Column.jsx b/superset-frontend/src/dashboard/components/gridComponents/Column.jsx index d63634978b1c..90666d6d9883 100644 --- a/superset-frontend/src/dashboard/components/gridComponents/Column.jsx +++ b/superset-frontend/src/dashboard/components/gridComponents/Column.jsx @@ -110,6 +110,7 @@ class Column extends React.PureComponent { onResizeStop, handleComponentDrop, editMode, + onChangeTab, isComponentVisible, } = this.props; @@ -191,6 +192,7 @@ class Column extends React.PureComponent { onResize={onResize} onResizeStop={onResizeStop} isComponentVisible={isComponentVisible} + onChangeTab={onChangeTab} /> ))} diff --git a/superset-frontend/src/dashboard/components/gridComponents/Row.jsx b/superset-frontend/src/dashboard/components/gridComponents/Row.jsx index a6b3598cf0cb..b0037bf12322 100644 --- a/superset-frontend/src/dashboard/components/gridComponents/Row.jsx +++ b/superset-frontend/src/dashboard/components/gridComponents/Row.jsx @@ -109,6 +109,7 @@ class Row extends React.PureComponent { onResizeStop, handleComponentDrop, editMode, + onChangeTab, isComponentVisible, } = this.props; @@ -176,6 +177,7 @@ class Row extends React.PureComponent { onResize={onResize} onResizeStop={onResizeStop} isComponentVisible={isComponentVisible} + onChangeTab={onChangeTab} /> ))}