Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted Tabs to Dropdown on Discord Users Page #873

Merged
merged 12 commits into from
Nov 21, 2024
6 changes: 2 additions & 4 deletions __tests__/users/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ describe('App Component', () => {
});

it('should update the URL query string and re-render the app', async () => {
await page.waitForSelector('[data_key="verified"]');

// Click on the "Linked Accounts" tab
await page.click('[data_key="verified"]');
await page.waitForSelector('[data-testid="tabs-section-select"]');
await page.select('[data-testid="tabs-section-select"]', 'verified');

// Get the current URL and make sure the query string has been updated
const url = await page.url();
Expand Down
4 changes: 2 additions & 2 deletions __tests__/users/applyFilterPagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ describe('Apply Filter and Pagination Functionality', () => {
});

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

// get the current URL
const url = await page.url();
Expand Down
6 changes: 3 additions & 3 deletions users/discord/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { NoUserFound } from './components/NoUserFound.js';
const { createElement, rerender } = react;

const tabs = [
{ display_name: 'In Discord', id: 'in_discord' },
{ display_name: 'Linked Accounts', id: 'verified' },
{ display_name: 'In Discord', id: 'in_discord', value: 'in_discord' },
{ display_name: 'Linked Accounts', id: 'verified', value: 'verified' },
];
export const usersData = {
in_discord: null,
Expand All @@ -22,7 +22,7 @@ let showUser = 0;
usersData[activeTab] = await getUsers(activeTab);

const handleTabNavigation = async (e) => {
const selectedTabId = e.target.getAttribute('data_key');
const selectedTabId = e.target.value;
if (selectedTabId) {
document.location.search = `tab=${selectedTabId}`;

Expand Down
10 changes: 6 additions & 4 deletions users/discord/components/TabsSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ const { createElement } = react;

export const TabsSection = ({ tabs, activeTab, handleTabNavigation }) => {
return createElement(
'div',
'select',
{
class: 'tabs_section',
onclick: handleTabNavigation,
'data-testid': 'tabs-section',
onchange: handleTabNavigation,
'data-testid': 'tabs-section-select',
},
tabs.map((tabItem) => {
return createElement(
'span',
'option',
{
data_key: `${tabItem.id}`,
class: `tab ${activeTab === tabItem.id ? 'active_tab' : ''}`,
value: `${tabItem.value}`,
...(activeTab === tabItem.id && { selected: 'true' }),
},
[tabItem.display_name],
);
Expand Down
8 changes: 6 additions & 2 deletions users/discord/style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
:root {
--light-gray: #d4d4d478;
--border-color-gray: #808080;
}

.header {
Expand All @@ -24,13 +25,16 @@ main {
}

.tabs_section {
padding: 1rem 0;
padding: 1rem;
margin: 1rem;
grid-area: tab;
width: 18rem;
border: 2px solid var(--border-color-gray);
font-size: unset;
}

.tab {
padding: 0.5rem;
padding: 1rem;
margin-inline-end: 0.5rem;
cursor: pointer;
}
Expand Down
3 changes: 2 additions & 1 deletion users/discord/utils/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const render = function (element, container) {
const component = document.createElement(element.tag);
element.props &&
Object.keys(element.props).forEach((prop) =>
prop == 'onclick' || prop == 'onsubmit'
// based on requirements, any other type of event listner can be added here as 'prop'
prop == 'onclick' || prop == 'onsubmit' || prop == 'onchange'
satyam73 marked this conversation as resolved.
Show resolved Hide resolved
? (component[prop] = element.props[prop])
: component.setAttribute(prop, element.props[prop]),
);
Expand Down
Loading