@@ -12,23 +12,36 @@ import {
1212 Stack ,
1313 TextField ,
1414} from '@fluentui/react'
15- import React from 'react'
15+ import React , { useEffect , useState } from 'react'
1616import { useDispatch , useSelector } from 'react-redux'
1717import { IRootState } from '../../../store'
1818import { setConfirmEditDialog , setEditPanel , setSelectedItem } from '../../../store/scriptlinks/actions'
19+ import { IScriptLink } from '../../../store/scriptlinks/types'
1920import { updateScriptLink } from '../chrome/chrome-actions'
2021
2122const ScriptLinksEditPanel = ( ) => {
22-
2323 const dispatch = useDispatch ( )
2424 const { isDark } = useSelector ( ( state : IRootState ) => state . home )
2525 const { editpanel, selectedItem, confirmedit } = useSelector ( ( state : IRootState ) => state . scriptLinks )
26+
27+ // Add local state to store edits
28+ const [ editItem , setEditItem ] = useState < IScriptLink > ( )
29+
30+ // Update local state when selected item changes
31+ useEffect ( ( ) => {
32+ setEditItem ( selectedItem )
33+ } , [ selectedItem ] )
2634
2735 const panelOverlayProps : IOverlayProps = { isDarkThemed : isDark }
2836 const _onRenderItemFooterContent = ( ) => {
2937 return (
3038 < PrimaryButton
31- onClick = { ( ) => dispatch ( setConfirmEditDialog ( false ) ) }
39+ onClick = { ( ) => {
40+ if ( editItem ) {
41+ dispatch ( setSelectedItem ( editItem ) )
42+ dispatch ( setConfirmEditDialog ( false ) )
43+ }
44+ } }
3245 style = { { marginRight : '8px' } }
3346 text = { 'Update' }
3447 />
@@ -54,32 +67,30 @@ const ScriptLinksEditPanel = () => {
5467 onRenderFooterContent = { _onRenderItemFooterContent }
5568 overlayProps = { panelOverlayProps }
5669 >
57- { selectedItem &&
70+ { selectedItem && editItem &&
5871 < Stack >
5972 < TextField
6073 label = 'Url'
6174 description = 'Url of the file to be injected.'
6275 multiline
6376 autoAdjustHeight
64- value = { selectedItem . Url }
77+ value = { editItem . Url }
6578 onChange = { ( event , newValue ?: string ) =>
66- dispatch ( setSelectedItem ( { ...selectedItem , Url : newValue ? newValue : '' } ) )
79+ setEditItem ( { ...editItem , Url : newValue ? newValue : '' } )
6780 }
6881 required
69- // TODO: do proper validation
7082 />
7183 < TextField
7284 label = 'Sequence'
7385 description = 'The sequence of the scriplink'
7486 styles = { { fieldGroup : { width : 100 } } }
75- value = { selectedItem . Sequence . toString ( ) }
87+ value = { editItem . Sequence . toString ( ) }
7688 type = { 'number' }
7789 onChange = { ( event , newValue ?: string ) =>
78- dispatch ( setSelectedItem ( { ...selectedItem , Sequence : newValue ? + newValue : selectedItem . Sequence } ) )
90+ setEditItem ( { ...editItem , Sequence : newValue ? + newValue : editItem . Sequence } )
7991 }
8092 onGetErrorMessage = { sequenceValidator }
8193 required
82- // TODO: do proper casting & validation
8394 />
8495 < Dropdown
8596 placeholder = 'Select scope'
@@ -88,15 +99,15 @@ const ScriptLinksEditPanel = () => {
8899 { key : 2 , text : 'Site Collection' } ,
89100 { key : 3 , text : 'Current Web' } ,
90101 ] }
91- selectedKey = { selectedItem . Scope }
102+ selectedKey = { editItem . Scope }
92103 onChange = { ( event , option ?: IDropdownOption ) =>
93- dispatch ( setSelectedItem ( { ...selectedItem , Scope : option ? + option . key : selectedItem . Scope } ) )
104+ setEditItem ( { ...editItem , Scope : option ? + option . key : editItem . Scope } )
94105 }
95106 />
96107 < TextField
97108 label = 'Id'
98109 description = 'Id of the custom action'
99- value = { selectedItem . Id }
110+ value = { editItem . Id }
100111 readOnly
101112 disabled
102113 />
@@ -125,4 +136,4 @@ const ScriptLinksEditPanel = () => {
125136 )
126137}
127138
128- export default ScriptLinksEditPanel
139+ export default ScriptLinksEditPanel
0 commit comments