Skip to content

Commit

Permalink
[frontend] Fix mappable content download (#8976)
Browse files Browse the repository at this point in the history
  • Loading branch information
Archidoit authored Nov 18, 2024
1 parent a11f111 commit 04226f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import MarkdownDisplay from '../../../../components/MarkdownDisplay';
import { FIVE_SECONDS } from '../../../../utils/Time';
import withRouter from '../../../../utils/compat_router/withRouter';
import CKEditor from '../../../../components/CKEditor';
import { htmlToPdf, htmlToPdfReport } from '../../../../utils/htmlToPdf';
import { htmlToPdf } from '../../../../utils/htmlToPdf';

pdfjs.GlobalWorkerOptions.workerSrc = `${APP_BASE_PATH}/static/ext/pdf.worker.mjs`;

Expand Down Expand Up @@ -424,21 +424,16 @@ class StixCoreObjectContentComponent extends Component {
this.setState({ markdownSelectedTab: tab });
}

async handleDownloadPdf() {
const { currentFileId, currentContent } = this.state;
async handleDownloadMappableContentInPdf() {
const { currentContent } = this.state;
const { stixCoreObject } = this.props;
if (currentFileId) {
if (currentFileId.startsWith('fromTemplate')) {
const file = stixCoreObject.contentsFromTemplate.edges.find((e) => e.node.id === currentFileId);
const name = currentFileId.split('/').pop().split('.')[0];
const markings = file?.node.objectMarking.map((m) => m.representative.main) ?? [];
htmlToPdfReport(stixCoreObject, currentContent, name, markings).download(`${name}.pdf`);
} else {
const fragment = stixCoreObject.name.split('/');
const currentName = R.last(fragment);
htmlToPdf(currentFileId, currentContent).download(`${currentName}.pdf`);
}
}
const regex = /<img[^>]+src=(\\?["'])[^'"]+\.gif\1[^>]*\/?>/gi;
const htmlData = currentContent
.replaceAll('id="undefined" ', '')
.replaceAll(regex, '');
const fragment = stixCoreObject.name.split('/');
const currentName = R.last(fragment);
htmlToPdf('content', htmlData).download(`${currentName}.pdf`);
}

render() {
Expand Down Expand Up @@ -488,7 +483,7 @@ class StixCoreObjectContentComponent extends Component {
{contentSelected && (
<StixCoreObjectMappableContent
containerData={stixCoreObject}
handleDownloadPdf={this.handleDownloadPdf.bind(this)}
handleDownloadPdf={this.handleDownloadMappableContentInPdf.bind(this)}
askAi={true}
editionMode={true}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const StixCoreObjectContentFilesList = ({
htmlToPdf(id, data).download(`${currentName}.pdf`);
}
} catch (e) {
MESSAGING$.notifyError('pouet');
MESSAGING$.notifyError('Error trying to download in PDF');
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const findPlaybooksForEntity = async (context: AuthContext, user: AuthUse
const jsonFilters = filters ? JSON.parse(filters) : null;
const newFilters = {
mode: FilterMode.And,
filters: findFiltersFromKey(jsonFilters.filters ?? [], 'entity_type'),
filters: findFiltersFromKey(jsonFilters?.filters ?? [], 'entity_type'),
filterGroups: []
};
const isMatch = await isStixMatchFilterGroup(context, SYSTEM_USER, stixEntity, newFilters);
Expand Down

0 comments on commit 04226f8

Please sign in to comment.