Skip to content

Commit

Permalink
[frontend] fix download files + some css issues (#9099)
Browse files Browse the repository at this point in the history
  • Loading branch information
lndrtrbn authored Nov 21, 2024
1 parent a0a5121 commit 497ca07
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ class StixCoreObjectContentComponent extends Component {
&& [...files, ...exportFiles, ...contentsFromTemplate].find((n) => n.id === currentFileId);
const currentFileType = currentFile && currentFile.metaData.mimetype;
const { innerHeight } = window;
const height = innerHeight - 300;
const height = innerHeight - 320;
const isContentCompatible = isContainerWithContent(stixCoreObject.entity_type);
return (
<div className={classes.container} data-testid='sco-content-page'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,20 @@ const StixCoreObjectContentFilesList = ({
const [deleting, setDeleting] = useState<string | null>(null);

const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
const openPopover = (e: MouseEvent<HTMLButtonElement>) => {
const [menuFile, setMenuFile] = useState<ContentFile | null>(null);
const openPopover = (e: MouseEvent<HTMLButtonElement>, file: ContentFile) => {
e.stopPropagation();
setAnchorEl(e.currentTarget);
setMenuFile(file);
};
const closePopover = () => {
setAnchorEl(null);
setMenuFile(null);
};

const [commitDelete] = useApiMutation<FileLineDeleteMutation>(deleteMutation);

const submitDelete = (fileId: string) => {
setAnchorEl(null);
closePopover();
setDeleting(fileId);
commitDelete({
variables: { fileName: fileId },
Expand All @@ -84,7 +89,7 @@ const StixCoreObjectContentFilesList = ({
};

const downloadPdf = async (file: ContentFile) => {
setAnchorEl(null);
closePopover();
const { id } = file;
const url = `${APP_BASE_PATH}/storage/view/${encodeURIComponent(id)}`;

Expand Down Expand Up @@ -132,7 +137,7 @@ const StixCoreObjectContentFilesList = ({
/>
<ListItemSecondaryAction>
<IconButton
onClick={openPopover}
onClick={(e) => openPopover(e, file)}
aria-haspopup="true"
color="primary"
size="small"
Expand All @@ -142,29 +147,36 @@ const StixCoreObjectContentFilesList = ({
</ListItemSecondaryAction>
</ListItemButton>
</Tooltip>
<Menu
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={() => setAnchorEl(null)}
>
</Fragment>
))}

<Menu
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={closePopover}
>
{menuFile && (
<>
<MenuItem
component={Link}
to={`${APP_BASE_PATH}/storage/get/${encodeURIComponent(file.id)}`}
onClick={() => setAnchorEl(null)}
to={`${APP_BASE_PATH}/storage/get/${encodeURIComponent(menuFile.id)}`}
onClick={closePopover}
target="_blank"
rel="noopener noreferrer"
>
{t_i18n('Download file')}
</MenuItem>
<MenuItem onClick={() => downloadPdf(file)}>
{t_i18n('Download in PDF')}
</MenuItem>
<MenuItem onClick={() => submitDelete(file.id)}>
{menuFile.metaData?.mimetype !== 'application/pdf' && (
<MenuItem onClick={() => downloadPdf(menuFile)}>
{t_i18n('Download in PDF')}
</MenuItem>
)}
<MenuItem onClick={() => submitDelete(menuFile.id)}>
{t_i18n('Delete')}
</MenuItem>
</Menu>
</Fragment>
))}
</>
)}
</Menu>
</List>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ const StixCoreObjectSubscribers: FunctionComponent<ContainerHeaderSharedProps> =
size="small"
variant="text"
color={hasSetAccess ? 'primary' : 'inherit'}
style={{ cursor: hasSetAccess && triggersKnowledgeCount && triggersKnowledgeCount > 0 ? 'pointer' : 'default', marginRight: 10 }}
style={{
cursor: hasSetAccess && triggersKnowledgeCount && triggersKnowledgeCount > 0 ? 'pointer' : 'default',
marginRight: 10,
whiteSpace: 'nowrap',
}}
sx={!hasSetAccess ? {
'&.MuiButtonBase-root:hover': {
bgcolor: 'transparent',
Expand Down

0 comments on commit 497ca07

Please sign in to comment.