mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00

* feat(lists): integrate Omegabrr * feat(lists): add missing lists index * feat(lists): add db repo * feat(lists): add db migrations * feat(lists): labels * feat(lists): url lists and more arrs * fix(lists): db migrations client_id wrong type * fix(lists): db fields * feat(lists): create list form wip * feat(lists): show in list and create * feat(lists): update and delete * feat(lists): trigger via webhook * feat(lists): add webhook handler * fix(arr): encode json to pointer * feat(lists): rename endpoint to lists * feat(lists): fetch tags from arr * feat(lists): process plaintext lists * feat(lists): add background refresh job * run every 6th hour with a random start delay between 1-35 seconds * feat(lists): refresh on save and improve logging * feat(lists): cast arr client to pointer * feat(lists): improve error handling * feat(lists): reset shows field with match release * feat(lists): filter opts all lists * feat(lists): trigger on update if enabled * feat(lists): update option for lists * feat(lists): show connected filters in list * feat(lists): missing listSvc dep * feat(lists): cleanup * feat(lists): typo arr list * feat(lists): radarr include original * feat(lists): rename ExcludeAlternateTitle to IncludeAlternateTitle * fix(lists): arr client type conversion to pointer * fix(actions): only log panic recover if err not nil * feat(lists): show spinner on save * feat(lists): show icon in filters list * feat(lists): change icon color in filters list * feat(lists): delete relations on filter delete
297 lines
9.6 KiB
TypeScript
297 lines
9.6 KiB
TypeScript
/*
|
|
* Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
import { JSX } from "react";
|
|
import { Field } from "formik";
|
|
import Select from "react-select";
|
|
import CreatableSelect from "react-select/creatable";
|
|
import type { FieldProps } from "formik";
|
|
|
|
import { OptionBasicTyped } from "@domain/constants";
|
|
import * as common from "@components/inputs/common";
|
|
import { DocsTooltip } from "@components/tooltips/DocsTooltip";
|
|
import { MultiSelect as RMSC } from "react-multi-select-component";
|
|
import { MultiSelectOption } from "@components/inputs/select.tsx";
|
|
|
|
interface SelectFieldProps<T> {
|
|
name: string;
|
|
label: string;
|
|
help?: string;
|
|
placeholder?: string;
|
|
required?: boolean;
|
|
defaultValue?: OptionBasicTyped<T>;
|
|
tooltip?: JSX.Element;
|
|
options: OptionBasicTyped<T>[];
|
|
}
|
|
|
|
export function SelectFieldCreatable<T>({ name, label, help, placeholder, tooltip, options }: SelectFieldProps<T>) {
|
|
return (
|
|
<div className="space-y-1 p-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4">
|
|
<div>
|
|
<label
|
|
htmlFor={name}
|
|
className="block ml-px text-sm font-medium text-gray-900 dark:text-white sm:pt-2"
|
|
>
|
|
<div className="flex">
|
|
{tooltip ? (
|
|
<DocsTooltip label={label}>{tooltip}</DocsTooltip>
|
|
) : label}
|
|
</div>
|
|
</label>
|
|
</div>
|
|
<div className="sm:col-span-2">
|
|
<Field name={name} type="select">
|
|
{({
|
|
field,
|
|
form: { setFieldValue }
|
|
}: FieldProps) => (
|
|
<CreatableSelect
|
|
{...field}
|
|
id={name}
|
|
isClearable={true}
|
|
isSearchable={true}
|
|
components={{
|
|
Input: common.SelectInput,
|
|
Control: common.SelectControl,
|
|
Menu: common.SelectMenu,
|
|
Option: common.SelectOption,
|
|
IndicatorSeparator: common.IndicatorSeparator,
|
|
DropdownIndicator: common.DropdownIndicator
|
|
}}
|
|
placeholder={placeholder ?? "Choose an option"}
|
|
styles={{
|
|
singleValue: (base) => ({
|
|
...base,
|
|
color: "unset"
|
|
})
|
|
}}
|
|
theme={(theme) => ({
|
|
...theme,
|
|
spacing: {
|
|
...theme.spacing,
|
|
controlHeight: 30,
|
|
baseUnit: 2
|
|
}
|
|
})}
|
|
// value={field?.value ? field.value : options.find(o => o.value == field?.value)}
|
|
value={field?.value ? { value: field.value, label: field.value } : field.value}
|
|
onChange={(newValue: unknown) => {
|
|
if (newValue) {
|
|
setFieldValue(field.name, (newValue as { value: string }).value);
|
|
}
|
|
else {
|
|
setFieldValue(field.name, "")
|
|
}
|
|
}}
|
|
options={[...[...options, { value: field.value, label: field.value }].reduce((map, obj) => map.set(obj.value, obj), new Map()).values()]}
|
|
/>
|
|
)}
|
|
</Field>
|
|
{help && (
|
|
<p className="mt-2 text-sm text-gray-500" id={`${name}-description`}>{help}</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function SelectField<T>({ name, label, help, placeholder, options }: SelectFieldProps<T>) {
|
|
return (
|
|
<div className="space-y-1 p-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4">
|
|
<div>
|
|
<label
|
|
htmlFor={name}
|
|
className="block ml-px text-sm font-medium text-gray-900 dark:text-white sm:pt-2"
|
|
>
|
|
{label}
|
|
</label>
|
|
</div>
|
|
<div className="sm:col-span-2">
|
|
<Field name={name} type="select">
|
|
{({
|
|
field,
|
|
form: { setFieldValue }
|
|
}: FieldProps) => (
|
|
<Select
|
|
{...field}
|
|
id={name}
|
|
components={{
|
|
Input: common.SelectInput,
|
|
Control: common.SelectControl,
|
|
Menu: common.SelectMenu,
|
|
Option: common.SelectOption,
|
|
IndicatorSeparator: common.IndicatorSeparator,
|
|
DropdownIndicator: common.DropdownIndicator
|
|
}}
|
|
placeholder={placeholder ?? "Choose an option"}
|
|
styles={{
|
|
singleValue: (base) => ({
|
|
...base,
|
|
color: "unset"
|
|
})
|
|
}}
|
|
theme={(theme) => ({
|
|
...theme,
|
|
spacing: {
|
|
...theme.spacing,
|
|
controlHeight: 30,
|
|
baseUnit: 2
|
|
}
|
|
})}
|
|
// value={field?.value ? field.value : options.find(o => o.value == field?.value)}
|
|
value={field?.value ? { value: field.value, label: field.value } : field.value}
|
|
onChange={(newValue: unknown) => {
|
|
if (newValue) {
|
|
setFieldValue(field.name, (newValue as { value: string }).value);
|
|
}
|
|
else {
|
|
setFieldValue(field.name, "")
|
|
}
|
|
}}
|
|
options={[...[...options, { value: field.value, label: field.value }].reduce((map, obj) => map.set(obj.value, obj), new Map()).values()]}
|
|
/>
|
|
)}
|
|
</Field>
|
|
{help && (
|
|
<p className="mt-2 text-sm text-gray-500" id={`${name}-description`}>{help}</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function SelectFieldBasic<T>({ name, label, help, placeholder, required, tooltip, defaultValue, options }: SelectFieldProps<T>) {
|
|
return (
|
|
<div className="space-y-1 p-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4">
|
|
<div>
|
|
<label
|
|
htmlFor={name}
|
|
className="block ml-px text-sm font-medium text-gray-900 dark:text-white sm:pt-2"
|
|
>
|
|
<div className="flex">
|
|
{tooltip ? (
|
|
<DocsTooltip label={label}>{tooltip}</DocsTooltip>
|
|
) : label}
|
|
</div>
|
|
</label>
|
|
</div>
|
|
<div className="sm:col-span-2">
|
|
<Field name={name} type="select">
|
|
{({
|
|
field,
|
|
form: { setFieldValue }
|
|
}: FieldProps) => (
|
|
<Select
|
|
{...field}
|
|
id={name}
|
|
required={required}
|
|
components={{
|
|
Input: common.SelectInput,
|
|
Control: common.SelectControl,
|
|
Menu: common.SelectMenu,
|
|
Option: common.SelectOption,
|
|
IndicatorSeparator: common.IndicatorSeparator,
|
|
DropdownIndicator: common.DropdownIndicator
|
|
}}
|
|
placeholder={placeholder ?? "Choose an option"}
|
|
styles={{
|
|
singleValue: (base) => ({
|
|
...base,
|
|
color: "unset"
|
|
})
|
|
}}
|
|
theme={(theme) => ({
|
|
...theme,
|
|
spacing: {
|
|
...theme.spacing,
|
|
controlHeight: 30,
|
|
baseUnit: 2
|
|
}
|
|
})}
|
|
defaultValue={defaultValue}
|
|
value={field?.value && options.find(o => o.value == field?.value)}
|
|
onChange={(newValue: unknown) => {
|
|
if (newValue) {
|
|
setFieldValue(field.name, (newValue as { value: string }).value);
|
|
}
|
|
else {
|
|
setFieldValue(field.name, "")
|
|
}
|
|
}}
|
|
options={options}
|
|
/>
|
|
)}
|
|
</Field>
|
|
{help && (
|
|
<p className="mt-2 text-sm text-gray-500" id={`${name}-description`}>{help}</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export interface MultiSelectFieldProps {
|
|
name: string;
|
|
label: string;
|
|
help?: string;
|
|
placeholder?: string;
|
|
required?: boolean;
|
|
tooltip?: JSX.Element;
|
|
options: OptionBasicTyped<number>[];
|
|
}
|
|
|
|
interface ListFilterMultiSelectOption {
|
|
id: number;
|
|
name: string;
|
|
}
|
|
|
|
export function ListFilterMultiSelectField({ name, label, help, tooltip, options }: MultiSelectFieldProps) {
|
|
return (
|
|
<div className="flex items-center space-y-1 p-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4">
|
|
<div>
|
|
<label
|
|
htmlFor={name}
|
|
className="block ml-px text-sm font-medium text-gray-900 dark:text-white"
|
|
>
|
|
<div className="flex">
|
|
{tooltip ? (
|
|
<DocsTooltip label={label}>{tooltip}</DocsTooltip>
|
|
) : label}
|
|
</div>
|
|
</label>
|
|
</div>
|
|
<div className="sm:col-span-2">
|
|
<Field name={name} type="select">
|
|
{({
|
|
field,
|
|
form: { setFieldValue }
|
|
}: FieldProps) => (
|
|
<>
|
|
<RMSC
|
|
{...field}
|
|
options={options}
|
|
// disabled={disabled}
|
|
labelledBy={name}
|
|
// isCreatable={creatable}
|
|
// onCreateOption={handleNewField}
|
|
value={field.value && field.value.map((item: ListFilterMultiSelectOption) => ({
|
|
value: item.id,
|
|
label: item.name
|
|
}))}
|
|
onChange={(values: MultiSelectOption[]) => {
|
|
const item = values && values.map((i) => ({ id: i.value, name: i.label }));
|
|
setFieldValue(field.name, item);
|
|
}}
|
|
/>
|
|
</>
|
|
)}
|
|
</Field>
|
|
{help && (
|
|
<p className="mt-2 text-sm text-gray-500" id={`${name}-description`}>{help}</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|