Skip to content

Commit 1fe23bf

Browse files
authored
Disable Gitconfig Save button if config has not changed (#1426)
Add a check that compared stored and new gitconfig data on input. If the entered gitconfig data matches with stored data, disable the Save button.
1 parent 25b3c90 commit 1fe23bf

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Form/__tests__/index.spec.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,33 @@ describe('GitConfigForm', () => {
9696
expect(screen.getByRole('button', { name: 'Save' })).toBeEnabled();
9797
expect(screen.getByRole('button', { name: 'Reload' })).toBeEnabled();
9898
});
99+
100+
test('with gitconfig not changed', () => {
101+
renderComponent(
102+
{ gitConfig: { user: { name: 'name', email: 'test@che' } } },
103+
{ isValid: true, nextGitConfig: { user: { name: 'name', email: 'test@che' } } },
104+
);
105+
106+
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled();
107+
});
108+
109+
test('with gitconfig name changed', () => {
110+
renderComponent(
111+
{ gitConfig: { user: { name: 'name', email: 'test@che' } } },
112+
{ isValid: true, nextGitConfig: { user: { name: 'new name', email: 'test@che' } } },
113+
);
114+
115+
expect(screen.getByRole('button', { name: 'Save' })).toBeEnabled();
116+
});
117+
118+
test('with gitconfig email changed', () => {
119+
renderComponent(
120+
{ gitConfig: { user: { name: 'name', email: 'test@che' } } },
121+
{ isValid: true, nextGitConfig: { user: { name: 'name', email: 'new-test@che' } } },
122+
);
123+
124+
expect(screen.getByRole('button', { name: 'Save' })).toBeEnabled();
125+
});
99126
});
100127

101128
test('handle the Reload button click', async () => {

packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Form/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,23 @@ export class GitConfigForm extends React.PureComponent<Props, State> {
6969
});
7070
}
7171

72+
private isGitConfigEqual(config1: GitConfig, config2: GitConfig): boolean {
73+
if (!config1 || !config2 || !config1.user || !config2.user) {
74+
return false;
75+
}
76+
return config1.user.email === config2.user.email && config1.user.name === config2.user.name;
77+
}
78+
7279
public render(): React.ReactElement {
7380
const { gitConfig, isLoading } = this.props;
7481
const { isValid, nextGitConfig } = this.state;
7582

7683
const config = { ...gitConfig, ...(nextGitConfig || {}) };
77-
const isSaveDisabled = isLoading || isValid === false || nextGitConfig === undefined;
84+
const isSaveDisabled =
85+
isLoading ||
86+
!isValid ||
87+
nextGitConfig === undefined ||
88+
this.isGitConfigEqual(gitConfig, nextGitConfig);
7889

7990
return (
8091
<PageSection variant={PageSectionVariants.light}>

0 commit comments

Comments
 (0)