Skip to content

Commit

Permalink
feat(manage slideover): show more request override details (#2772)
Browse files Browse the repository at this point in the history
* feat(manage slideover): show the language profile if request is for a show

* feat(manage slideover): show name of profiles instead of id
  • Loading branch information
danshilm authored May 23, 2022
1 parent 14519ef commit 90095bb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
18 changes: 14 additions & 4 deletions src/components/RequestBlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const messages = defineMessages({
server: 'Destination Server',
profilechanged: 'Quality Profile',
rootfolder: 'Root Folder',
languageprofile: 'Language Profile',
});

interface RequestBlockProps {
Expand All @@ -38,7 +39,8 @@ const RequestBlock: React.FC<RequestBlockProps> = ({ request, onUpdate }) => {
const intl = useIntl();
const [isUpdating, setIsUpdating] = useState(false);
const [showEditModal, setShowEditModal] = useState(false);
const { profile, rootFolder, server } = useRequestOverride(request);
const { profile, rootFolder, server, languageProfile } =
useRequestOverride(request);

const updateRequest = async (type: 'approve' | 'decline'): Promise<void> => {
setIsUpdating(true);
Expand Down Expand Up @@ -209,7 +211,7 @@ const RequestBlock: React.FC<RequestBlockProps> = ({ request, onUpdate }) => {
</div>
</div>
)}
{(server || profile !== null || rootFolder) && (
{(server || profile || rootFolder || languageProfile) && (
<>
<div className="mt-4 mb-1 text-sm">
{intl.formatMessage(messages.requestoverrides)}
Expand All @@ -223,12 +225,12 @@ const RequestBlock: React.FC<RequestBlockProps> = ({ request, onUpdate }) => {
<span>{server}</span>
</li>
)}
{profile !== null && (
{profile && (
<li className="flex justify-between px-1 py-2">
<span className="font-bold">
{intl.formatMessage(messages.profilechanged)}
</span>
<span>ID {profile}</span>
<span>{profile}</span>
</li>
)}
{rootFolder && (
Expand All @@ -239,6 +241,14 @@ const RequestBlock: React.FC<RequestBlockProps> = ({ request, onUpdate }) => {
<span>{rootFolder}</span>
</li>
)}
{languageProfile && (
<li className="flex justify-between px-1 py-2">
<span className="mr-2 font-bold">
{intl.formatMessage(messages.languageprofile)}
</span>
<span>{languageProfile}</span>
</li>
)}
</ul>
</>
)}
Expand Down
50 changes: 33 additions & 17 deletions src/hooks/useRequestOverride.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,61 @@
import useSWR from 'swr';
import { MediaRequest } from '../../server/entity/MediaRequest';
import { ServiceCommonServer } from '../../server/interfaces/api/serviceInterfaces';
import {
ServiceCommonServer,
ServiceCommonServerWithDetails,
} from '../../server/interfaces/api/serviceInterfaces';

interface OverrideStatus {
server: string | null;
profile: number | null;
rootFolder: string | null;
server?: string;
profile?: string;
rootFolder?: string;
languageProfile?: string;
}

const useRequestOverride = (request: MediaRequest): OverrideStatus => {
const { data } = useSWR<ServiceCommonServer[]>(
const { data: allServers } = useSWR<ServiceCommonServer[]>(
`/api/v1/service/${request.type === 'movie' ? 'radarr' : 'sonarr'}`
);

if (!data) {
return {
server: null,
profile: null,
rootFolder: null,
};
const { data } = useSWR<ServiceCommonServerWithDetails>(
`/api/v1/service/${request.type === 'movie' ? 'radarr' : 'sonarr'}/${
request.serverId
}`
);

if (!data || !allServers) {
return {};
}

const defaultServer = data.find(
const defaultServer = allServers.find(
(server) => server.is4k === request.is4k && server.isDefault
);

const activeServer = data.find((server) => server.id === request.serverId);
const activeServer = allServers.find(
(server) => server.id === request.serverId
);

return {
server:
activeServer && request.serverId !== defaultServer?.id
? activeServer.name
: null,
: undefined,
profile:
defaultServer?.activeProfileId !== request.profileId
? request.profileId
: null,
? data.profiles.find((profile) => profile.id === request.profileId)
?.name
: undefined,
rootFolder:
defaultServer?.activeDirectory !== request.rootFolder
? request.rootFolder
: null,
: undefined,
languageProfile:
request.type === 'tv' &&
defaultServer?.activeLanguageProfileId !== request.languageProfileId
? data.languageProfiles?.find(
(profile) => profile.id === request.languageProfileId
)?.name
: undefined,
};
};

Expand Down
1 change: 1 addition & 0 deletions src/i18n/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
"components.QuotaSelector.unlimited": "Unlimited",
"components.RegionSelector.regionDefault": "All Regions",
"components.RegionSelector.regionServerDefault": "Default ({region})",
"components.RequestBlock.languageprofile": "Language Profile",
"components.RequestBlock.profilechanged": "Quality Profile",
"components.RequestBlock.requestoverrides": "Request Overrides",
"components.RequestBlock.rootfolder": "Root Folder",
Expand Down

0 comments on commit 90095bb

Please sign in to comment.