mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 21:04:37 +03:00
Fix empty strings overwriting during scrape (#3647)
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
|||||||
ScrapedInputGroupRow,
|
ScrapedInputGroupRow,
|
||||||
ScrapedTextAreaRow,
|
ScrapedTextAreaRow,
|
||||||
ScrapeResult,
|
ScrapeResult,
|
||||||
|
ZeroableScrapeResult,
|
||||||
} from "../Shared/ScrapeDialog";
|
} from "../Shared/ScrapeDialog";
|
||||||
import { clone, uniq } from "lodash-es";
|
import { clone, uniq } from "lodash-es";
|
||||||
import {
|
import {
|
||||||
@@ -65,8 +66,9 @@ const SceneMergeDetails: React.FC<ISceneMergeDetailsProps> = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const [rating, setRating] = useState(
|
const [rating, setRating] = useState(
|
||||||
new ScrapeResult<number>(dest.rating100)
|
new ZeroableScrapeResult<number>(dest.rating100)
|
||||||
);
|
);
|
||||||
|
// zero values can be treated as missing for these fields
|
||||||
const [oCounter, setOCounter] = useState(
|
const [oCounter, setOCounter] = useState(
|
||||||
new ScrapeResult<number>(dest.o_counter)
|
new ScrapeResult<number>(dest.o_counter)
|
||||||
);
|
);
|
||||||
@@ -118,7 +120,7 @@ const SceneMergeDetails: React.FC<ISceneMergeDetailsProps> = ({
|
|||||||
const [stashIDs, setStashIDs] = useState(new ScrapeResult<GQL.StashId[]>([]));
|
const [stashIDs, setStashIDs] = useState(new ScrapeResult<GQL.StashId[]>([]));
|
||||||
|
|
||||||
const [organized, setOrganized] = useState(
|
const [organized, setOrganized] = useState(
|
||||||
new ScrapeResult<boolean>(dest.organized)
|
new ZeroableScrapeResult<boolean>(dest.organized)
|
||||||
);
|
);
|
||||||
|
|
||||||
const [image, setImage] = useState<ScrapeResult<string>>(
|
const [image, setImage] = useState<ScrapeResult<string>>(
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ export class ScrapeResult<T> {
|
|||||||
) {
|
) {
|
||||||
this.originalValue = originalValue ?? undefined;
|
this.originalValue = originalValue ?? undefined;
|
||||||
this.newValue = newValue ?? undefined;
|
this.newValue = newValue ?? undefined;
|
||||||
const hasNewValue = this.newValue !== undefined;
|
// NOTE: this means that zero values are treated as null
|
||||||
|
// this is incorrect for numbers and booleans, but correct for strings
|
||||||
|
const hasNewValue = !!this.newValue;
|
||||||
|
|
||||||
const valuesEqual = isEqual(originalValue, newValue);
|
const valuesEqual = isEqual(originalValue, newValue);
|
||||||
this.useNewValue = useNewValue ?? (hasNewValue && !valuesEqual);
|
this.useNewValue = useNewValue ?? (hasNewValue && !valuesEqual);
|
||||||
@@ -68,6 +70,23 @@ export class ScrapeResult<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for types where !!value is a valid value (boolean and number)
|
||||||
|
export class ZeroableScrapeResult<T> extends ScrapeResult<T> {
|
||||||
|
public constructor(
|
||||||
|
originalValue?: T | null,
|
||||||
|
newValue?: T | null,
|
||||||
|
useNewValue?: boolean
|
||||||
|
) {
|
||||||
|
super(originalValue, newValue, useNewValue);
|
||||||
|
|
||||||
|
const hasNewValue = this.newValue !== undefined;
|
||||||
|
|
||||||
|
const valuesEqual = isEqual(originalValue, newValue);
|
||||||
|
this.useNewValue = useNewValue ?? (hasNewValue && !valuesEqual);
|
||||||
|
this.scraped = hasNewValue && !valuesEqual;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export function hasScrapedValues(values: ScrapeResult<any>[]) {
|
export function hasScrapedValues(values: ScrapeResult<any>[]) {
|
||||||
return values.some((r) => r.scraped);
|
return values.some((r) => r.scraped);
|
||||||
|
|||||||
Reference in New Issue
Block a user