Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
meetulr committed Dec 15, 2023
2 parents 5375a2f + d9e7acb commit d5b7d9f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 85 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"plugins": ["react", "@typescript-eslint", "jest"],
"rules": {
"react/destructuring-assignment": ["off"],
"@typescript-eslint/no-explicit-any": ["error"],
"@typescript-eslint/explicit-module-boundary-types": ["error"],
"@typescript-eslint/no-explicit-any": ["off"],
"@typescript-eslint/explicit-module-boundary-types": ["off"],
"react/no-multi-comp": [
"error",
{
Expand Down
3 changes: 1 addition & 2 deletions public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@
"users": "Users",
"searchName": "Enter Name",
"searchevent": "Enter Event",
"searchFirstName": "Enter First Name",
"searchLastName": "Enter Last Name"
"searchFullName": "Enter Full Name"
},
"userListCard": {
"joined": "Joined",
Expand Down
64 changes: 18 additions & 46 deletions src/screens/OrganizationPeople/OrganizationPeople.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,9 @@ console.error = jest.fn();

describe('Organization People Page', () => {
const searchData = {
firstName: 'Aditya',
lastNameMember: 'Memberguy',
lastNameAdmin: 'Adminguy',
lastNameUser: 'Userguytwo',
fullNameMember: 'Aditya Memberguy',
fullNameAdmin: 'Aditya Adminguy',
fullNameUser: 'Aditya Userguytwo',
location: 'Delhi, India',
event: 'Event',
};
Expand Down Expand Up @@ -716,12 +715,12 @@ describe('Organization People Page', () => {
expect(findtext).toBeInTheDocument();

userEvent.type(
screen.getByPlaceholderText(/Enter First Name/i),
searchData.firstName
screen.getByPlaceholderText(/Enter Full Name/i),
searchData.fullNameMember
);
await wait();
expect(screen.getByPlaceholderText(/Enter First Name/i)).toHaveValue(
searchData.firstName
expect(screen.getByPlaceholderText(/Enter Full Name/i)).toHaveValue(
searchData.fullNameMember
);

await wait();
Expand Down Expand Up @@ -755,29 +754,16 @@ describe('Organization People Page', () => {
expect(screen.getByLabelText(/Members/i)).toBeChecked();
await wait();

const firstNameInput = screen.getByPlaceholderText(/Enter First Name/i);
const lastNameInput = screen.getByPlaceholderText(/Enter Last Name/i);
const fullNameInput = screen.getByPlaceholderText(/Enter Full Name/i);

// Only First Name
userEvent.type(firstNameInput, searchData.firstName);
userEvent.type(fullNameInput, searchData.fullNameMember);
await wait();

let findtext = screen.getByText(/Aditya Memberguy/i);
await wait();
expect(findtext).toBeInTheDocument();

// First & Last Name
userEvent.type(lastNameInput, searchData.lastNameMember);
await wait();

findtext = screen.getByText(/Aditya Memberguy/i);
await wait();
expect(findtext).toBeInTheDocument();

// Only Last Name
userEvent.type(firstNameInput, '');
await wait();

findtext = screen.getByText(/Aditya Memberguy/i);
await wait();
expect(findtext).toBeInTheDocument();
Expand Down Expand Up @@ -819,12 +805,12 @@ describe('Organization People Page', () => {
expect(findtext).toBeInTheDocument();

userEvent.type(
screen.getByPlaceholderText(/Enter First Name/i),
searchData.firstName
screen.getByPlaceholderText(/Enter Full Name/i),
searchData.fullNameAdmin
);
await wait();
expect(screen.getByPlaceholderText(/Enter First Name/i)).toHaveValue(
searchData.firstName
expect(screen.getByPlaceholderText(/Enter Full Name/i)).toHaveValue(
searchData.fullNameAdmin
);
await wait();

Expand Down Expand Up @@ -860,33 +846,19 @@ describe('Organization People Page', () => {
expect(screen.getByLabelText(/Admins/i)).toBeChecked();
await wait();

const firstNameInput = screen.getByPlaceholderText(/Enter First Name/i);
const lastNameInput = screen.getByPlaceholderText(/Enter Last Name/i);
const fullNameInput = screen.getByPlaceholderText(/Enter Full Name/i);

// Only First Name
userEvent.type(firstNameInput, searchData.firstName);
userEvent.type(fullNameInput, searchData.fullNameAdmin);
await wait();

let findtext = screen.getByText(/Aditya Adminguy/i);
await wait();
expect(findtext).toBeInTheDocument();

// First & Last Name
userEvent.type(lastNameInput, searchData.lastNameAdmin);
await wait();

findtext = screen.getByText(/Aditya Adminguy/i);
await wait();
expect(findtext).toBeInTheDocument();

// Only Last Name
userEvent.type(firstNameInput, '');
await wait();

findtext = screen.getByText(/Aditya Adminguy/i);
await wait();
expect(findtext).toBeInTheDocument();

await wait();
expect(window.location).toBeAt('/orgpeople/id=orgid');
});
Expand Down Expand Up @@ -972,10 +944,10 @@ describe('Organization People Page', () => {
expect(screen.getByLabelText(/Users/i)).toBeChecked();
await wait();

const firstNameInput = screen.getByPlaceholderText(/Enter First Name/i);
const fullNameInput = screen.getByPlaceholderText(/Enter Full Name/i);

// Only First Name
userEvent.type(firstNameInput, searchData.firstName);
// Only Full Name
userEvent.type(fullNameInput, searchData.fullNameUser);
await wait();

const orgUsers = dataQueryForUsers?.filter(
Expand Down
56 changes: 21 additions & 35 deletions src/screens/OrganizationPeople/OrganizationPeople.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function organizationPeople(): JSX.Element {
lastName_contains: '',
});

const [fullName, setFullName] = useState('');

const {
data: memberData,
loading: memberLoading,
Expand Down Expand Up @@ -112,22 +114,31 @@ function organizationPeople(): JSX.Element {
}

/* istanbul ignore next */
const handleFirstNameSearchChange = (filterData: any): void => {
const handleFullNameSearchChange = (fullName: string): void => {
/* istanbul ignore next */
const [firstName, lastName] = fullName.split(' ');

const newFilterData = {
firstName_contains: firstName ?? '',
lastName_contains: lastName ?? '',
};

setFilterData(newFilterData);

if (state === 0) {
memberRefetch({
...filterData,
...newFilterData,
orgId: currentUrl,
});
} else if (state === 1) {
adminRefetch({
...filterData,
...newFilterData,
orgId: currentUrl,
admin_for: currentUrl,
});
} else {
usersRefetch({
...filterData,
...newFilterData,
});
}
};
Expand All @@ -148,8 +159,8 @@ function organizationPeople(): JSX.Element {
setPage(0);
};

const debouncedHandleFirstNameSearchChange = debounce(
handleFirstNameSearchChange
const debouncedHandleFullNameSearchChange = debounce(
handleFullNameSearchChange
);

return (
Expand All @@ -160,42 +171,17 @@ function organizationPeople(): JSX.Element {
<div className={styles.sidebar}>
<div className={styles.sidebarsticky}>
<h6 className={styles.searchtitle}>{t('filterByName')}</h6>
<Form.Control
type="name"
id="searchname"
placeholder={t('searchFirstName')}
autoComplete="off"
required
value={filterData.firstName_contains}
onChange={(e): void => {
const { value } = e.target;

const newFilterData = {
...filterData,
firstName_contains: value?.trim(),
};

setFilterData(newFilterData);
debouncedHandleFirstNameSearchChange(newFilterData);
}}
/>
<Form.Control
type="name"
id="searchLastName"
placeholder={t('searchLastName')}
placeholder={t('searchFullName')}
autoComplete="off"
required
value={filterData.lastName_contains}
value={fullName}
onChange={(e): void => {
const { value } = e.target;

const newFilterData = {
...filterData,
lastName_contains: value?.trim(),
};

setFilterData(newFilterData);
debouncedHandleFirstNameSearchChange(newFilterData);
setFullName(value);
debouncedHandleFullNameSearchChange(value);
}}
/>
<div
Expand Down

0 comments on commit d5b7d9f

Please sign in to comment.