mirror of
https://github.com/Radarr/Radarr
synced 2025-12-06 08:28:50 +01:00
Improve typings for select options
This commit is contained in:
parent
9ef7c2a0b4
commit
3a55316ada
4 changed files with 44 additions and 44 deletions
|
|
@ -1,13 +1,10 @@
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import AvailabilitySelectInput from 'Components/Form/Select/AvailabilitySelectInput';
|
import FormInputGroup from 'Components/Form/FormInputGroup';
|
||||||
import QualityProfileSelectInput from 'Components/Form/Select/QualityProfileSelectInput';
|
|
||||||
import RootFolderSelectInput from 'Components/Form/Select/RootFolderSelectInput';
|
|
||||||
import SelectInput from 'Components/Form/SelectInput';
|
|
||||||
import SpinnerButton from 'Components/Link/SpinnerButton';
|
import SpinnerButton from 'Components/Link/SpinnerButton';
|
||||||
import PageContentFooter from 'Components/Page/PageContentFooter';
|
import PageContentFooter from 'Components/Page/PageContentFooter';
|
||||||
import { kinds } from 'Helpers/Props';
|
import { inputTypes, kinds } from 'Helpers/Props';
|
||||||
import translate from 'Utilities/String/translate';
|
import translate from 'Utilities/String/translate';
|
||||||
import CollectionFooterLabel from './CollectionFooterLabel';
|
import CollectionFooterLabel from './CollectionFooterLabel';
|
||||||
import styles from './CollectionFooter.css';
|
import styles from './CollectionFooter.css';
|
||||||
|
|
@ -19,8 +16,7 @@ const monitoredOptions = [
|
||||||
key: NO_CHANGE,
|
key: NO_CHANGE,
|
||||||
get value() {
|
get value() {
|
||||||
return translate('NoChange');
|
return translate('NoChange');
|
||||||
},
|
}
|
||||||
isDisabled: true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'monitored',
|
key: 'monitored',
|
||||||
|
|
@ -41,8 +37,7 @@ const searchOnAddOptions = [
|
||||||
key: NO_CHANGE,
|
key: NO_CHANGE,
|
||||||
get value() {
|
get value() {
|
||||||
return translate('NoChange');
|
return translate('NoChange');
|
||||||
},
|
}
|
||||||
isDisabled: true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'yes',
|
key: 'yes',
|
||||||
|
|
@ -173,7 +168,8 @@ class CollectionFooter extends Component {
|
||||||
isSaving={isSaving && monitored !== NO_CHANGE}
|
isSaving={isSaving && monitored !== NO_CHANGE}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SelectInput
|
<FormInputGroup
|
||||||
|
type={inputTypes.SELECT}
|
||||||
name="monitored"
|
name="monitored"
|
||||||
value={monitored}
|
value={monitored}
|
||||||
values={monitoredOptions}
|
values={monitoredOptions}
|
||||||
|
|
@ -188,7 +184,8 @@ class CollectionFooter extends Component {
|
||||||
isSaving={isSaving && monitor !== NO_CHANGE}
|
isSaving={isSaving && monitor !== NO_CHANGE}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SelectInput
|
<FormInputGroup
|
||||||
|
type={inputTypes.SELECT}
|
||||||
name="monitor"
|
name="monitor"
|
||||||
value={monitor}
|
value={monitor}
|
||||||
values={monitoredOptions}
|
values={monitoredOptions}
|
||||||
|
|
@ -203,10 +200,12 @@ class CollectionFooter extends Component {
|
||||||
isSaving={isSaving && qualityProfileId !== NO_CHANGE}
|
isSaving={isSaving && qualityProfileId !== NO_CHANGE}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<QualityProfileSelectInput
|
<FormInputGroup
|
||||||
|
type={inputTypes.QUALITY_PROFILE_SELECT}
|
||||||
name="qualityProfileId"
|
name="qualityProfileId"
|
||||||
value={qualityProfileId}
|
value={qualityProfileId}
|
||||||
includeNoChange={true}
|
includeNoChange={true}
|
||||||
|
includeNoChangeDisabled={false}
|
||||||
isDisabled={!selectedCount}
|
isDisabled={!selectedCount}
|
||||||
onChange={this.onInputChange}
|
onChange={this.onInputChange}
|
||||||
/>
|
/>
|
||||||
|
|
@ -218,10 +217,12 @@ class CollectionFooter extends Component {
|
||||||
isSaving={isSaving && minimumAvailability !== NO_CHANGE}
|
isSaving={isSaving && minimumAvailability !== NO_CHANGE}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<AvailabilitySelectInput
|
<FormInputGroup
|
||||||
|
type={inputTypes.AVAILABILITY_SELECT}
|
||||||
name="minimumAvailability"
|
name="minimumAvailability"
|
||||||
value={minimumAvailability}
|
value={minimumAvailability}
|
||||||
includeNoChange={true}
|
includeNoChange={true}
|
||||||
|
includeNoChangeDisabled={false}
|
||||||
isDisabled={!selectedCount}
|
isDisabled={!selectedCount}
|
||||||
onChange={this.onInputChange}
|
onChange={this.onInputChange}
|
||||||
/>
|
/>
|
||||||
|
|
@ -233,12 +234,14 @@ class CollectionFooter extends Component {
|
||||||
isSaving={isSaving && rootFolderPath !== NO_CHANGE}
|
isSaving={isSaving && rootFolderPath !== NO_CHANGE}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<RootFolderSelectInput
|
<FormInputGroup
|
||||||
|
type={inputTypes.ROOT_FOLDER_SELECT}
|
||||||
name="rootFolderPath"
|
name="rootFolderPath"
|
||||||
value={rootFolderPath}
|
value={rootFolderPath}
|
||||||
includeNoChange={true}
|
includeNoChange={true}
|
||||||
isDisabled={!selectedCount}
|
includeNoChangeDisabled={false}
|
||||||
selectedValueOptions={{ includeFreeSpace: false }}
|
selectedValueOptions={{ includeFreeSpace: false }}
|
||||||
|
isDisabled={!selectedCount}
|
||||||
onChange={this.onInputChange}
|
onChange={this.onInputChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -249,7 +252,8 @@ class CollectionFooter extends Component {
|
||||||
isSaving={isSaving && searchOnAdd !== NO_CHANGE}
|
isSaving={isSaving && searchOnAdd !== NO_CHANGE}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SelectInput
|
<FormInputGroup
|
||||||
|
type={inputTypes.SELECT}
|
||||||
name="searchOnAdd"
|
name="searchOnAdd"
|
||||||
value={searchOnAdd}
|
value={searchOnAdd}
|
||||||
values={searchOnAddOptions}
|
values={searchOnAddOptions}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import React, { ChangeEvent, SyntheticEvent, useCallback } from 'react';
|
import React, {
|
||||||
|
ChangeEvent,
|
||||||
|
ComponentProps,
|
||||||
|
SyntheticEvent,
|
||||||
|
useCallback,
|
||||||
|
} from 'react';
|
||||||
import { InputChanged } from 'typings/inputs';
|
import { InputChanged } from 'typings/inputs';
|
||||||
import styles from './SelectInput.css';
|
import styles from './SelectInput.css';
|
||||||
|
|
||||||
interface SelectInputOption {
|
export interface SelectInputOption
|
||||||
key: string;
|
extends Pick<ComponentProps<'option'>, 'disabled'> {
|
||||||
|
key: string | number;
|
||||||
value: string | number | (() => string | number);
|
value: string | number | (() => string | number);
|
||||||
isDisabled?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SelectInputProps<T> {
|
interface SelectInputProps<T> {
|
||||||
|
|
@ -62,20 +67,10 @@ function SelectInput<T>({
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
>
|
>
|
||||||
{values.map((option) => {
|
{values.map((option) => {
|
||||||
const {
|
const { key, value: optionValue, ...otherOptionProps } = option;
|
||||||
key,
|
|
||||||
value: optionValue,
|
|
||||||
isDisabled: optionIsDisabled = false,
|
|
||||||
...otherOptionProps
|
|
||||||
} = option;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<option
|
<option key={key} value={key} {...otherOptionProps}>
|
||||||
key={key}
|
|
||||||
value={key}
|
|
||||||
disabled={optionIsDisabled}
|
|
||||||
{...otherOptionProps}
|
|
||||||
>
|
|
||||||
{typeof optionValue === 'function' ? optionValue() : optionValue}
|
{typeof optionValue === 'function' ? optionValue() : optionValue}
|
||||||
</option>
|
</option>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,10 @@ import _ from 'lodash';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import CheckInput from 'Components/Form/CheckInput';
|
import CheckInput from 'Components/Form/CheckInput';
|
||||||
import AvailabilitySelectInput from 'Components/Form/Select/AvailabilitySelectInput';
|
import FormInputGroup from 'Components/Form/FormInputGroup';
|
||||||
import QualityProfileSelectInput from 'Components/Form/Select/QualityProfileSelectInput';
|
|
||||||
import RootFolderSelectInput from 'Components/Form/Select/RootFolderSelectInput';
|
|
||||||
import SelectInput from 'Components/Form/SelectInput';
|
|
||||||
import SpinnerButton from 'Components/Link/SpinnerButton';
|
import SpinnerButton from 'Components/Link/SpinnerButton';
|
||||||
import PageContentFooter from 'Components/Page/PageContentFooter';
|
import PageContentFooter from 'Components/Page/PageContentFooter';
|
||||||
import { kinds } from 'Helpers/Props';
|
import { inputTypes, kinds } from 'Helpers/Props';
|
||||||
import monitorOptions from 'Utilities/Movie/monitorOptions';
|
import monitorOptions from 'Utilities/Movie/monitorOptions';
|
||||||
import translate from 'Utilities/String/translate';
|
import translate from 'Utilities/String/translate';
|
||||||
import DiscoverMovieFooterLabel from './DiscoverMovieFooterLabel';
|
import DiscoverMovieFooterLabel from './DiscoverMovieFooterLabel';
|
||||||
|
|
@ -146,7 +143,8 @@ class DiscoverMovieFooter extends Component {
|
||||||
isSaving={isAdding}
|
isSaving={isAdding}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SelectInput
|
<FormInputGroup
|
||||||
|
type={inputTypes.SELECT}
|
||||||
name="monitor"
|
name="monitor"
|
||||||
value={monitor}
|
value={monitor}
|
||||||
values={monitorOptions}
|
values={monitorOptions}
|
||||||
|
|
@ -161,7 +159,8 @@ class DiscoverMovieFooter extends Component {
|
||||||
isSaving={isAdding}
|
isSaving={isAdding}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<QualityProfileSelectInput
|
<FormInputGroup
|
||||||
|
type={inputTypes.QUALITY_PROFILE_SELECT}
|
||||||
name="qualityProfileId"
|
name="qualityProfileId"
|
||||||
value={qualityProfileId}
|
value={qualityProfileId}
|
||||||
isDisabled={!selectedCount}
|
isDisabled={!selectedCount}
|
||||||
|
|
@ -175,7 +174,8 @@ class DiscoverMovieFooter extends Component {
|
||||||
isSaving={isAdding}
|
isSaving={isAdding}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<AvailabilitySelectInput
|
<FormInputGroup
|
||||||
|
type={inputTypes.AVAILABILITY_SELECT}
|
||||||
name="minimumAvailability"
|
name="minimumAvailability"
|
||||||
value={minimumAvailability}
|
value={minimumAvailability}
|
||||||
isDisabled={!selectedCount}
|
isDisabled={!selectedCount}
|
||||||
|
|
@ -189,7 +189,8 @@ class DiscoverMovieFooter extends Component {
|
||||||
isSaving={isAdding}
|
isSaving={isAdding}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<RootFolderSelectInput
|
<FormInputGroup
|
||||||
|
type={inputTypes.ROOT_FOLDER_SELECT}
|
||||||
name="rootFolderPath"
|
name="rootFolderPath"
|
||||||
value={rootFolderPath}
|
value={rootFolderPath}
|
||||||
isDisabled={!selectedCount}
|
isDisabled={!selectedCount}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { createSelector } from 'reselect';
|
||||||
import AppState from 'App/State/AppState';
|
import AppState from 'App/State/AppState';
|
||||||
import InteractiveImportAppState from 'App/State/InteractiveImportAppState';
|
import InteractiveImportAppState from 'App/State/InteractiveImportAppState';
|
||||||
import * as commandNames from 'Commands/commandNames';
|
import * as commandNames from 'Commands/commandNames';
|
||||||
import SelectInput from 'Components/Form/SelectInput';
|
import SelectInput, { SelectInputOption } from 'Components/Form/SelectInput';
|
||||||
import Icon from 'Components/Icon';
|
import Icon from 'Components/Icon';
|
||||||
import Button from 'Components/Link/Button';
|
import Button from 'Components/Link/Button';
|
||||||
import SpinnerButton from 'Components/Link/SpinnerButton';
|
import SpinnerButton from 'Components/Link/SpinnerButton';
|
||||||
|
|
@ -141,7 +141,7 @@ const COLUMNS = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const importModeOptions = [
|
const importModeOptions: SelectInputOption[] = [
|
||||||
{
|
{
|
||||||
key: 'chooseImportMode',
|
key: 'chooseImportMode',
|
||||||
value: () => translate('ChooseImportMode'),
|
value: () => translate('ChooseImportMode'),
|
||||||
|
|
@ -289,7 +289,7 @@ function InteractiveImportModalContent(
|
||||||
}, [selectedState]);
|
}, [selectedState]);
|
||||||
|
|
||||||
const bulkSelectOptions = useMemo(() => {
|
const bulkSelectOptions = useMemo(() => {
|
||||||
const options = [
|
const options: SelectInputOption[] = [
|
||||||
{
|
{
|
||||||
key: 'select',
|
key: 'select',
|
||||||
value: translate('SelectDropdown'),
|
value: translate('SelectDropdown'),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue