-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into phone_number_copy
- Loading branch information
Showing
75 changed files
with
3,000 additions
and
6,034 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...src/modules/action-menu/actions/record-actions/single-record/hooks/useExportNoteAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { SingleRecordActionHookWithObjectMetadataItem } from '@/action-menu/actions/types/SingleRecordActionHook'; | ||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; | ||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState'; | ||
import { BlockNoteEditor } from '@blocknote/core'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { isDefined } from 'twenty-ui'; | ||
|
||
export const useExportNoteAction: SingleRecordActionHookWithObjectMetadataItem = | ||
({ recordId, objectMetadataItem }) => { | ||
const selectedRecord = useRecoilValue(recordStoreFamilyState(recordId)); | ||
|
||
const filename = `${(selectedRecord?.title || 'Untitled Note').replace(/[<>:"/\\|?*]/g, '-')}`; | ||
|
||
const isNoteOrTask = | ||
objectMetadataItem?.nameSingular === CoreObjectNameSingular.Note || | ||
objectMetadataItem?.nameSingular === CoreObjectNameSingular.Task; | ||
|
||
const shouldBeRegistered = | ||
isDefined(objectMetadataItem) && | ||
isDefined(selectedRecord) && | ||
isNoteOrTask; | ||
|
||
const onClick = async () => { | ||
if (!shouldBeRegistered || !selectedRecord?.body) { | ||
return; | ||
} | ||
|
||
const editor = await BlockNoteEditor.create({ | ||
initialContent: JSON.parse(selectedRecord.body), | ||
}); | ||
|
||
const { exportBlockNoteEditorToPdf } = await import( | ||
'@/action-menu/actions/record-actions/single-record/utils/exportBlockNoteEditorToPdf' | ||
); | ||
|
||
await exportBlockNoteEditorToPdf(editor, filename); | ||
|
||
// TODO later: implement DOCX export | ||
// const { exportBlockNoteEditorToDocx } = await import( | ||
// '@/action-menu/actions/record-actions/single-record/utils/exportBlockNoteEditorToDocx' | ||
// ); | ||
// await exportBlockNoteEditorToDocx(editor, filename); | ||
}; | ||
|
||
return { | ||
shouldBeRegistered, | ||
onClick, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...les/action-menu/actions/record-actions/single-record/utils/exportBlockNoteEditorToDocx.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { BlockNoteEditor } from '@blocknote/core'; | ||
|
||
import { | ||
docxDefaultSchemaMappings, | ||
DOCXExporter, | ||
} from '@blocknote/xl-docx-exporter'; | ||
import { Buffer } from 'buffer'; | ||
import { Packer } from 'docx'; | ||
import { saveAs } from 'file-saver'; | ||
|
||
export const exportBlockNoteEditorToDocx = async ( | ||
editor: BlockNoteEditor, | ||
filename: string, | ||
) => { | ||
// Polyfill needed for exportBlockNoteEditorToDocX | ||
if (typeof window !== 'undefined') { | ||
window.Buffer = Buffer; | ||
} | ||
|
||
const exporter = new DOCXExporter(editor.schema, docxDefaultSchemaMappings); | ||
|
||
const docxDocument = await exporter.toDocxJsDocument(editor.document); | ||
|
||
const blob = await Packer.toBlob(docxDocument); | ||
saveAs(blob, `${filename}.docx`); | ||
}; |
19 changes: 19 additions & 0 deletions
19
...ules/action-menu/actions/record-actions/single-record/utils/exportBlockNoteEditorToPdf.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { BlockNoteEditor } from '@blocknote/core'; | ||
import { | ||
PDFExporter, | ||
pdfDefaultSchemaMappings, | ||
} from '@blocknote/xl-pdf-exporter'; | ||
import * as ReactPDF from '@react-pdf/renderer'; | ||
import { saveAs } from 'file-saver'; | ||
|
||
export const exportBlockNoteEditorToPdf = async ( | ||
editor: BlockNoteEditor, | ||
filename: string, | ||
) => { | ||
const exporter = new PDFExporter(editor.schema, pdfDefaultSchemaMappings); | ||
|
||
const pdfDocument = await exporter.toReactPDFDocument(editor.document); | ||
|
||
const blob = await ReactPDF.pdf(pdfDocument).toBlob(); | ||
saveAs(blob, `${filename}.pdf`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...ons/single-record/workflow-run-actions/constants/WorkflowRunsSingleRecordActionsConfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useAddToFavoritesSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useAddToFavoritesSingleRecordAction'; | ||
import { useNavigateToNextRecordSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useNavigateToNextRecordSingleRecordAction'; | ||
import { useNavigateToPreviousRecordSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useNavigateToPreviousRecordSingleRecordAction'; | ||
import { useRemoveFromFavoritesSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useRemoveFromFavoritesSingleRecordAction'; | ||
import { SingleRecordActionKeys } from '@/action-menu/actions/record-actions/single-record/types/SingleRecordActionsKey'; | ||
import { ActionAvailableOn } from '@/action-menu/actions/types/ActionAvailableOn'; | ||
import { SingleRecordActionHook } from '@/action-menu/actions/types/SingleRecordActionHook'; | ||
import { | ||
ActionMenuEntry, | ||
ActionMenuEntryScope, | ||
ActionMenuEntryType, | ||
} from '@/action-menu/types/ActionMenuEntry'; | ||
import { | ||
IconChevronDown, | ||
IconChevronUp, | ||
IconHeart, | ||
IconHeartOff, | ||
} from 'twenty-ui'; | ||
|
||
export const WORKFLOW_RUNS_SINGLE_RECORD_ACTIONS_CONFIG: Record< | ||
string, | ||
ActionMenuEntry & { | ||
actionHook: SingleRecordActionHook; | ||
} | ||
> = { | ||
addToFavoritesSingleRecord: { | ||
type: ActionMenuEntryType.Standard, | ||
scope: ActionMenuEntryScope.RecordSelection, | ||
key: SingleRecordActionKeys.ADD_TO_FAVORITES, | ||
label: 'Add to favorites', | ||
shortLabel: 'Add to favorites', | ||
position: 0, | ||
isPinned: true, | ||
Icon: IconHeart, | ||
availableOn: [ | ||
ActionAvailableOn.INDEX_PAGE_SINGLE_RECORD_SELECTION, | ||
ActionAvailableOn.SHOW_PAGE, | ||
], | ||
actionHook: useAddToFavoritesSingleRecordAction, | ||
}, | ||
removeFromFavoritesSingleRecord: { | ||
type: ActionMenuEntryType.Standard, | ||
scope: ActionMenuEntryScope.RecordSelection, | ||
key: SingleRecordActionKeys.REMOVE_FROM_FAVORITES, | ||
label: 'Remove from favorites', | ||
shortLabel: 'Remove from favorites', | ||
isPinned: true, | ||
position: 1, | ||
Icon: IconHeartOff, | ||
availableOn: [ | ||
ActionAvailableOn.INDEX_PAGE_SINGLE_RECORD_SELECTION, | ||
ActionAvailableOn.SHOW_PAGE, | ||
], | ||
actionHook: useRemoveFromFavoritesSingleRecordAction, | ||
}, | ||
navigateToPreviousRecord: { | ||
type: ActionMenuEntryType.Standard, | ||
scope: ActionMenuEntryScope.RecordSelection, | ||
key: SingleRecordActionKeys.NAVIGATE_TO_PREVIOUS_RECORD, | ||
label: 'Navigate to previous record', | ||
shortLabel: '', | ||
position: 2, | ||
isPinned: true, | ||
Icon: IconChevronUp, | ||
availableOn: [ActionAvailableOn.SHOW_PAGE], | ||
actionHook: useNavigateToPreviousRecordSingleRecordAction, | ||
}, | ||
navigateToNextRecord: { | ||
type: ActionMenuEntryType.Standard, | ||
scope: ActionMenuEntryScope.RecordSelection, | ||
key: SingleRecordActionKeys.NAVIGATE_TO_NEXT_RECORD, | ||
label: 'Navigate to next record', | ||
shortLabel: '', | ||
position: 3, | ||
isPinned: true, | ||
Icon: IconChevronDown, | ||
availableOn: [ActionAvailableOn.SHOW_PAGE], | ||
actionHook: useNavigateToNextRecordSingleRecordAction, | ||
}, | ||
}; |
Oops, something went wrong.