Skip to content

Commit

Permalink
Revert shared to v188; Undo dropdown helpers refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tsvetelinpetrov committed Oct 22, 2024
1 parent cb51404 commit 0b48008
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 12 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"prepare": "husky install"
},
"devDependencies": {
"@nordicsemiconductor/pc-nrfconnect-shared": "^189.0.0",
"@nordicsemiconductor/pc-nrfconnect-shared": "^188.0.0",
"ansi-escapes": "^4.3.2",
"serialport": "^10.5.0",
"xterm-addon-fit": "^0.8.0",
Expand Down
6 changes: 2 additions & 4 deletions src/components/Terminal/SerialSettings/Baudrate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@

import React from 'react';
import { useSelector } from 'react-redux';
import {
convertToNumberDropDownItems,
NumberInputWithDropdown,
} from '@nordicsemiconductor/pc-nrfconnect-shared';
import { NumberInputWithDropdown } from '@nordicsemiconductor/pc-nrfconnect-shared';
import type { AutoDetectTypes } from '@serialport/bindings-cpp';
import { SerialPortOpenOptions } from 'serialport';

import {
getSerialOptions,
getSerialPort,
} from '../../../features/terminal/terminalSlice';
import { convertToNumberDropDownItems } from '../../../utils/dataConstructors';

interface BaudRateProperties {
updateSerialPort: (
Expand Down
6 changes: 4 additions & 2 deletions src/components/Terminal/SerialSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import { useDispatch, useSelector } from 'react-redux';
import {
Button,
ConflictingSettingsDialog,
convertToDropDownItems,
createSerialPort,
Dropdown,
DropdownItem,
getSelectedDropdownItem,
Group,
logger,
persistSerialPortOptions,
Expand All @@ -33,6 +31,10 @@ import {
setShowOverwriteDialog,
updateSerialOptions,
} from '../../../features/terminal/terminalSlice';
import {
convertToDropDownItems,
getSelectedDropdownItem,
} from '../../../utils/dataConstructors';
import Baudrate from './Baudrate';

type Parity = 'none' | 'even' | 'mark' | 'odd' | 'space' | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Terminal/TerminalSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import React, { useEffect, useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
convertToDropDownItems,
Dropdown,
getPersistedTerminalSettings,
Group,
Expand All @@ -30,6 +29,7 @@ import {
setLineEnding,
setLineMode,
} from '../../../features/terminal/terminalSlice';
import { convertToDropDownItems } from '../../../utils/dataConstructors';
import ExportLog from './ExportLog';

export default () => {
Expand Down
46 changes: 46 additions & 0 deletions src/utils/dataConstructors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
*/

import {
DropdownItem,
NumberDropdownItem,
} from '@nordicsemiconductor/pc-nrfconnect-shared';

export const getSelectedDropdownItem = (
itemList: DropdownItem[],
value: unknown,
notFound?: DropdownItem
) => {
if (typeof value === 'boolean') value = value ? 'on' : 'off';

if (value === undefined) return notFound ?? itemList[0];

const result = itemList[itemList.findIndex(e => e.value === `${value}`)];

return result === undefined ? notFound ?? itemList[0] : result;
};

export const convertToDropDownItems: <T>(
data: T[],
addAuto?: boolean
) => DropdownItem[] = (data, addAuto = true) => {
const mappedData = data.map(v => ({
label: `${v}`,
value: `${v}`,
}));

return addAuto
? [{ label: 'Default', value: 'undefined' }, ...mappedData]
: mappedData;
};

export const convertToNumberDropDownItems: (
data: number[]
) => NumberDropdownItem[] = data =>
data.map(v => ({
label: `${v}`,
value: v,
}));

0 comments on commit 0b48008

Please sign in to comment.