-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Shows related dashboards in Explore (#21685)
- Loading branch information
1 parent
0ff1e49
commit 200bed6
Showing
9 changed files
with
282 additions
and
7 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
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
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
78 changes: 78 additions & 0 deletions
78
...rontend/src/explore/components/useExploreAdditionalActionsMenu/DashboardsSubMenu.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,78 @@ | ||
/** | ||
* 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 { render, screen, waitFor } from 'spec/helpers/testing-library'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { Menu } from 'src/components/Menu'; | ||
import DashboardItems from './DashboardsSubMenu'; | ||
|
||
const asyncRender = (numberOfItems: number) => | ||
waitFor(() => { | ||
const dashboards = []; | ||
for (let i = 1; i <= numberOfItems; i += 1) { | ||
dashboards.push({ id: i, dashboard_title: `Dashboard ${i}` }); | ||
} | ||
render( | ||
<Menu openKeys={['menu']}> | ||
<Menu.SubMenu title="Dashboards added to" key="menu"> | ||
<DashboardItems key="menu" dashboards={dashboards} /> | ||
</Menu.SubMenu> | ||
</Menu>, | ||
{ | ||
useRouter: true, | ||
}, | ||
); | ||
}); | ||
|
||
test('renders a submenu', async () => { | ||
await asyncRender(3); | ||
expect(screen.getByText('Dashboard 1')).toBeInTheDocument(); | ||
expect(screen.getByText('Dashboard 2')).toBeInTheDocument(); | ||
expect(screen.getByText('Dashboard 3')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders a submenu with search', async () => { | ||
await asyncRender(20); | ||
expect(screen.getByPlaceholderText('Search')).toBeInTheDocument(); | ||
}); | ||
|
||
test('displays a searched value', async () => { | ||
await asyncRender(20); | ||
userEvent.type(screen.getByPlaceholderText('Search'), '2'); | ||
expect(screen.getByText('Dashboard 2')).toBeInTheDocument(); | ||
expect(screen.getByText('Dashboard 20')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders a "No results found" message when searching', async () => { | ||
await asyncRender(20); | ||
userEvent.type(screen.getByPlaceholderText('Search'), 'unknown'); | ||
expect(screen.getByText('No results found')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders a submenu with no dashboards', async () => { | ||
await asyncRender(0); | ||
expect(screen.getByText('None')).toBeInTheDocument(); | ||
}); | ||
|
||
test('shows link icon when hovering', async () => { | ||
await asyncRender(3); | ||
expect(screen.queryByRole('img', { name: 'full' })).not.toBeInTheDocument(); | ||
userEvent.hover(screen.getByText('Dashboard 1')); | ||
expect(screen.getByRole('img', { name: 'full' })).toBeInTheDocument(); | ||
}); |
146 changes: 146 additions & 0 deletions
146
...set-frontend/src/explore/components/useExploreAdditionalActionsMenu/DashboardsSubMenu.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,146 @@ | ||
/** | ||
* 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, { useState } from 'react'; | ||
import { css, t, useTheme } from '@superset-ui/core'; | ||
import { Input } from 'src/components/Input'; | ||
import Icons from 'src/components/Icons'; | ||
import { Menu } from 'src/components/Menu'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
export interface DashboardsSubMenuProps { | ||
chartId?: number; | ||
dashboards?: { id: number; dashboard_title: string }[]; | ||
} | ||
|
||
const WIDTH = 220; | ||
const HEIGHT = 300; | ||
const SEARCH_THRESHOLD = 10; | ||
|
||
const DashboardsSubMenu = ({ | ||
chartId, | ||
dashboards = [], | ||
...menuProps | ||
}: DashboardsSubMenuProps) => { | ||
const theme = useTheme(); | ||
const [dashboardSearch, setDashboardSearch] = useState<string>(); | ||
const [hoveredItem, setHoveredItem] = useState<number | null>(); | ||
const showSearch = dashboards.length > SEARCH_THRESHOLD; | ||
const filteredDashboards = dashboards.filter( | ||
dashboard => | ||
!dashboardSearch || | ||
dashboard.dashboard_title | ||
.toLowerCase() | ||
.includes(dashboardSearch.toLowerCase()), | ||
); | ||
const noResults = dashboards.length === 0; | ||
const noResultsFound = dashboardSearch && filteredDashboards.length === 0; | ||
const urlQueryString = chartId ? `?focused_chart=${chartId}` : ''; | ||
return ( | ||
<> | ||
{showSearch && ( | ||
<Input | ||
allowClear | ||
placeholder={t('Search')} | ||
prefix={<Icons.Search iconSize="l" />} | ||
css={css` | ||
width: ${WIDTH}px; | ||
margin: ${theme.gridUnit * 2}px ${theme.gridUnit * 3}px; | ||
`} | ||
value={dashboardSearch} | ||
onChange={e => setDashboardSearch(e.currentTarget.value?.trim())} | ||
/> | ||
)} | ||
<div | ||
css={css` | ||
max-height: ${HEIGHT}px; | ||
overflow: auto; | ||
`} | ||
> | ||
{filteredDashboards.map(dashboard => ( | ||
<Menu.Item | ||
key={String(dashboard.id)} | ||
onMouseEnter={() => setHoveredItem(dashboard.id)} | ||
onMouseLeave={() => { | ||
if (hoveredItem === dashboard.id) { | ||
setHoveredItem(null); | ||
} | ||
}} | ||
{...menuProps} | ||
> | ||
<Link | ||
target="_blank" | ||
rel="noreferer noopener" | ||
to={`/superset/dashboard/${dashboard.id}${urlQueryString}`} | ||
> | ||
<div | ||
css={css` | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
max-width: ${WIDTH}px; | ||
`} | ||
> | ||
<div | ||
css={css` | ||
white-space: normal; | ||
`} | ||
> | ||
{dashboard.dashboard_title} | ||
</div> | ||
<Icons.Full | ||
iconSize="l" | ||
iconColor={theme.colors.grayscale.base} | ||
css={css` | ||
margin-left: ${theme.gridUnit * 2}px; | ||
visibility: ${hoveredItem === dashboard.id | ||
? 'visible' | ||
: 'hidden'}; | ||
`} | ||
/> | ||
</div> | ||
</Link> | ||
</Menu.Item> | ||
))} | ||
{noResultsFound && ( | ||
<div | ||
css={css` | ||
margin-left: ${theme.gridUnit * 3}px; | ||
margin-bottom: ${theme.gridUnit}px; | ||
`} | ||
> | ||
{t('No results found')} | ||
</div> | ||
)} | ||
{noResults && ( | ||
<Menu.Item | ||
disabled | ||
css={css` | ||
min-width: ${WIDTH}px; | ||
`} | ||
{...menuProps} | ||
> | ||
{t('None')} | ||
</Menu.Item> | ||
)} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default DashboardsSubMenu; |
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.