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

edit duplicate variable name #1354

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions desktop-app/src/renderer/components/DeviceManager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import {
import { APP_VIEWS, setAppView } from 'renderer/store/features/ui';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR, please follow the following structure:

  • Make a file named DeviceManager.tsx for this file
  • In the index.tsx file just do export { DeviceManager } from './DeviceManager -> this acts as a export hub for anything you need to export
  • Create separate file components for the lines of code I am commenting below

import { defaultDevices, Device, getDevicesMap } from 'common/deviceList';

import cx from 'classnames';
import Button from '../Button';
import DeviceLabel from './DeviceLabel';
import DeviceDetailsModal from './DeviceDetailsModal';
import { PreviewSuites } from './PreviewSuites';
import { ManageSuitesTool } from './PreviewSuites/ManageSuitesTool/ManageSuitesTool';
import { Divider } from '../Divider';
import { AccordionItem, Accordion } from '../Accordion';
import { DropDown } from '../DropDown';

const filterDevices = (devices: Device[], filter: string) => {
const sanitizedFilter = filter.trim().toLowerCase();
Expand All @@ -38,18 +40,28 @@ const DeviceManager = () => {
const activeSuite = useSelector(selectActiveSuite);
const devices = activeSuite.devices?.map((id) => getDevicesMap()[id]);
const [searchText, setSearchText] = useState<string>('');
const [filteredType, setFilteredType] = useState<string | null>(null);
const [filteredDevices, setFilteredDevices] =
useState<Device[]>(defaultDevices);
const [customDevices, setCustomDevices] = useState<Device[]>(
window.electron.store.get('deviceManager.customDevices')
);
const [filteredCustomDevices, setFilteredCustomDevices] =
useState<Device[]>(customDevices);
const deviceTypes = Array.from(
new Set(defaultDevices.map((device) => device.type))
);

useEffect(() => {
setFilteredDevices(filterDevices(defaultDevices, searchText));
setFilteredCustomDevices(filterDevices(customDevices, searchText));
}, [customDevices, searchText]);
const filtered = filterDevices(defaultDevices, searchText).filter(
(device) => (filteredType ? device.type === filteredType : true)
);
const filteredCustom = filterDevices(customDevices, searchText).filter(
(device) => (filteredType ? device.type === filteredType : true)
);
setFilteredDevices(filtered);
setFilteredCustomDevices(filteredCustom);
}, [customDevices, searchText, filteredType]);

const saveCustomDevices = (newCustomDevices: Device[]) => {
setCustomDevices(newCustomDevices);
Expand Down Expand Up @@ -111,6 +123,50 @@ const DeviceManager = () => {
<div className="flex w-fit flex-col items-start px-1">
<h2 className="text-2xl font-bold">Manage Devices</h2>
</div>
<div>
<DropDown
label={
<div className="flex items-center gap-2">
<Icon icon="mdi:devices" fontSize={18} />
<span>Device Type</span>
</div>
}
options={[
{
label: (
<div className="flex items-center gap-2">
{filteredType === null && <Icon icon="mdi:check" />}
<span
className={cx('capitalize', {
'font-semibold text-black dark:text-white':
filteredType === null,
})}
>
All Device Types
</span>
</div>
),
onClick: () => setFilteredType(null),
},
...deviceTypes.map((type) => ({
label: (
<div className="flex items-center gap-2">
{filteredType === type && <Icon icon="mdi:check" />}
<span
className={cx('capitalize', {
'font-semibold text-black dark:text-white':
filteredType === type,
})}
>
{type}
</span>
</div>
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as the lines 137 to 147, please refactor into a reusable separate component. You could call it DeviceManagerLabel if you'd like, and pass props to it to handle variations

onClick: () => setFilteredType(type),
})),
]}
/>
</div>
<div className="flex w-fit items-center bg-white px-1 dark:bg-slate-900">
<Icon icon="ic:outline-search" height={24} />
<input
Expand Down
Loading