Skip to content

Commit 2629ec5

Browse files
DepayanMondalDepayan MondalAchintya-Chatterjeesatyam73
authored
Converted Tabs to Dropdown on Discord Users Page (#873)
* added dropdown * draft: add dropdown on discord user page to combine 'linked account' and 'n discord' buttons * added dropdown in the discord users page * Added dropdown option in the Discord Users page * used data test id for the tests and variable for css * added a comment on react.js for future convenience --------- Co-authored-by: Depayan Mondal <[email protected]> Co-authored-by: Achintya Chatterjee <[email protected]> Co-authored-by: Satyam Bajpai <[email protected]>
1 parent 66d8f37 commit 2629ec5

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

__tests__/users/App.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ describe('App Component', () => {
9393
});
9494

9595
it('should update the URL query string and re-render the app', async () => {
96-
await page.waitForSelector('[data_key="verified"]');
97-
98-
// Click on the "Linked Accounts" tab
99-
await page.click('[data_key="verified"]');
96+
await page.waitForSelector('[data-testid="tabs-section-select"]');
97+
await page.select('[data-testid="tabs-section-select"]', 'verified');
10098

10199
// Get the current URL and make sure the query string has been updated
102100
const url = await page.url();

__tests__/users/applyFilterPagination.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ describe('Apply Filter and Pagination Functionality', () => {
7878
});
7979

8080
it('should update the URL query string when applying filters', async () => {
81-
// click on the "Verified" tab
82-
await page.click('[data_key="verified"]');
81+
await page.waitForSelector('[data-testid="tabs-section-select"]');
82+
await page.select('[data-testid="tabs-section-select"]', 'verified');
8383

8484
// get the current URL
8585
const url = await page.url();

users/discord/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { NoUserFound } from './components/NoUserFound.js';
77
const { createElement, rerender } = react;
88

99
const tabs = [
10-
{ display_name: 'In Discord', id: 'in_discord' },
11-
{ display_name: 'Linked Accounts', id: 'verified' },
10+
{ display_name: 'In Discord', id: 'in_discord', value: 'in_discord' },
11+
{ display_name: 'Linked Accounts', id: 'verified', value: 'verified' },
1212
];
1313
export const usersData = {
1414
in_discord: null,
@@ -22,7 +22,7 @@ let showUser = 0;
2222
usersData[activeTab] = await getUsers(activeTab);
2323

2424
const handleTabNavigation = async (e) => {
25-
const selectedTabId = e.target.getAttribute('data_key');
25+
const selectedTabId = e.target.value;
2626
if (selectedTabId) {
2727
document.location.search = `tab=${selectedTabId}`;
2828

users/discord/components/TabsSection.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ const { createElement } = react;
22

33
export const TabsSection = ({ tabs, activeTab, handleTabNavigation }) => {
44
return createElement(
5-
'div',
5+
'select',
66
{
77
class: 'tabs_section',
8-
onclick: handleTabNavigation,
9-
'data-testid': 'tabs-section',
8+
onchange: handleTabNavigation,
9+
'data-testid': 'tabs-section-select',
1010
},
1111
tabs.map((tabItem) => {
1212
return createElement(
13-
'span',
13+
'option',
1414
{
1515
data_key: `${tabItem.id}`,
1616
class: `tab ${activeTab === tabItem.id ? 'active_tab' : ''}`,
17+
value: `${tabItem.value}`,
18+
...(activeTab === tabItem.id && { selected: 'true' }),
1719
},
1820
[tabItem.display_name],
1921
);

users/discord/style.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
:root {
22
--light-gray: #d4d4d478;
3+
--border-color-gray: #808080;
34
}
45

56
.header {
@@ -24,13 +25,16 @@ main {
2425
}
2526

2627
.tabs_section {
27-
padding: 1rem 0;
28+
padding: 1rem;
2829
margin: 1rem;
2930
grid-area: tab;
31+
width: 18rem;
32+
border: 2px solid var(--border-color-gray);
33+
font-size: unset;
3034
}
3135

3236
.tab {
33-
padding: 0.5rem;
37+
padding: 1rem;
3438
margin-inline-end: 0.5rem;
3539
cursor: pointer;
3640
}

users/discord/utils/react.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const render = function (element, container) {
88
const component = document.createElement(element.tag);
99
element.props &&
1010
Object.keys(element.props).forEach((prop) =>
11-
prop == 'onclick' || prop == 'onsubmit'
11+
// based on requirements, any other type of event listner can be added here as 'prop'
12+
prop == 'onclick' || prop == 'onsubmit' || prop == 'onchange'
1213
? (component[prop] = element.props[prop])
1314
: component.setAttribute(prop, element.props[prop]),
1415
);

0 commit comments

Comments
 (0)