Fix tag selector in scrape dialogs (#4526)

This commit is contained in:
WithoutPants
2024-02-06 10:26:16 +11:00
committed by GitHub
parent 3ea31aeb76
commit 217c02f181
8 changed files with 93 additions and 98 deletions

View File

@@ -1,16 +1,13 @@
import React, { useMemo } from "react";
import * as GQL from "src/core/generated-graphql";
import {
MovieSelect,
TagSelect,
StudioSelect,
} from "src/components/Shared/Select";
import { MovieSelect, StudioSelect } from "src/components/Shared/Select";
import {
ScrapeDialogRow,
IHasName,
} from "src/components/Shared/ScrapeDialog/ScrapeDialog";
import { PerformerSelect } from "src/components/Performers/PerformerSelect";
import { ScrapeResult } from "src/components/Shared/ScrapeDialog/scrapeResult";
import { TagSelect } from "src/components/Tags/TagSelect";
interface IScrapedStudioRow {
title: string;
@@ -230,35 +227,45 @@ export const ScrapedMoviesRow: React.FC<
};
export const ScrapedTagsRow: React.FC<
IScrapedObjectRowImpl<GQL.ScrapedTag, string>
IScrapedObjectRowImpl<GQL.ScrapedTag, GQL.ScrapedTag>
> = ({ title, result, onChange, newObjects, onCreateNew }) => {
function renderScrapedTags(
scrapeResult: ScrapeResult<string[]>,
scrapeResult: ScrapeResult<GQL.ScrapedTag[]>,
isNew?: boolean,
onChangeFn?: (value: string[]) => void
onChangeFn?: (value: GQL.ScrapedTag[]) => void
) {
const resultValue = isNew
? scrapeResult.newValue
: scrapeResult.originalValue;
const value = resultValue ?? [];
const selectValue = value.map((p) => {
const aliases: string[] = [];
return {
id: p.stored_id ?? "",
name: p.name ?? "",
aliases,
};
});
return (
<TagSelect
isMulti
className="form-control react-select"
className="form-control"
isDisabled={!isNew}
onSelect={(items) => {
if (onChangeFn) {
onChangeFn(items.map((i) => i.id));
// map the id back to stored_id
onChangeFn(items.map((p) => ({ ...p, stored_id: p.id })));
}
}}
ids={value}
values={selectValue}
/>
);
}
return (
<ScrapedObjectsRow<GQL.ScrapedTag, string>
<ScrapedObjectsRow<GQL.ScrapedTag, GQL.ScrapedTag>
title={title}
result={result}
renderObjects={renderScrapedTags}