From 9ef0b99963588b27eb2773a759f3b5623097915d Mon Sep 17 00:00:00 2001 From: Saelmala Date: Fri, 23 Aug 2024 09:24:02 +0200 Subject: [PATCH 1/9] feat: add additional filtering --- src/api/agileLive/ingest.ts | 39 +++++++++- .../manager/sources/resources/[id]/route.ts | 21 +++++ .../api/manager/sources/resources/route.ts | 18 +++++ src/components/filter/FilterDropdown.tsx | 77 ++++++++++++++++++- src/components/filter/FilterOptions.tsx | 61 +++++++++++++-- src/hooks/sources/useResources.tsx | 59 ++++++++++++++ 6 files changed, 264 insertions(+), 11 deletions(-) create mode 100644 src/app/api/manager/sources/resources/[id]/route.ts create mode 100644 src/app/api/manager/sources/resources/route.ts create mode 100644 src/hooks/sources/useResources.tsx diff --git a/src/api/agileLive/ingest.ts b/src/api/agileLive/ingest.ts index dc3b1012..baf28e66 100644 --- a/src/api/agileLive/ingest.ts +++ b/src/api/agileLive/ingest.ts @@ -5,6 +5,7 @@ import { } from '../../../types/agile-live'; import { AGILE_BASE_API_PATH } from '../../constants'; import { getAuthorizationHeader } from './utils/authheader'; +import { ResourcesSourceResponse } from '../../../types/agile-live'; // TODO: create proper cache... const INGEST_UUID_CACHE: Map = new Map(); @@ -77,6 +78,27 @@ export async function getIngests(): Promise { throw await response.json(); } +export async function getCompleteIngests(): Promise { + const response = await fetch( + new URL( + AGILE_BASE_API_PATH + `/ingests?expand=true`, + process.env.AGILE_URL + ), + { + headers: { + authorization: getAuthorizationHeader() + }, + next: { + revalidate: 0 + } + } + ); + if (response.ok) { + return response.json(); + } + throw await response.json(); +} + export async function getIngest( uuid: string ): Promise { @@ -123,7 +145,22 @@ export async function getSourceThumbnail( ); if (response.ok) { const json = (await response.json()) as ResourcesThumbnailResponse; - return json?.data; + return json.data; + } + throw await response.json(); +} + +export async function getIngestSources(uuid: string) { + const response = await fetch( + new URL(AGILE_BASE_API_PATH + `/ingests/${uuid}/sources?expand=true`, process.env.AGILE_URL), + { + headers: { + authorization: getAuthorizationHeader() + } + } + ); + if (response.ok) { + return response.json(); } throw await response.json(); } diff --git a/src/app/api/manager/sources/resources/[id]/route.ts b/src/app/api/manager/sources/resources/[id]/route.ts new file mode 100644 index 00000000..da6c2357 --- /dev/null +++ b/src/app/api/manager/sources/resources/[id]/route.ts @@ -0,0 +1,21 @@ +import { NextResponse, NextRequest } from "next/server"; +import { getIngestSources } from "../../../../../../api/agileLive/ingest"; +import { isAuthenticated } from "../../../../../../api/manager/auth"; + +type Params = { + id: string; +}; + +export async function GET(request: NextRequest, { params }: { params: Params }): Promise { + if (!(await isAuthenticated())) { + return new NextResponse(`Not Authorized!`, { + status: 403 + }); + } + + try { + return NextResponse.json(await getIngestSources(params.id)); + } catch (e) { + return new NextResponse(e?.toString(), { status: 404 }); + } +} diff --git a/src/app/api/manager/sources/resources/route.ts b/src/app/api/manager/sources/resources/route.ts new file mode 100644 index 00000000..5a942676 --- /dev/null +++ b/src/app/api/manager/sources/resources/route.ts @@ -0,0 +1,18 @@ +import { NextResponse } from 'next/server'; +import { isAuthenticated } from '../../../../../api/manager/auth'; +import { getCompleteIngests } from '../../../../../api/agileLive/ingest'; + + +export async function GET(): Promise { + if (!(await isAuthenticated())) { + return new NextResponse(`Not Authorized!`, { + status: 403 + }); + } + + try { + return NextResponse.json(await getCompleteIngests()); + } catch (e) { + return new NextResponse(e?.toString(), { status: 404 }) + } +} diff --git a/src/components/filter/FilterDropdown.tsx b/src/components/filter/FilterDropdown.tsx index 6d874d0e..9bc2e617 100644 --- a/src/components/filter/FilterDropdown.tsx +++ b/src/components/filter/FilterDropdown.tsx @@ -10,10 +10,16 @@ function FilterDropdown({ isLocationHidden, showConfigSources, selectedTags, + showConfigNdiType, + showConfigBmdType, + showConfigSrtType, setIsTypeHidden, setIsLocationHidden, setSelectedTags, - setOnlyShowActiveSources: setOnlyShowConfigSources + setOnlyShowActiveSources: setOnlyShowConfigSources, + setOnlyShowNdiSources: setOnlyShowNdiSources, + setOnlyShowBmdSources: setOnlyShowBmdSources, + setOnlyShowSrtSources: setOnlyShowSrtSources }: { close: () => void; types: string[]; @@ -23,10 +29,16 @@ function FilterDropdown({ isLocationHidden: boolean; showConfigSources: boolean; selectedTags: Set; + showConfigNdiType: boolean; + showConfigSrtType: boolean; + showConfigBmdType: boolean; setIsTypeHidden: React.Dispatch>; setIsLocationHidden: React.Dispatch>; setOnlyShowActiveSources: React.Dispatch>; setSelectedTags: React.Dispatch>>; + setOnlyShowNdiSources: React.Dispatch>; + setOnlyShowBmdSources: React.Dispatch>; + setOnlyShowSrtSources: React.Dispatch>; }) { const [searchedTypes, setSearchedTypes] = useState([]); const [searchedLocations, setSearchedLocations] = useState([]); @@ -48,6 +60,18 @@ function FilterDropdown({ setOnlyShowConfigSources(!showConfigSources); }; + const showSelectedConfigNdiType = () => { + setOnlyShowNdiSources(!showConfigNdiType); + }; + + const showSelectedConfigBmdType = () => { + setOnlyShowBmdSources(!showConfigBmdType); + }; + + const showSelectedConfigSrtType = () => { + setOnlyShowSrtSources(!showConfigSrtType); + }; + const deleteTag = (value: string) => { const temp = selectedTags; temp.delete(value); @@ -222,17 +246,64 @@ function FilterDropdown({ +
+ + +
+
+ + +
+
+ + +
+ +
diff --git a/src/hooks/sources/useResources.tsx b/src/hooks/sources/useResources.tsx new file mode 100644 index 00000000..d6b37b71 --- /dev/null +++ b/src/hooks/sources/useResources.tsx @@ -0,0 +1,59 @@ +import { + ResourcesIngestResponse, + ResourcesSourceResponse +} from '../../../types/agile-live'; +import { useState, useEffect } from 'react'; + +export function useResources() { + const [ingests, setIngests] = useState([]); + const [resources, setResources] = useState([]); + + useEffect(() => { + let isMounted = true; + + const fetchSources = async () => { + try { + const response = await fetch(`/api/manager/sources/resourceSource`, { + method: 'GET', + headers: [['x-api-key', `Bearer apisecretkey`]] + }); + + if (!response.ok) { + throw new Error('Error'); + } + + const ing = await response.json(); + if (isMounted) { + setIngests(ing); + } + } catch (e) { + console.log('ERROR'); + } + }; + fetchSources(); + + return () => { + isMounted = false; + }; + }, []); + + useEffect(() => { + if (ingests) { + for (let i = 0; i < ingests.length; i++) { + const id = ingests[i].uuid; + if (id) { + fetch(`/api/manager/resources/${id}`, { + method: 'GET', + headers: [['x-api-key', `Bearer apisecretkey`]] + }).then(async (response) => { + console.log('RESPONSE: ', response); + const sources = await response.json(); + setResources(sources); + }); + } + } + } + }, [ingests]); + + return [resources]; +} From 4b6d3edb14c7f23d21563d9463965f57ee8cecbd Mon Sep 17 00:00:00 2001 From: Saelmala Date: Fri, 23 Aug 2024 11:00:58 +0200 Subject: [PATCH 2/9] fix: handle active + source filter, reduce code --- src/api/agileLive/ingest.ts | 21 ------- .../api/manager/sources/resources/route.ts | 4 +- src/components/filter/FilterDropdown.tsx | 57 +++++++++++++------ src/components/filter/FilterOptions.tsx | 57 ++++++++++--------- src/hooks/sources/useResources.tsx | 33 ++++------- 5 files changed, 81 insertions(+), 91 deletions(-) diff --git a/src/api/agileLive/ingest.ts b/src/api/agileLive/ingest.ts index baf28e66..733164ef 100644 --- a/src/api/agileLive/ingest.ts +++ b/src/api/agileLive/ingest.ts @@ -78,27 +78,6 @@ export async function getIngests(): Promise { throw await response.json(); } -export async function getCompleteIngests(): Promise { - const response = await fetch( - new URL( - AGILE_BASE_API_PATH + `/ingests?expand=true`, - process.env.AGILE_URL - ), - { - headers: { - authorization: getAuthorizationHeader() - }, - next: { - revalidate: 0 - } - } - ); - if (response.ok) { - return response.json(); - } - throw await response.json(); -} - export async function getIngest( uuid: string ): Promise { diff --git a/src/app/api/manager/sources/resources/route.ts b/src/app/api/manager/sources/resources/route.ts index 5a942676..8932a0df 100644 --- a/src/app/api/manager/sources/resources/route.ts +++ b/src/app/api/manager/sources/resources/route.ts @@ -1,6 +1,6 @@ import { NextResponse } from 'next/server'; import { isAuthenticated } from '../../../../../api/manager/auth'; -import { getCompleteIngests } from '../../../../../api/agileLive/ingest'; +import { getIngests } from '../../../../../api/agileLive/ingest'; export async function GET(): Promise { @@ -11,7 +11,7 @@ export async function GET(): Promise { } try { - return NextResponse.json(await getCompleteIngests()); + return NextResponse.json(await getIngests()); } catch (e) { return new NextResponse(e?.toString(), { status: 404 }) } diff --git a/src/components/filter/FilterDropdown.tsx b/src/components/filter/FilterDropdown.tsx index 9bc2e617..ac03f7c0 100644 --- a/src/components/filter/FilterDropdown.tsx +++ b/src/components/filter/FilterDropdown.tsx @@ -10,9 +10,9 @@ function FilterDropdown({ isLocationHidden, showConfigSources, selectedTags, - showConfigNdiType, - showConfigBmdType, - showConfigSrtType, + showNdiType, + showBmdType, + showSrtType, setIsTypeHidden, setIsLocationHidden, setSelectedTags, @@ -29,9 +29,9 @@ function FilterDropdown({ isLocationHidden: boolean; showConfigSources: boolean; selectedTags: Set; - showConfigNdiType: boolean; - showConfigSrtType: boolean; - showConfigBmdType: boolean; + showNdiType: boolean; + showSrtType: boolean; + showBmdType: boolean; setIsTypeHidden: React.Dispatch>; setIsLocationHidden: React.Dispatch>; setOnlyShowActiveSources: React.Dispatch>; @@ -60,16 +60,34 @@ function FilterDropdown({ setOnlyShowConfigSources(!showConfigSources); }; - const showSelectedConfigNdiType = () => { - setOnlyShowNdiSources(!showConfigNdiType); + const showSelectedNdiType = () => { + if (!showNdiType) { + setOnlyShowNdiSources(true); + setOnlyShowBmdSources(false); + setOnlyShowSrtSources(false); + } else { + setOnlyShowNdiSources(false); + } }; - const showSelectedConfigBmdType = () => { - setOnlyShowBmdSources(!showConfigBmdType); + const showSelectedSrtType = () => { + if (!showSrtType) { + setOnlyShowSrtSources(true); + setOnlyShowNdiSources(false); + setOnlyShowBmdSources(false); + } else { + setOnlyShowSrtSources(false); + } }; - const showSelectedConfigSrtType = () => { - setOnlyShowSrtSources(!showConfigSrtType); + const showSelectedBmdType = () => { + if (!showBmdType) { + setOnlyShowBmdSources(true); + setOnlyShowNdiSources(false); + setOnlyShowSrtSources(false); + } else { + setOnlyShowBmdSources(false); + } }; const deleteTag = (value: string) => { @@ -122,6 +140,9 @@ function FilterDropdown({ const handleClear = () => { setSelectedTags(new Set()); setOnlyShowConfigSources(false); + setOnlyShowBmdSources(false); + setOnlyShowNdiSources(false); + setOnlyShowSrtSources(false); }; const typesSearch = (event: ChangeEvent) => { @@ -262,8 +283,8 @@ function FilterDropdown({ id="showNdiCheckbox" type="checkbox" className="flex ml-2 w-4 justify-center rounded-lg text-zinc-300" - checked={showConfigNdiType} - onChange={showSelectedConfigNdiType} + checked={showNdiType} + onChange={showSelectedNdiType} />