Skip to content

Commit

Permalink
Fix error when viewing scenes related to objects with illegal charact…
Browse files Browse the repository at this point in the history
…ers in name (#395)

* Fix gitattributes for v2.5
  • Loading branch information
WithoutPants authored Mar 13, 2020
1 parent 6f5f311 commit 1a6374f
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
go.mod text eol=lf
go.sum text eol=lf
ui/v2.5/** -text
ui/v2.5/**/*.ts* text eol=lf
4 changes: 1 addition & 3 deletions ui/v2.5/src/components/Scenes/SceneDetails/Scene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ export const Scene: React.FC = () => {
/>
</Tab>
<Tab eventKey="scene-operations-panel" title="Operations">
<SceneOperationsPanel
scene={scene}
/>
<SceneOperationsPanel scene={scene} />
</Tab>
</Tabs>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ interface IOperationsPanelProps {
scene: GQL.SceneDataFragment;
}

export const SceneOperationsPanel: FunctionComponent<IOperationsPanelProps> = (props: IOperationsPanelProps) => {
export const SceneOperationsPanel: FunctionComponent<IOperationsPanelProps> = (
props: IOperationsPanelProps
) => {
const Toast = useToast();
const [generateScreenshot] = StashService.useSceneGenerateScreenshot();

Expand All @@ -25,7 +27,10 @@ export const SceneOperationsPanel: FunctionComponent<IOperationsPanelProps> = (p

return (
<>
<Button className="edit-button" onClick={() => onGenerateScreenshot(JWUtils.getPlayer().getPosition())}>
<Button
className="edit-button"
onClick={() => onGenerateScreenshot(JWUtils.getPlayer().getPosition())}
>
Generate thumbnail from current
</Button>
<Button className="edit-button" onClick={() => onGenerateScreenshot()}>
Expand Down
18 changes: 9 additions & 9 deletions ui/v2.5/src/core/StashService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ export class StashService {
}

public static useSceneGenerateScreenshot() {
return GQL.useSceneGenerateScreenshotMutation({
update: () => StashService.invalidateQueries(["findScenes"]),
return GQL.useSceneGenerateScreenshotMutation({
update: () => StashService.invalidateQueries(["findScenes"])
});
}

Expand Down Expand Up @@ -514,7 +514,7 @@ export class StashService {

public static mutateStopJob() {
return StashService.client.mutate<GQL.StopJobMutation>({
mutation: GQL.StopJobDocument,
mutation: GQL.StopJobDocument
});
}

Expand Down Expand Up @@ -574,39 +574,39 @@ export class StashService {
public static mutateMetadataScan(input: GQL.ScanMetadataInput) {
return StashService.client.mutate<GQL.MetadataScanMutation>({
mutation: GQL.MetadataScanDocument,
variables: { input },
variables: { input }
});
}

public static mutateMetadataAutoTag(input: GQL.AutoTagMetadataInput) {
return StashService.client.mutate<GQL.MetadataAutoTagMutation>({
mutation: GQL.MetadataAutoTagDocument,
variables: { input },
variables: { input }
});
}

public static mutateMetadataGenerate(input: GQL.GenerateMetadataInput) {
return StashService.client.mutate<GQL.MetadataGenerateMutation>({
mutation: GQL.MetadataGenerateDocument,
variables: { input },
variables: { input }
});
}

public static mutateMetadataClean() {
return StashService.client.mutate<GQL.MetadataCleanMutation>({
mutation: GQL.MetadataCleanDocument,
mutation: GQL.MetadataCleanDocument
});
}

public static mutateMetadataExport() {
return StashService.client.mutate<GQL.MetadataExportMutation>({
mutation: GQL.MetadataExportDocument,
mutation: GQL.MetadataExportDocument
});
}

public static mutateMetadataImport() {
return StashService.client.mutate<GQL.MetadataImportMutation>({
mutation: GQL.MetadataImportDocument,
mutation: GQL.MetadataImportDocument
});
}

Expand Down
4 changes: 4 additions & 0 deletions ui/v2.5/src/models/list-filter/criteria/criterion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ export abstract class Criterion {
}
}
*/

public encodeValue(): CriterionValue {
return this.value;
}
}

export interface ICriterionOption {
Expand Down
8 changes: 7 additions & 1 deletion ui/v2.5/src/models/list-filter/criteria/performers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CriterionModifier } from "src/core/generated-graphql";
import { ILabeledId, IOptionType } from "../types";
import { ILabeledId, IOptionType, encodeILabeledId } from "../types";
import { Criterion, CriterionType, ICriterionOption } from "./criterion";

export class PerformersCriterion extends Criterion {
Expand All @@ -13,6 +13,12 @@ export class PerformersCriterion extends Criterion {
];
public options: IOptionType[] = [];
public value: ILabeledId[] = [];

public encodeValue() {
return this.value.map(o => {
return encodeILabeledId(o);
});
}
}

export class PerformersCriterionOption implements ICriterionOption {
Expand Down
8 changes: 7 additions & 1 deletion ui/v2.5/src/models/list-filter/criteria/studios.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CriterionModifier } from "src/core/generated-graphql";
import { ILabeledId, IOptionType } from "../types";
import { ILabeledId, IOptionType, encodeILabeledId } from "../types";
import { Criterion, CriterionType, ICriterionOption } from "./criterion";

export class StudiosCriterion extends Criterion {
Expand All @@ -12,6 +12,12 @@ export class StudiosCriterion extends Criterion {
];
public options: IOptionType[] = [];
public value: ILabeledId[] = [];

public encodeValue() {
return this.value.map(o => {
return encodeILabeledId(o);
});
}
}

export class StudiosCriterionOption implements ICriterionOption {
Expand Down
8 changes: 7 additions & 1 deletion ui/v2.5/src/models/list-filter/criteria/tags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as GQL from "src/core/generated-graphql";
import { ILabeledId, IOptionType } from "../types";
import { ILabeledId, IOptionType, encodeILabeledId } from "../types";
import { Criterion, CriterionType, ICriterionOption } from "./criterion";

export class TagsCriterion extends Criterion {
Expand All @@ -22,6 +22,12 @@ export class TagsCriterion extends Criterion {
this.parameterName = "scene_tags";
}
}

public encodeValue() {
return this.value.map(o => {
return encodeILabeledId(o);
});
}
}

export class TagsCriterionOption implements ICriterionOption {
Expand Down
6 changes: 5 additions & 1 deletion ui/v2.5/src/models/list-filter/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ export class ListFilterModel {
this.criteria.forEach(criterion => {
const encodedCriterion: Partial<Criterion> = {
type: criterion.type,
value: criterion.value,
// #394 - the presence of a # symbol results in the query URL being
// malformed. We could set encode: true in the queryString.stringify
// call below, but this results in a URL that gets pretty long and ugly.
// Instead, we'll encode the criteria values.
value: criterion.encodeValue(),
modifier: criterion.modifier
};
const jsonCriterion = JSON.stringify(encodedCriterion);
Expand Down
4 changes: 4 additions & 0 deletions ui/v2.5/src/models/list-filter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export interface ILabeledValue {
value: string;
}

export function encodeILabeledId(o: ILabeledId) {
return { ...o, label: encodeURIComponent(o.label) };
}

export interface IOptionType {
id: string;
name?: string;
Expand Down
4 changes: 4 additions & 0 deletions ui/v2/src/models/list-filter/criteria/criterion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ export abstract class Criterion<Option = any, Value = any> {
this.value = value;
}
}

public encodeValue(): Value {
return this.value;
}
}

export interface ICriterionOption {
Expand Down
6 changes: 5 additions & 1 deletion ui/v2/src/models/list-filter/criteria/movies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CriterionModifier } from "../../../core/generated-graphql";
import { ILabeledId } from "../types";
import { ILabeledId, encodeILabeledId } from "../types";
import {
Criterion,
CriterionType,
Expand All @@ -22,6 +22,10 @@ export class MoviesCriterion extends Criterion<IOptionType, ILabeledId[]> {
];
public options: IOptionType[] = [];
public value: ILabeledId[] = [];

public encodeValue() {
return this.value.map((o) => { return encodeILabeledId(o); });
}
}

export class MoviesCriterionOption implements ICriterionOption {
Expand Down
6 changes: 5 additions & 1 deletion ui/v2/src/models/list-filter/criteria/performers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CriterionModifier } from "../../../core/generated-graphql";
import { ILabeledId } from "../types";
import { ILabeledId, encodeILabeledId } from "../types";
import {
Criterion,
CriterionType,
Expand All @@ -23,6 +23,10 @@ export class PerformersCriterion extends Criterion<IOptionType, ILabeledId[]> {
];
public options: IOptionType[] = [];
public value: ILabeledId[] = [];

public encodeValue() {
return this.value.map((o) => { return encodeILabeledId(o); });
}
}

export class PerformersCriterionOption implements ICriterionOption {
Expand Down
6 changes: 5 additions & 1 deletion ui/v2/src/models/list-filter/criteria/studios.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CriterionModifier } from "../../../core/generated-graphql";
import { ILabeledId } from "../types";
import { ILabeledId, encodeILabeledId } from "../types";
import {
Criterion,
CriterionType,
Expand All @@ -22,6 +22,10 @@ export class StudiosCriterion extends Criterion<IOptionType, ILabeledId[]> {
];
public options: IOptionType[] = [];
public value: ILabeledId[] = [];

public encodeValue() {
return this.value.map((o) => { return encodeILabeledId(o); });
}
}

export class StudiosCriterionOption implements ICriterionOption {
Expand Down
6 changes: 5 additions & 1 deletion ui/v2/src/models/list-filter/criteria/tags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as GQL from "../../../core/generated-graphql";
import { CriterionModifier } from "../../../core/generated-graphql";
import { ILabeledId } from "../types";
import { ILabeledId, encodeILabeledId } from "../types";
import {
Criterion,
CriterionType,
Expand All @@ -27,6 +27,10 @@ export class TagsCriterion extends Criterion<GQL.AllTagsForFilterAllTags, ILabel
this.parameterName = "scene_tags";
}
}

public encodeValue() {
return this.value.map((o) => { return encodeILabeledId(o); });
}
}

export class TagsCriterionOption implements ICriterionOption {
Expand Down
7 changes: 6 additions & 1 deletion ui/v2/src/models/list-filter/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ export class ListFilterModel {
this.criteria.forEach((criterion) => {
const encodedCriterion: any = {};
encodedCriterion.type = criterion.type;
encodedCriterion.value = criterion.value;
// #394 - the presence of a # symbol results in the query URL being
// malformed. We could set encode: true in the queryString.stringify
// call below, but this results in a URL that gets pretty long and ugly.
// Instead, we'll encode the criteria values.
encodedCriterion.value = criterion.encodeValue();

encodedCriterion.modifier = criterion.modifier;
const jsonCriterion = JSON.stringify(encodedCriterion);
encodedCriteria.push(jsonCriterion);
Expand Down
6 changes: 6 additions & 0 deletions ui/v2/src/models/list-filter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export interface ILabeledId {
label: string;
}

export function encodeILabeledId(o: ILabeledId) {
let ret = Object.assign({}, o);
ret.label = encodeURIComponent(o.label);
return ret;
}

export interface ILabeledValue {
label: string;
value: string;
Expand Down

0 comments on commit 1a6374f

Please sign in to comment.