Skip to content

Commit 031fed0

Browse files
committed
feat: add an edit button by the side of description
1 parent 6c783e3 commit 031fed0

7 files changed

Lines changed: 108 additions & 56 deletions

File tree

packages/neuron-ui/src/components/Addresses/index.tsx

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
TextField,
77
IColumn,
88
CheckboxVisibility,
9-
ITextFieldStyleProps,
9+
IconButton,
1010
getTheme,
1111
} from 'office-ui-fabric-react'
1212

@@ -39,7 +39,7 @@ const Addresses = ({
3939
onDescriptionPress,
4040
onDescriptionFieldBlur,
4141
onDescriptionChange,
42-
onDescriptionFocus,
42+
onDescriptionSelected,
4343
} = useLocalDescription('address', walletID, dispatch)
4444

4545
const theme = getTheme()
@@ -88,31 +88,40 @@ const Addresses = ({
8888
minWidth: 100,
8989
maxWidth: 300,
9090
onRender: (item?: State.Address) => {
91+
const isSelected = item && localDescription.key === item.address
9192
return item ? (
92-
<TextField
93-
borderless
94-
title={item.description}
95-
value={localDescription.key === item.address ? localDescription.description : item.description || ''}
96-
onBlur={onDescriptionFieldBlur(item.address, item.description)}
97-
onFocus={onDescriptionFocus}
98-
onKeyPress={onDescriptionPress(item.address, item.description)}
99-
onChange={onDescriptionChange(item.address)}
100-
disabled={localDescription.key === item.address && isUpdatingDescription}
101-
iconProps={{
102-
iconName: localDescription.key === item.address && isUpdatingDescription ? 'Updating' : '',
103-
}}
104-
styles={(props: ITextFieldStyleProps) => {
105-
return {
93+
<>
94+
<TextField
95+
borderless
96+
title={item.description}
97+
value={isSelected ? localDescription.description : item.description || ''}
98+
onBlur={isSelected ? onDescriptionFieldBlur(item.address, item.description) : undefined}
99+
onKeyPress={isSelected ? onDescriptionPress(item.address, item.description) : undefined}
100+
onChange={isSelected ? onDescriptionChange(item.address) : undefined}
101+
disabled={isSelected && isUpdatingDescription}
102+
iconProps={{
103+
iconName: isSelected && isUpdatingDescription ? 'Updating' : '',
104+
}}
105+
readOnly={!isSelected}
106+
styles={{
106107
root: {
107108
flex: 1,
108109
},
109110
fieldGroup: {
110-
borderColor: props.focused ? semanticColors.inputBorder : 'transparent',
111-
border: '1px solid',
111+
backgroundColor: isSelected ? '#fff' : 'transparent',
112+
borderColor: 'transparent',
113+
border: isSelected ? '1px solid' : 'none',
112114
},
113-
}
114-
}}
115-
/>
115+
}}
116+
/>
117+
{isSelected ? null : (
118+
<IconButton
119+
iconProps={{ iconName: 'Edit' }}
120+
className="editButton"
121+
onClick={onDescriptionSelected(item.address, item.description)}
122+
/>
123+
)}
124+
</>
116125
) : null
117126
},
118127
},
@@ -152,7 +161,7 @@ const Addresses = ({
152161
localDescription,
153162
onDescriptionFieldBlur,
154163
onDescriptionPress,
155-
onDescriptionFocus,
164+
// onDescriptionFocus,
156165
isUpdatingDescription,
157166
t,
158167
semanticColors,

packages/neuron-ui/src/components/TransactionList/index.tsx

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import {
55
Text,
66
ShimmeredDetailsList,
77
TextField,
8+
IconButton,
89
IColumn,
910
IGroup,
1011
CheckboxVisibility,
11-
ITextFieldStyleProps,
1212
getTheme,
1313
} from 'office-ui-fabric-react'
1414

@@ -73,7 +73,7 @@ const TransactionList = ({
7373
onDescriptionPress,
7474
onDescriptionFieldBlur,
7575
onDescriptionChange,
76-
onDescriptionFocus,
76+
onDescriptionSelected,
7777
} = useLocalDescription('transaction', walletID, dispatch)
7878

7979
const transactionColumns: IColumn[] = useMemo(
@@ -175,28 +175,37 @@ const TransactionList = ({
175175
minWidth: 100,
176176
maxWidth: 100,
177177
onRender: (item?: FormatTransaction) => {
178+
const isSelected = item && localDescription.key === item.hash
178179
return item ? (
179-
<TextField
180-
title={item.description}
181-
value={localDescription.key === item.hash ? localDescription.description : item.description || ''}
182-
onFocus={onDescriptionFocus}
183-
onBlur={onDescriptionFieldBlur(item.hash, item.description)}
184-
onKeyPress={onDescriptionPress(item.hash, item.description)}
185-
onChange={onDescriptionChange(item.hash)}
186-
disabled={localDescription.key === item.hash && isUpdatingDescription}
187-
iconProps={{
188-
iconName: localDescription.key === item.hash && isUpdatingDescription ? 'Updating' : '',
189-
}}
190-
borderless
191-
styles={(props: ITextFieldStyleProps) => {
192-
return {
180+
<>
181+
<TextField
182+
title={item.description}
183+
value={isSelected ? localDescription.description : item.description || ''}
184+
onBlur={isSelected ? onDescriptionFieldBlur(item.hash, item.description) : undefined}
185+
onKeyPress={isSelected ? onDescriptionPress(item.hash, item.description) : undefined}
186+
onChange={isSelected ? onDescriptionChange(item.hash) : undefined}
187+
disabled={isSelected && isUpdatingDescription}
188+
iconProps={{
189+
iconName: isSelected && isUpdatingDescription ? 'Updating' : '',
190+
}}
191+
borderless
192+
readOnly={!isSelected}
193+
styles={{
193194
fieldGroup: {
194-
borderColor: '#ccc',
195-
border: props.focused ? '1px solid' : 'none',
195+
backgroundColor: isSelected ? '#fff' : 'transparent',
196+
borderColor: 'transparent',
197+
border: isSelected ? '1px solid' : 'none',
196198
},
197-
}
198-
}}
199-
/>
199+
}}
200+
/>
201+
{isSelected ? null : (
202+
<IconButton
203+
iconProps={{ iconName: 'Edit' }}
204+
className="editButton"
205+
onClick={onDescriptionSelected(item.hash, item.description)}
206+
/>
207+
)}
208+
</>
200209
) : null
201210
},
202211
},
@@ -224,7 +233,7 @@ const TransactionList = ({
224233
onDescriptionChange,
225234
onDescriptionFieldBlur,
226235
onDescriptionPress,
227-
onDescriptionFocus,
236+
onDescriptionSelected,
228237
isUpdatingDescription,
229238
t,
230239
]

packages/neuron-ui/src/states/stateProvider/actionCreators/transactions.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ export const updateTransactionDescription = (params: Controller.UpdateTransactio
2929
updateDescription: true,
3030
},
3131
})
32+
const descriptionParams = {
33+
hash: params.hash,
34+
description: params.description,
35+
}
36+
dispatch({
37+
type: NeuronWalletActions.UpdateTransactionDescription,
38+
payload: descriptionParams,
39+
}) // update local description before remote description to avoid the flicker on the field
3240
updateRemoteTransactionDescription(params)
3341
.then(res => {
3442
if (res.status) {
3543
dispatch({
3644
type: NeuronWalletActions.UpdateTransactionDescription,
37-
payload: {
38-
hash: params.hash,
39-
description: params.description,
40-
},
45+
payload: descriptionParams,
4146
})
4247
} else {
4348
addNotification(failureResToNotification(res))(dispatch)

packages/neuron-ui/src/states/stateProvider/actionCreators/wallets.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,20 @@ export const updateAddressDescription = (params: Controller.UpdateAddressDescrip
209209
updateDescription: true,
210210
},
211211
})
212+
const descriptionParams = {
213+
address: params.address,
214+
description: params.description,
215+
}
216+
dispatch({
217+
type: NeuronWalletActions.UpdateAddressDescription,
218+
payload: descriptionParams,
219+
})
212220
updateRemoteAddressDescription(params)
213221
.then(res => {
214222
if (res.status) {
215223
dispatch({
216224
type: NeuronWalletActions.UpdateAddressDescription,
217-
payload: {
218-
address: params.address,
219-
description: params.description,
220-
},
225+
payload: descriptionParams,
221226
})
222227
} else {
223228
addNotification(failureResToNotification(res))(dispatch)

packages/neuron-ui/src/styles/index.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,28 @@ navbar {
5757
.ms-DetailsRow-cell {
5858
display: flex;
5959
align-items: center;
60+
61+
.editButton {
62+
position: absolute;
63+
right: 0;
64+
justify-content: center;
65+
align-items: center;
66+
display: none;
67+
background-color: transparent;
68+
}
69+
70+
&:hover {
71+
.editButton {
72+
display: flex;
73+
}
74+
}
6075
}
6176

6277
.text-overflow {
6378
overflow: hidden;
6479
text-overflow: ellipsis;
6580
}
81+
6682
}
6783

6884
// hack fabric ui experimental pagination style

packages/neuron-ui/src/theme.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Close as FailIcon,
1111
Copy as CopyIcon,
1212
Down as ArrowDownIcon,
13+
FormEdit as EditIcon,
1314
FormClose as ClearIcon,
1415
FormAdd as CreateIcon,
1516
FormPreviousLink as LeaveIcon,
@@ -56,6 +57,7 @@ registerIcons({
5657
info: <InfoIcon size="16px" />,
5758
errorbadge: <AlertIcon size="16px" />,
5859
completed: <SuccessIcon size="16px" />,
60+
cancel: <DismissIcon size="16px" />,
5961
MiniCopy: <CopyIcon size="small" color={semanticColors.primaryButtonBackground} />,
6062
Search: <SearchIcon size="16px" color={semanticColors.menuIcon} />,
6163
FirstPage: <LinkTopIcon size="16px" color={semanticColors.menuIcon} style={{ transform: 'rotate(-90deg)' }} />,
@@ -83,6 +85,7 @@ registerIcons({
8385
TransactionFailure: <FailIcon size="14px" color="#d50000" />,
8486
TransactionPending: <PendingIcon size="14px" style={{ animation: 'rotate360 3s linear infinite' }} />,
8587
Keystore: <KeystoreIcon color="white" style={{ transform: 'scale(0.6)' }} />,
88+
Edit: <EditIcon color="#000" size="20px" />,
8689
},
8790
})
8891

packages/neuron-ui/src/utils/hooks.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export const useLocalDescription = (type: 'address' | 'transaction', walletID: s
3232
description: localDescription.description,
3333
})(dispatch)
3434
}
35+
36+
setLocalDescription({ key: '', description: '' })
3537
},
3638
[type, walletID, localDescription, dispatch]
3739
)
@@ -59,15 +61,18 @@ export const useLocalDescription = (type: 'address' | 'transaction', walletID: s
5961
},
6062
[setLocalDescription]
6163
)
62-
const onDescriptionFocus = useCallback(() => {
63-
setLocalDescription({ key: '', description: '' })
64-
}, [setLocalDescription])
64+
const onDescriptionSelected = useCallback(
65+
(hash: string, originDesc: string) => () => {
66+
setLocalDescription({ key: hash, description: originDesc })
67+
},
68+
[setLocalDescription]
69+
)
6570
return {
6671
localDescription,
6772
onDescriptionFieldBlur,
6873
onDescriptionPress,
6974
onDescriptionChange,
70-
onDescriptionFocus,
75+
onDescriptionSelected,
7176
}
7277
}
7378

0 commit comments

Comments
 (0)