@@ -6,15 +6,24 @@ import {
66 useReactTable
77} from "@tanstack/react-table" ;
88import { useMemo , useState } from "react" ;
9+ import {
10+ useDeleteIncidentAgentDirectiveMutation ,
11+ useGetIncidentAgentDirectivesQuery
12+ } from "../../../redux/services/digma" ;
13+ import type {
14+ Directive ,
15+ IncidentAgentEvent
16+ } from "../../../redux/services/types" ;
917import { SortIcon } from "../../common/icons/16px/SortIcon" ;
1018import { TrashBinIcon } from "../../common/icons/16px/TrashBinIcon" ;
1119import { Direction } from "../../common/icons/types" ;
1220import { KebabMenu } from "../../common/KebabMenu" ;
1321import { Checkmark } from "../../common/v3/Checkmark" ;
1422import type { MenuItem } from "../../Navigation/common/MenuList/types" ;
1523import * as s from "./styles" ;
16- import type { ColumnMeta , Directive , ExtendedDirective } from "./types" ;
24+ import type { ColumnMeta , ExtendedDirective } from "./types" ;
1725
26+ // TODO: remove
1827const mockData : Directive [ ] = [
1928 {
2029 id : "1" ,
@@ -42,13 +51,73 @@ const mockData: Directive[] = [
4251 }
4352] ;
4453
54+ // TODO: remove
55+ const mockEventsData : IncidentAgentEvent [ ] = [
56+ {
57+ agent_name : "incident_entry" ,
58+ message : "" ,
59+ type : "memory_update"
60+ } ,
61+ {
62+ agent_name : "incident_entry" ,
63+ message : "" ,
64+ type : "memory_update"
65+ } ,
66+ {
67+ agent_name : "incident_entry" ,
68+ message : "" ,
69+ type : "memory_update"
70+ } ,
71+ {
72+ agent_name : "incident_entry" ,
73+ message : "" ,
74+ type : "memory_update"
75+ } ,
76+ {
77+ agent_name : "incident_entry" ,
78+ message : "" ,
79+ type : "memory_update"
80+ } ,
81+ {
82+ agent_name : "incident_entry" ,
83+ message : "" ,
84+ type : "memory_update"
85+ } ,
86+ {
87+ agent_name : "incident_entry" ,
88+ message : "" ,
89+ type : "memory_update"
90+ } ,
91+ {
92+ agent_name : "incident_entry" ,
93+ message : "" ,
94+ type : "memory_update"
95+ } ,
96+ {
97+ agent_name : "incident_entry" ,
98+ message : "" ,
99+ type : "memory_update"
100+ } ,
101+ {
102+ agent_name : "incident_entry" ,
103+ message : "" ,
104+ type : "memory_update"
105+ }
106+ ] ;
107+
45108const columnHelper = createColumnHelper < ExtendedDirective > ( ) ;
46109
47110export const IncidentDirectives = ( ) => {
48111 const [ searchInputValue , setSearchInputValue ] = useState ( "" ) ;
49- const [ bottomInputValue , setBottomInputValue ] = useState ( "" ) ;
50112 const [ selectedConditions , setSelectedConditions ] = useState < string [ ] > ( [ ] ) ;
51113
114+ const { data } = useGetIncidentAgentDirectivesQuery ( {
115+ search_term : searchInputValue
116+ } ) ;
117+
118+ const [ deleteIncidentAgentDirective ] =
119+ useDeleteIncidentAgentDirectiveMutation ( ) ;
120+
52121 const handleSearchInputChange = ( value : string ) => {
53122 setSearchInputValue ( value ) ;
54123 } ;
@@ -59,31 +128,32 @@ export const IncidentDirectives = () => {
59128 ) ;
60129 } ;
61130
62- const handleBottomInputChange = ( ) => {
63- setBottomInputValue ( "" ) ;
131+ const handleMessageSend = ( ) => {
132+ // TODO: implement
64133 } ;
65134
66- const handleBottomInputSubmit = ( ) => {
67- return undefined ;
135+ const handleSelectedConditionTagClick = ( id : string ) => ( ) => {
136+ setSelectedConditions ( ( prev ) => prev . filter ( ( x ) => x !== id ) ) ;
68137 } ;
69138
70139 const items = useMemo ( ( ) => {
71- const filteredItems = mockData . filter ( ( item ) => {
72- const conditionMatch = item . condition
73- . toLowerCase ( )
74- . includes ( searchInputValue . toLowerCase ( ) ) ;
75- const directiveMatch = item . directive
76- . toLowerCase ( )
77- . includes ( searchInputValue . toLowerCase ( ) ) ;
78- return conditionMatch || directiveMatch ;
79- } ) ;
140+ // const filteredItems = (data?.directives ?? mockData) .filter((item) => {
141+ // const conditionMatch = item.condition
142+ // .toLowerCase()
143+ // .includes(searchInputValue.toLowerCase());
144+ // const directiveMatch = item.directive
145+ // .toLowerCase()
146+ // .includes(searchInputValue.toLowerCase());
147+ // return conditionMatch || directiveMatch;
148+ // });
80149
81- return filteredItems . map ( ( item , index ) => ( {
150+ // TODO: remove mock data
151+ return ( data ?. directives ?? mockData ) ?. map ( ( item , index ) => ( {
82152 ...item ,
83153 number : index + 1 ,
84154 isSelected : selectedConditions . includes ( item . id )
85155 } ) ) ;
86- } , [ searchInputValue , selectedConditions ] ) ;
156+ } , [ selectedConditions , data ?. directives ] ) ;
87157
88158 const columns = [
89159 columnHelper . accessor ( ( x ) => x , {
@@ -180,9 +250,13 @@ export const IncidentDirectives = () => {
180250 minWidth : 100 ,
181251 textAlign : "center"
182252 } ,
183- cell : ( ) => {
253+ cell : ( info ) => {
254+ const value = info . getValue ( ) ;
255+
184256 const handleDeleteMenuItemClick = ( ) => {
185- // TODO: implement
257+ void deleteIncidentAgentDirective ( {
258+ id : value . id
259+ } ) ;
186260 } ;
187261
188262 const items : MenuItem [ ] = [
@@ -200,7 +274,7 @@ export const IncidentDirectives = () => {
200274 ] ;
201275
202276 const table = useReactTable ( {
203- data : items ,
277+ data : items ?? [ ] ,
204278 columns,
205279 getCoreRowModel : getCoreRowModel ( ) ,
206280 getSortedRowModel : getSortedRowModel ( ) ,
@@ -301,21 +375,26 @@ export const IncidentDirectives = () => {
301375 </ s . TableBody >
302376 </ s . Table >
303377 </ s . TableContainer >
304- { selectedConditions . length > 0 && (
305- < s . SelectedConditionsContainer >
306- Selected Conditions
307- < s . SelectedConditionsList >
308- { selectedConditions . map ( ( x ) => (
309- < s . SelectedConditionTag key = { x } > #{ x } </ s . SelectedConditionTag >
310- ) ) }
311- </ s . SelectedConditionsList >
312- </ s . SelectedConditionsContainer >
313- ) }
314- < s . StyledPromptInput
315- onChange = { handleBottomInputChange }
316- onSubmit = { handleBottomInputSubmit }
317- value = { bottomInputValue }
318- isDisabled = { true }
378+ < s . StyledAgentChat
379+ // TODO: remove mock data
380+ data = { mockEventsData }
381+ isDataLoading = { false }
382+ onMessageSend = { handleMessageSend }
383+ isMessageSending = { false }
384+ attachmentsComponent = {
385+ selectedConditions . length > 0 && (
386+ < s . SelectedConditionsContainer >
387+ { selectedConditions . map ( ( x ) => (
388+ < s . SelectedConditionTag
389+ onClick = { handleSelectedConditionTagClick ( x ) }
390+ key = { x }
391+ >
392+ #{ x }
393+ </ s . SelectedConditionTag >
394+ ) ) }
395+ </ s . SelectedConditionsContainer >
396+ )
397+ }
319398 />
320399 </ s . Container >
321400 ) ;
0 commit comments