Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Dashboard toggle fullscreen button #10840

Merged
merged 3 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ describe('HeaderActionsDropdown', () => {
expect(wrapper.find(SaveModal)).not.toExist();
});

it('should render two MenuItems', () => {
it('should render four MenuItems', () => {
const wrapper = setup(overrideProps);
expect(wrapper.find(MenuItem)).toHaveLength(3);
expect(wrapper.find(MenuItem)).toHaveLength(4);
});

it('should render the RefreshIntervalModal', () => {
Expand Down Expand Up @@ -100,9 +100,9 @@ describe('HeaderActionsDropdown', () => {
expect(wrapper.find(SaveModal)).toExist();
});

it('should render three MenuItems', () => {
it('should render four MenuItems', () => {
const wrapper = setup(overrideProps);
expect(wrapper.find(MenuItem)).toHaveLength(3);
expect(wrapper.find(MenuItem)).toHaveLength(4);
});

it('should render the RefreshIntervalModal', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,15 @@ describe('getChartIdsFromLayout', () => {
expect(url).toBe(
'path?preselect_filters=%7B%2235%22%3A%7B%22key%22%3A%5B%22value%22%5D%7D%7D',
);

const urlWithHash = getDashboardUrl('path', filters, 'iamhashtag');
expect(urlWithHash).toBe(
'path?preselect_filters=%7B%2235%22%3A%7B%22key%22%3A%5B%22value%22%5D%7D%7D#iamhashtag',
);

const urlWithStandalone = getDashboardUrl('path', filters, '', true);
expect(urlWithStandalone).toBe(
'path?preselect_filters=%7B%2235%22%3A%7B%22key%22%3A%5B%22value%22%5D%7D%7D&standalone=true',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,25 @@ class HeaderActionsDropdown extends React.PureComponent {
{t('Download as image')}
</MenuItem>
)}

{!editMode && (
<MenuItem
onClick={() => {
const hasStandalone = window.location.search.includes(
'standalone=true',
);
const url = getDashboardUrl(
window.location.pathname,
getActiveFilters(),
window.location.hash,
!hasStandalone,
);
window.location.replace(url);
}}
>
{t('Toggle FullScreen')}
</MenuItem>
)}
</DropdownButton>
);
}
Expand Down
10 changes: 8 additions & 2 deletions superset-frontend/src/dashboard/util/getDashboardUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
*/
import serializeActiveFilterValues from './serializeActiveFilterValues';

export default function getDashboardUrl(pathname, filters = {}, hash = '') {
export default function getDashboardUrl(
pathname,
filters = {},
hash = '',
standalone = false,
) {
// convert flattened { [id_column]: values } object
// to nested filter object
const obj = serializeActiveFilterValues(filters);
const preselectFilters = encodeURIComponent(JSON.stringify(obj));
const hashSection = hash ? `#${hash}` : '';
return `${pathname}?preselect_filters=${preselectFilters}${hashSection}`;
const standaloneParam = standalone ? '&standalone=true' : '';
return `${pathname}?preselect_filters=${preselectFilters}${standaloneParam}${hashSection}`;
}