Skip to content

Commit

Permalink
Merge pull request openshift#7443 from divyanshiGupta/ODC-3289
Browse files Browse the repository at this point in the history
Fix to not show misleading alert message in Project Access Page
  • Loading branch information
openshift-merge-robot authored Dec 9, 2020
2 parents 75ca65d + 5a7128d commit 9ebf5d1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
4 changes: 4 additions & 0 deletions frontend/packages/dev-console/locales/en/devconsole.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@
"Rate of transmitted packets dropped": "Rate of transmitted packets dropped",
"Average Container bandwidth by Pod: received": "Average Container bandwidth by Pod: received",
"Average Container bandwidth by Pod: transmitted": "Average Container bandwidth by Pod: transmitted",
"Add Access": "Add Access",
"Role": "Role",
"Select a role": "Select a role",
"Reload": "Reload",
"or": "or",
"Create a Project": "Create a Project",
"Overview": "Overview",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import * as _ from 'lodash';
import { Form, TextInputTypes } from '@patternfly/react-core';
import { FormikProps, FormikValues } from 'formik';
import { MultiColumnField, InputField, DropdownField, FormFooter } from '@console/shared';
import { useTranslation } from 'react-i18next';

enum accessRoles {
'' = 'Select a role',
admin = 'Admin',
edit = 'Edit',
view = 'View',
Expand All @@ -18,29 +18,40 @@ const ProjectAccessForm: React.FC<FormikProps<FormikValues>> = ({
status,
errors,
dirty,
}) => (
<Form onSubmit={handleSubmit}>
<div className="co-m-pane__form">
<MultiColumnField
name="projectAccess"
addLabel="Add Access"
headers={['Name', 'Role']}
emptyValues={{ user: '', role: '' }}
>
<InputField name="user" type={TextInputTypes.text} placeholder="Name" />
<DropdownField name="role" items={accessRoles} fullWidth />
</MultiColumnField>
<hr />
<FormFooter
handleReset={handleReset}
isSubmitting={isSubmitting}
errorMessage={status && status.submitError}
successMessage={status && !dirty && status.success}
disableSubmit={!dirty || !_.isEmpty(errors)}
showAlert={dirty}
/>
</div>
</Form>
);
}) => {
const { t } = useTranslation();
const disableSubmit = !dirty || !_.isEmpty(errors);
return (
<Form onSubmit={handleSubmit}>
<div className="co-m-pane__form">
<MultiColumnField
name="projectAccess"
addLabel={t('devconsole~Add Access')}
headers={[t('devconsole~Name'), t('devconsole~Role')]}
emptyValues={{ user: '', role: '' }}
>
<InputField name="user" type={TextInputTypes.text} placeholder={t('devconsole~Name')} />
<DropdownField
name="role"
title={t('devconsole~Select a role')}
items={accessRoles}
fullWidth
/>
</MultiColumnField>
<hr />
<FormFooter
handleReset={handleReset}
isSubmitting={isSubmitting}
errorMessage={status && status.submitError}
successMessage={status && !dirty && status.success}
disableSubmit={disableSubmit}
showAlert={!disableSubmit}
submitLabel={t('devconsole~Save')}
resetLabel={t('devconsole~Reload')}
/>
</div>
</Form>
);
};

export default ProjectAccessForm;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import ProjectAccessForm from '../ProjectAccessForm';
type ProjectAccessFormProps = React.ComponentProps<typeof ProjectAccessForm>;
let formProps: ProjectAccessFormProps;

jest.mock('react-i18next', () => {
const reactI18next = require.requireActual('react-i18next');
return {
...reactI18next,
useTranslation: () => ({ t: (key) => key.split('~')[1] }),
};
});

describe('Project Access Form', () => {
const projectAccessForm = shallow(<ProjectAccessForm {...formProps} />);
beforeEach(() => {
Expand Down Expand Up @@ -109,6 +117,6 @@ describe('Project Access Form', () => {
.children()
.at(1)
.props().items,
).toEqual({ '': 'Select a role', admin: 'Admin', view: 'View', edit: 'Edit' });
).toEqual({ admin: 'Admin', view: 'View', edit: 'Edit' });
});
});

0 comments on commit 9ebf5d1

Please sign in to comment.