forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dashboard): narrow empty drop area (apache#26313)
- Loading branch information
1 parent
68a0b82
commit 3532eb8
Showing
6 changed files
with
235 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardWrapper.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* 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 React from 'react'; | ||
import { fireEvent, render } from 'spec/helpers/testing-library'; | ||
import { OptionControlLabel } from 'src/explore/components/controls/OptionControls'; | ||
|
||
import DashboardWrapper from './DashboardWrapper'; | ||
|
||
test('should render children', () => { | ||
const { getByTestId } = render( | ||
<DashboardWrapper> | ||
<div data-test="mock-children" /> | ||
</DashboardWrapper>, | ||
{ useRedux: true, useDnd: true }, | ||
); | ||
expect(getByTestId('mock-children')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should update the style on dragging state', () => { | ||
const defaultProps = { | ||
label: <span>Test label</span>, | ||
tooltipTitle: 'This is a tooltip title', | ||
onRemove: jest.fn(), | ||
onMoveLabel: jest.fn(), | ||
onDropLabel: jest.fn(), | ||
type: 'test', | ||
index: 0, | ||
}; | ||
const { container, getByText } = render( | ||
<DashboardWrapper> | ||
<OptionControlLabel | ||
{...defaultProps} | ||
index={1} | ||
label={<span>Label 1</span>} | ||
/> | ||
<OptionControlLabel | ||
{...defaultProps} | ||
index={2} | ||
label={<span>Label 2</span>} | ||
/> | ||
</DashboardWrapper>, | ||
{ | ||
useRedux: true, | ||
useDnd: true, | ||
initialState: { | ||
dashboardState: { | ||
editMode: true, | ||
}, | ||
}, | ||
}, | ||
); | ||
expect( | ||
container.getElementsByClassName('dragdroppable--dragging'), | ||
).toHaveLength(0); | ||
fireEvent.dragStart(getByText('Label 1')); | ||
expect( | ||
container.getElementsByClassName('dragdroppable--dragging'), | ||
).toHaveLength(1); | ||
}); |
128 changes: 128 additions & 0 deletions
128
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/** | ||
* 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 React, { useEffect } from 'react'; | ||
import { css, styled } from '@superset-ui/core'; | ||
import { RootState } from 'src/dashboard/types'; | ||
import { useSelector } from 'react-redux'; | ||
import { useDragDropManager } from 'react-dnd'; | ||
import classNames from 'classnames'; | ||
|
||
const StyledDiv = styled.div` | ||
${({ theme }) => css` | ||
display: grid; | ||
grid-template-columns: auto 1fr; | ||
grid-template-rows: auto 1fr; | ||
flex: 1; | ||
/* Special cases */ | ||
&.dragdroppable--dragging | ||
.dashboard-component-tabs-content | ||
> .empty-droptarget.empty-droptarget--full { | ||
height: 100%; | ||
} | ||
/* A row within a column has inset hover menu */ | ||
.dragdroppable-column .dragdroppable-row .hover-menu--left { | ||
left: ${theme.gridUnit * -3}px; | ||
background: ${theme.colors.grayscale.light5}; | ||
border: 1px solid ${theme.colors.grayscale.light2}; | ||
} | ||
.dashboard-component-tabs { | ||
position: relative; | ||
} | ||
/* A column within a column or tabs has inset hover menu */ | ||
.dragdroppable-column .dragdroppable-column .hover-menu--top, | ||
.dashboard-component-tabs .dragdroppable-column .hover-menu--top { | ||
top: ${theme.gridUnit * -3}px; | ||
background: ${theme.colors.grayscale.light5}; | ||
border: 1px solid ${theme.colors.grayscale.light2}; | ||
} | ||
/* move Tabs hover menu to top near actual Tabs */ | ||
.dashboard-component-tabs > .hover-menu-container > .hover-menu--left { | ||
top: 0; | ||
transform: unset; | ||
background: transparent; | ||
} | ||
/* push Chart actions to upper right */ | ||
.dragdroppable-column .dashboard-component-chart-holder .hover-menu--top, | ||
.dragdroppable .dashboard-component-header .hover-menu--top { | ||
right: ${theme.gridUnit * 2}px; | ||
top: ${theme.gridUnit * 2}px; | ||
background: transparent; | ||
border: none; | ||
transform: unset; | ||
left: unset; | ||
} | ||
div:hover > .hover-menu-container .hover-menu, | ||
.hover-menu-container .hover-menu:hover { | ||
opacity: 1; | ||
} | ||
p { | ||
margin: 0 0 ${theme.gridUnit * 2}px 0; | ||
} | ||
i.danger { | ||
color: ${theme.colors.error.base}; | ||
} | ||
i.warning { | ||
color: ${theme.colors.alert.base}; | ||
} | ||
`} | ||
`; | ||
|
||
type Props = {}; | ||
|
||
const DashboardWrapper: React.FC<Props> = ({ children }) => { | ||
const editMode = useSelector<RootState, boolean>( | ||
state => state.dashboardState.editMode, | ||
); | ||
const dragDropManager = useDragDropManager(); | ||
const [isDragged, setIsDragged] = React.useState( | ||
dragDropManager.getMonitor().isDragging(), | ||
); | ||
|
||
useEffect(() => { | ||
const monitor = dragDropManager.getMonitor(); | ||
const unsub = monitor.subscribeToStateChange(() => { | ||
setIsDragged(monitor.isDragging()); | ||
}); | ||
|
||
return () => { | ||
unsub(); | ||
}; | ||
}, [dragDropManager]); | ||
|
||
return ( | ||
<StyledDiv | ||
className={classNames({ | ||
'dragdroppable--dragging': editMode && isDragged, | ||
})} | ||
> | ||
{children} | ||
</StyledDiv> | ||
); | ||
}; | ||
|
||
export default DashboardWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.