1
1
import { type NodeViewProps } from '@tiptap/react'
2
2
import graphql from 'babel-plugin-relay/macro'
3
3
import type { InsightsBlockEditingQuery } from '../../../__generated__/InsightsBlockEditingQuery.graphql'
4
+ import Ellipsis from '../../../components/Ellipsis/Ellipsis'
4
5
import { MeetingDatePicker } from '../../../components/MeetingDatePicker'
5
6
import { MeetingTypePickerCombobox } from '../../../components/MeetingTypePickerCombobox'
6
7
import { SpecificMeetingPickerRoot } from '../../../components/SpecificMeetingPickerRoot'
@@ -10,33 +11,37 @@ import useMutationProps from '../../../hooks/useMutationProps'
10
11
import { Button } from '../../../ui/Button/Button'
11
12
import { quickHash } from '../../../utils/quickHash'
12
13
import type { InsightsBlockAttrs } from './InsightsBlock'
14
+ import { InsightsBlockPromptRoot } from './InsightsBlockPromptRoot'
13
15
14
16
const queryNode = graphql `
15
- query InsightsBlockEditingQuery($meetingIds: [ID!]!) {
17
+ query InsightsBlockEditingQuery($meetingIds: [ID!]!, $prompt: String! ) {
16
18
viewer {
17
- pageInsights(meetingIds: $meetingIds)
19
+ pageInsights(meetingIds: $meetingIds, prompt: $prompt )
18
20
}
19
21
}
20
22
`
21
23
22
24
export const InsightsBlockEditing = ( props : NodeViewProps ) => {
23
25
const { editor, node, updateAttributes} = props
24
26
const attrs = node . attrs as InsightsBlockAttrs
25
- const { id, after, before, meetingTypes, teamIds, meetingIds, hash, title} = attrs
27
+ const { id, after, before, meetingTypes, teamIds, meetingIds, hash, title, prompt } = attrs
26
28
const canQueryMeetings = teamIds . length > 0 && meetingTypes . length > 0 && after && before
27
29
const { submitting, submitMutation, onCompleted} = useMutationProps ( )
28
30
const atmosphere = useAtmosphere ( )
29
31
const disabled = submitting || meetingIds . length < 1
30
32
31
33
const generateInsights = async ( ) => {
32
34
if ( disabled ) return
33
- const resultsHash = await quickHash ( meetingIds )
35
+ const resultsHash = await quickHash ( [ ... meetingIds , prompt ] )
34
36
if ( resultsHash === hash ) {
35
37
updateAttributes ( { editing : false } )
36
38
return
37
39
}
38
40
submitMutation ( )
39
- const res = await atmosphere . fetchQuery < InsightsBlockEditingQuery > ( queryNode , { meetingIds} )
41
+ const res = await atmosphere . fetchQuery < InsightsBlockEditingQuery > ( queryNode , {
42
+ meetingIds,
43
+ prompt
44
+ } )
40
45
onCompleted ( )
41
46
if ( res instanceof Error ) {
42
47
atmosphere . eventEmitter . emit ( 'addSnackbar' , {
@@ -67,7 +72,7 @@ export const InsightsBlockEditing = (props: NodeViewProps) => {
67
72
} }
68
73
value = { title }
69
74
/>
70
- < div className = 'grid grid-cols-[auto_1fr] gap-4 p -4' >
75
+ < div className = 'grid grid-cols-[auto_1fr] gap-4 py -4' >
71
76
{ /* Row 1 */ }
72
77
< label className = 'self-center font-semibold' > Teams</ label >
73
78
< TeamPickerComboboxRoot updateAttributes = { updateAttributes } attrs = { attrs } />
@@ -81,6 +86,7 @@ export const InsightsBlockEditing = (props: NodeViewProps) => {
81
86
{ canQueryMeetings && (
82
87
< SpecificMeetingPickerRoot updateAttributes = { updateAttributes } attrs = { attrs } />
83
88
) }
89
+ < InsightsBlockPromptRoot updateAttributes = { updateAttributes } attrs = { attrs } />
84
90
< div className = 'flex justify-end p-4 select-none' >
85
91
< Button
86
92
variant = 'secondary'
@@ -90,6 +96,7 @@ export const InsightsBlockEditing = (props: NodeViewProps) => {
90
96
disabled = { disabled }
91
97
>
92
98
Generate Insights
99
+ { submitting ? < Ellipsis /> : undefined }
93
100
</ Button >
94
101
</ div >
95
102
</ >
0 commit comments