;
}) => {
switch (key) {
case MenuKeys.ForceRefresh:
refreshChart();
props.addSuccessToast(t('Data refreshed'));
break;
case MenuKeys.ToggleChartDescription:
// eslint-disable-next-line no-unused-expressions
props.toggleExpandSlice?.(props.slice.slice_id);
break;
case MenuKeys.ExploreChart:
// eslint-disable-next-line no-unused-expressions
props.logExploreChart?.(props.slice.slice_id);
if (domEvent.metaKey || domEvent.ctrlKey) {
domEvent.preventDefault();
window.open(props.exploreUrl, '_blank');
} else {
history.push(props.exploreUrl);
}
break;
case MenuKeys.ExportCsv:
// eslint-disable-next-line no-unused-expressions
props.exportCSV?.(props.slice.slice_id);
break;
case MenuKeys.ExportPivotCsv:
// eslint-disable-next-line no-unused-expressions
props.exportPivotCSV?.(props.slice.slice_id);
break;
case MenuKeys.Fullscreen:
props.handleToggleFullSize();
break;
case MenuKeys.ExportFullCsv:
// eslint-disable-next-line no-unused-expressions
props.exportFullCSV?.(props.slice.slice_id);
break;
case MenuKeys.ExportFullXlsx:
// eslint-disable-next-line no-unused-expressions
props.exportFullXLSX?.(props.slice.slice_id);
break;
case MenuKeys.ExportXlsx:
// eslint-disable-next-line no-unused-expressions
props.exportXLSX?.(props.slice.slice_id);
break;
case MenuKeys.DownloadAsImage: {
// menu closes with a delay, we need to hide it manually,
// so that we don't capture it on the screenshot
const menu = document.querySelector(
'.antd5-dropdown:not(.antd5-dropdown-hidden)',
) as HTMLElement;
if (menu) {
menu.style.visibility = 'hidden';
}
downloadAsImage(
getScreenshotNodeSelector(props.slice.slice_id),
props.slice.slice_name,
true,
// @ts-ignore
)(domEvent).then(() => {
if (menu) {
menu.style.visibility = 'visible';
}
});
props.logEvent?.(LOG_ACTIONS_CHART_DOWNLOAD_AS_IMAGE, {
chartId: props.slice.slice_id,
});
break;
}
case MenuKeys.CrossFilterScoping: {
openScopingModal();
break;
}
case MenuKeys.ViewResults: {
if (resultsMenuRef.current && !resultsMenuRef.current.showModal) {
resultsMenuRef.current.open(domEvent);
}
break;
}
case MenuKeys.DrillToDetail: {
setDrillModalIsOpen(!drillModalIsOpen);
break;
}
case MenuKeys.ViewQuery: {
if (queryMenuRef.current && !queryMenuRef.current.showModal) {
queryMenuRef.current.open(domEvent);
}
break;
}
default:
break;
}
setIsDropdownVisible(false);
};
const {
componentId,
dashboardId,
slice,
isFullSize,
cachedDttm = [],
updatedDttm = null,
addSuccessToast = () => {},
addDangerToast = () => {},
supersetCanShare = false,
isCached = [],
} = props;
const isTable = slice.viz_type === VizType.Table;
const isPivotTable = slice.viz_type === VizType.PivotTable;
const cachedWhen = (cachedDttm || []).map(itemCachedDttm =>
extendedDayjs.utc(itemCachedDttm).fromNow(),
);
const updatedWhen = updatedDttm
? extendedDayjs.utc(updatedDttm).fromNow()
: '';
const getCachedTitle = (itemCached: boolean) => {
if (itemCached) {
return t('Cached %s', cachedWhen);
}
if (updatedWhen) {
return t('Fetched %s', updatedWhen);
}
return '';
};
const refreshTooltipData = [...new Set(isCached.map(getCachedTitle) || '')];
// If all queries have same cache time we can unit them to one
const refreshTooltip = refreshTooltipData.map((item, index) => (
{refreshTooltipData.length > 1
? t('Query %s: %s', index + 1, item)
: item}
));
const fullscreenLabel = isFullSize
? t('Exit fullscreen')
: t('Enter fullscreen');
// @z-index-below-dashboard-header (100) - 1 = 99 for !isFullSize and 101 for isFullSize
const dropdownOverlayStyle = {
zIndex: isFullSize ? 101 : 99,
animationDuration: '0s',
};
const menu = (
);
return (
<>
{isFullSize && (
{
props.handleToggleFullSize();
}}
/>
)}
menu}
overlayStyle={dropdownOverlayStyle}
trigger={['click']}
placement="bottomRight"
open={isDropdownVisible}
onOpenChange={visible => setIsDropdownVisible(visible)}
>
{
setDrillModalIsOpen(false);
}}
chartId={slice.slice_id}
showModal={drillModalIsOpen}
/>
{canEditCrossFilters && scopingModal}
>
);
};
export default SliceHeaderControls;