Skip to content

Commit

Permalink
use container name in template
Browse files Browse the repository at this point in the history
  • Loading branch information
lndrtrbn committed Oct 28, 2024
1 parent f0537a6 commit 60f3304
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ class StixCoreObjectContentComponent extends Component {
<div className={classes.container} data-testid='sco-content-page'>
<StixCoreObjectContentFiles
stixCoreObjectId={stixCoreObject.id}
stixCoreObjectName={stixCoreObject.name}
content={isContentCompatible ? stixCoreObject.contentField ?? '' : null}
contentSelected={contentSelected}
files={files}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const stixCoreObjectContentFilesUploadStixCoreObjectMutation = graphql`
interface StixCoreObjectContentFilesProps {
files: NonNullable<StixCoreObjectContent_stixCoreObject$data['importFiles']>['edges'][number]['node'][],
stixCoreObjectId: string,
stixCoreObjectName: string,
content: string | null,
handleSelectFile: (fileId: string) => void,
handleSelectContent: () => void,
Expand All @@ -100,6 +101,7 @@ interface StixCoreObjectContentFilesProps {
const StixCoreObjectContentFiles: FunctionComponent<StixCoreObjectContentFilesProps> = ({
files,
stixCoreObjectId,
stixCoreObjectName,
content,
handleSelectFile,
handleSelectContent,
Expand Down Expand Up @@ -273,6 +275,7 @@ const StixCoreObjectContentFiles: FunctionComponent<StixCoreObjectContentFilesPr
>
<StixCoreObjectContentFilesList
files={filesList}
stixCoreObjectName={stixCoreObjectName}
currentFileId={currentFileId}
handleSelectFile={handleSelectFile}
onFileChange={onFileChange}
Expand All @@ -298,6 +301,7 @@ const StixCoreObjectContentFiles: FunctionComponent<StixCoreObjectContentFilesPr
{isEnterpriseEdition && (
<StixCoreObjectContentFilesList
files={contentsFromTemplate}
stixCoreObjectName={stixCoreObjectName}
currentFileId={currentFileId}
handleSelectFile={handleSelectFile}
onFileChange={onFileChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export interface ContentFile {
}

interface StixCoreObjectContentFilesListProps {
files: ContentFile[]
files: ContentFile[],
stixCoreObjectName: string,
currentFileId: string,
handleSelectFile: (fileId: string) => void,
onFileChange: (fileName?: string, isDeleted?: boolean) => void,
Expand All @@ -55,6 +56,7 @@ interface StixCoreObjectContentFilesListProps {
const StixCoreObjectContentFilesList = ({
files,
currentFileId,
stixCoreObjectName,
handleSelectFile,
onFileChange,
}: StixCoreObjectContentFilesListProps) => {
Expand Down Expand Up @@ -88,11 +90,11 @@ const StixCoreObjectContentFilesList = ({

try {
const { data } = await axios.get(url);
const currentName = id.split('/').pop() ?? '';
const currentName = (id.split('/').pop() ?? '').split('.')[0];

if (id.startsWith('fromTemplate')) {
const markings = file?.objectMarking?.map((m) => m.representative.main) ?? [];
htmlToPdfReport({ name: 'hello' }, data, currentName, markings).download(`${currentName}.pdf`);
htmlToPdfReport(stixCoreObjectName, data, currentName, markings).download(`${currentName}.pdf`);
} else {
htmlToPdf(id, data).download(`${currentName}.pdf`);
}
Expand Down
6 changes: 3 additions & 3 deletions opencti-platform/opencti-front/src/utils/htmlToPdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const htmlToPdf = (fileName: string, content: string) => {
return generatePdf(pdfMakeObject);
};

export const htmlToPdfReport = (stixCoreObject: any, content: string, templateName: string, markings: string[]) => {
export const htmlToPdfReport = (reportName: string, content: string, templateName: string, markings: string[]) => {
let htmlData = removeUselessContent(content);
htmlData = setImagesWidth(htmlData);
htmlData = setTableFullWidth(htmlData);
Expand Down Expand Up @@ -219,7 +219,7 @@ export const htmlToPdfReport = (stixCoreObject: any, content: string, templateNa
],
},
{
text: stixCoreObject.name,
text: reportName,
alignment: 'right',
style: 'firstPageSubtitle',
},
Expand Down Expand Up @@ -252,7 +252,7 @@ export const htmlToPdfReport = (stixCoreObject: any, content: string, templateNa
margin: [50, 40, 50, 0],
columns: [
{
text: truncate(stixCoreObject.name, 20, false),
text: truncate(reportName, 20, false),
alignment: 'left',
},
{
Expand Down

0 comments on commit 60f3304

Please sign in to comment.