Skip to content

Commit 556521c

Browse files
feat: add droppable area to tab empty state
1 parent 84279ac commit 556521c

File tree

2 files changed

+95
-37
lines changed

2 files changed

+95
-37
lines changed

superset-frontend/src/dashboard/components/gridComponents/Tab/Tab.jsx

Lines changed: 94 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ const TitleDropIndicator = styled.div`
115115
}
116116
`;
117117

118-
const renderDraggableContent = dropProps =>
119-
dropProps.dropIndicatorProps && <div {...dropProps.dropIndicatorProps} />;
118+
const renderDraggableContent = dropProps => {
119+
return (
120+
dropProps.dropIndicatorProps && <div {...dropProps.dropIndicatorProps} />
121+
);
122+
};
120123

121124
const Tab = props => {
122125
const dispatch = useDispatch();
@@ -213,6 +216,46 @@ const Tab = props => {
213216

214217
const shouldDropToChild = useCallback(item => item.type !== TAB_TYPE, []);
215218

219+
const renderDropableEmptyState = dropProps => {
220+
return (
221+
<EmptyState
222+
title={
223+
props.editMode
224+
? t('Drag and drop components to this tab')
225+
: t('There are no components added to this tab')
226+
}
227+
description={
228+
canEdit &&
229+
(props.editMode ? (
230+
<span>
231+
{t('You can')}{' '}
232+
<a
233+
href={`/chart/add?dashboard_id=${props.dashboardId}`}
234+
rel="noopener noreferrer"
235+
target="_blank"
236+
>
237+
{t('create a new chart')}
238+
</a>{' '}
239+
{t('or use existing ones from the panel on the right')}
240+
</span>
241+
) : (
242+
<span>
243+
{t('You can add the components in the')}{' '}
244+
<span
245+
role="button"
246+
tabIndex={0}
247+
onClick={() => dispatch(setEditMode(true))}
248+
>
249+
{t('edit mode')}
250+
</span>
251+
</span>
252+
))
253+
}
254+
image="chart.svg"
255+
/>
256+
);
257+
};
258+
216259
const renderTabContent = useCallback(() => {
217260
const {
218261
component: tabComponent,
@@ -253,41 +296,55 @@ const Tab = props => {
253296
</Droppable>
254297
)}
255298
{shouldDisplayEmptyState && (
256-
<EmptyState
257-
title={
258-
editMode
259-
? t('Drag and drop components to this tab')
260-
: t('There are no components added to this tab')
261-
}
262-
description={
263-
canEdit &&
264-
(editMode ? (
265-
<span>
266-
{t('You can')}{' '}
267-
<a
268-
href={`/chart/add?dashboard_id=${dashboardId}`}
269-
rel="noopener noreferrer"
270-
target="_blank"
271-
>
272-
{t('create a new chart')}
273-
</a>{' '}
274-
{t('or use existing ones from the panel on the right')}
275-
</span>
276-
) : (
277-
<span>
278-
{t('You can add the components in the')}{' '}
279-
<span
280-
role="button"
281-
tabIndex={0}
282-
onClick={() => dispatch(setEditMode(true))}
283-
>
284-
{t('edit mode')}
285-
</span>
286-
</span>
287-
))
288-
}
289-
image="chart.svg"
290-
/>
299+
<Droppable
300+
component={tabComponent}
301+
orientation="column"
302+
index={editMode ? 1 : 0}
303+
depth={depth}
304+
onDrop={handleTopDropTargetDrop}
305+
editMode={editMode}
306+
dropToChild
307+
>
308+
{() => (
309+
<div data-test="emptystate-drop-indicator">
310+
<EmptyState
311+
title={
312+
editMode
313+
? t('Drag and drop components to this tab')
314+
: t('There are no components added to this tab')
315+
}
316+
description={
317+
canEdit &&
318+
(editMode ? (
319+
<span>
320+
{t('You can')}{' '}
321+
<a
322+
href={`/chart/add?dashboard_id=${dashboardId}`}
323+
rel="noopener noreferrer"
324+
target="_blank"
325+
>
326+
{t('create a new chart')}
327+
</a>{' '}
328+
{t('or use existing ones from the panel on the right')}
329+
</span>
330+
) : (
331+
<span>
332+
{t('You can add the components in the')}{' '}
333+
<span
334+
role="button"
335+
tabIndex={0}
336+
onClick={() => dispatch(setEditMode(true))}
337+
>
338+
{t('edit mode')}
339+
</span>
340+
</span>
341+
))
342+
}
343+
image="chart.svg"
344+
/>
345+
</div>
346+
)}
347+
</Droppable>
291348
)}
292349
{tabComponent.children.map((componentId, componentIndex) => (
293350
<Fragment key={componentId}>

superset-frontend/src/dashboard/components/gridComponents/Tab/Tab.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ test('Render tab content with no children, editMode: true, canEdit: true', () =>
403403
},
404404
},
405405
});
406+
expect(screen.queryByTestId('emptystate-drop-indicator')).toBeInTheDocument();
406407
expect(
407408
screen.getByText('Drag and drop components to this tab'),
408409
).toBeVisible();

0 commit comments

Comments
 (0)