Skip to content

Commit

Permalink
chore: Add downloadAsImage types, change filter selector (#26297)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje authored Dec 21, 2023
1 parent 60abf7e commit 5e85f5c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
25 changes: 19 additions & 6 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
"@testing-library/react-hooks": "^5.0.3",
"@testing-library/user-event": "^12.7.0",
"@types/classnames": "^2.2.10",
"@types/dom-to-image": "^2.6.7",
"@types/enzyme": "^3.10.5",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/fetch-mock": "^7.3.2",
Expand Down
18 changes: 2 additions & 16 deletions superset-frontend/src/types/dom-to-image-more.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@
*/

declare module 'dom-to-image-more' {
export interface Options {
filter?: ((node: Node) => boolean) | undefined;
bgcolor?: string | undefined;
width?: number | undefined;
height?: number | undefined;
style?: {} | undefined;
quality?: number | undefined;
imagePlaceholder?: string | undefined;
cacheBust?: boolean | undefined;
}

class DomToImageMore {
static toJpeg(node: Node, options?: Options): Promise<string>;
}

export default DomToImageMore;
import domToImage = require('dom-to-image-more');
export = domToImage;
}
7 changes: 3 additions & 4 deletions superset-frontend/src/utils/downloadAsImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,24 @@ export default function downloadAsImage(
if (typeof node.className === 'string') {
return (
node.className !== 'mapboxgl-control-container' &&
!node.className.includes('ant-dropdown')
!node.className.includes('header-controls')
);
}
return true;
};

return domToImage
.toJpeg(elementToPrint, {
quality: 1,
bgcolor: supersetTheme.colors.grayscale.light4,
filter,
})
.then(dataUrl => {
.then((dataUrl: string) => {
const link = document.createElement('a');
link.download = `${generateFileStem(description)}.jpg`;
link.href = dataUrl;
link.click();
})
.catch(e => {
.catch((e: Error) => {
console.error('Creating image failed', e);
});
};
Expand Down

0 comments on commit 5e85f5c

Please sign in to comment.