Skip to content

Commit

Permalink
Accept incorrectly insensitivised frontpage config keys
Browse files Browse the repository at this point in the history
  • Loading branch information
DingDongSoLong4 committed Oct 23, 2023
1 parent 298f3d4 commit db052f6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 15 deletions.
14 changes: 4 additions & 10 deletions ui/v2.5/src/components/FrontPage/Control.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React, { useContext, useMemo } from "react";
import { useIntl } from "react-intl";
import {
FrontPageContent,
ICustomFilter,
ISavedFilterRow,
} from "src/core/config";
import { FrontPageContent, ICustomFilter } from "src/core/config";
import * as GQL from "src/core/generated-graphql";
import { useFindSavedFilter } from "src/core/StashService";
import { ConfigurationContext } from "src/hooks/Config";
Expand Down Expand Up @@ -167,17 +163,15 @@ interface IProps {
export const Control: React.FC<IProps> = ({ content }) => {
switch (content.__typename) {
case "SavedFilter":
if (!(content as ISavedFilterRow).savedFilterId) {
if (!content.savedFilterId) {
return <div>Error: missing savedFilterId</div>;
}

return (
<SavedFilterResults
savedFilterID={(content as ISavedFilterRow).savedFilterId.toString()}
/>
<SavedFilterResults savedFilterID={content.savedFilterId.toString()} />
);
case "CustomFilter":
return <CustomFilterResults customFilter={content as ICustomFilter} />;
return <CustomFilterResults customFilter={content} />;
default:
return <></>;
}
Expand Down
5 changes: 3 additions & 2 deletions ui/v2.5/src/components/FrontPage/FrontPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ConfigurationContext } from "src/hooks/Config";
import {
FrontPageContent,
generateDefaultFrontPageContent,
getFrontPageContent,
IUIConfig,
} from "src/core/config";
import { useScrollToTopOnMount } from "src/hooks/scrollToTop";
Expand Down Expand Up @@ -65,12 +66,12 @@ const FrontPage: React.FC = () => {
onUpdateConfig(defaultContent);
}

const { frontPageContent } = ui;
const frontPageContent = getFrontPageContent(ui);

return (
<div className="recommendations-container">
<div>
{frontPageContent?.map((content: FrontPageContent, i) => (
{frontPageContent?.map((content, i) => (
<Control key={i} content={content} />
))}
</div>
Expand Down
6 changes: 4 additions & 2 deletions ui/v2.5/src/components/FrontPage/FrontPageConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ICustomFilter,
FrontPageContent,
generatePremadeFrontPageContent,
getFrontPageContent,
} from "src/core/config";

interface IAddSavedFilterModalProps {
Expand Down Expand Up @@ -299,8 +300,9 @@ export const FrontPageConfig: React.FC<IFrontPageConfigProps> = ({
return;
}

if (ui?.frontPageContent) {
setCurrentContent(ui.frontPageContent);
const frontPageContent = getFrontPageContent(ui);
if (frontPageContent) {
setCurrentContent(frontPageContent);
}
}, [allFilters, ui]);

Expand Down
45 changes: 44 additions & 1 deletion ui/v2.5/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export type FrontPageContent = ISavedFilterRow | ICustomFilter;
export const defaultMaxOptionsShown = 200;

export interface IUIConfig {
frontPageContent?: FrontPageContent[];
// unknown to prevent direct access - use getFrontPageContent
frontPageContent?: unknown;

showChildTagContent?: boolean;
showChildStudioContent?: boolean;
Expand Down Expand Up @@ -81,6 +82,48 @@ export interface IUIConfig {
pinnedFilters?: PinnedFilters;
}

interface ISavedFilterRowBroken extends ISavedFilterRow {
savedfilterid?: number;
}

interface ICustomFilterBroken extends ICustomFilter {
sortby?: string;
}

type FrontPageContentBroken = ISavedFilterRowBroken | ICustomFilterBroken;

// #4128: deal with incorrectly insensitivised keys (sortBy and savedFilterId)
export function getFrontPageContent(
ui: IUIConfig
): FrontPageContent[] | undefined {
return (ui.frontPageContent as FrontPageContentBroken[] | undefined)?.map(
(content) => {
switch (content.__typename) {
case "SavedFilter":
if (content.savedfilterid) {
return {
...content,
savedFilterId: content.savedFilterId ?? content.savedfilterid,
savedfilterid: undefined,
};
}
return content;
case "CustomFilter":
if (content.sortby) {
return {
...content,
sortBy: content.sortBy ?? content.sortby,
sortby: undefined,
};
}
return content;
default:
return content;
}
}
);
}

function recentlyReleased(
intl: IntlShape,
mode: FilterMode,
Expand Down

0 comments on commit db052f6

Please sign in to comment.