Skip to content

Commit

Permalink
Merge pull request #1010 from sgratch/reset-data-changed-when-enterin…
Browse files Browse the repository at this point in the history
…g-edit

🐞  Reset dataChanged when entering Edit mode for the Credentials section
  • Loading branch information
yaacov authored Mar 24, 2024
2 parents ad68f4b + 18dc444 commit afb2984
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export const BaseCredentialsSection: React.FC<BaseCredentialsSectionProps> = ({
return { ...state, reveal: !state.reveal };
case 'TOGGLE_EDIT':
return { ...state, edit: !state.edit };
case 'RESET_DATA_CHANGED': {
return { ...state, dataChanged: false };
}
case 'SET_NEW_SECRET': {
const dataChanged = isSecretDataChanged(secret, action.payload);
const validationError = validator(action.payload);
Expand Down Expand Up @@ -127,6 +130,11 @@ export const BaseCredentialsSection: React.FC<BaseCredentialsSectionProps> = ({
dispatch({ type: 'TOGGLE_REVEAL' });
}

// mark data as unchanged, i.e. current staged secret data is equal to saved secret data
function resetDataChanged() {
dispatch({ type: 'RESET_DATA_CHANGED' });
}

// Handle user edits
function onNewSecretChange(newValue: IoK8sApiCoreV1Secret) {
// update staged secret with new value
Expand All @@ -150,6 +158,7 @@ export const BaseCredentialsSection: React.FC<BaseCredentialsSectionProps> = ({
await patchSecretData(state.newSecret, true);

setIsLoading(false);
resetDataChanged();
toggleEdit();
} catch (err) {
dispatch({
Expand Down

0 comments on commit afb2984

Please sign in to comment.