From cf1fe451c9a7ebf3524bdb318bc6d71c8cb2735c Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Sun, 6 Feb 2022 23:12:39 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8E=20Wiring=20up=20the=20refactored?= =?UTF-8?q?=20elasticsearch=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +- src/client/actions/comicinfo.actions.tsx | 69 +++++++++++---- src/client/actions/fileops.actions.tsx | 8 +- .../ComicDetail/ComicVineMatchPanel.tsx | 7 +- src/client/components/Dashboard.tsx | 8 -- src/client/components/RecentlyImported.tsx | 2 +- .../components/VolumeDetail/VolumeDetail.tsx | 86 +++++++++++-------- src/client/constants/action-types.ts | 6 +- src/client/constants/endpoints.ts | 2 +- src/client/reducers/comicinfo.reducer.js | 20 ++++- yarn.lock | 16 ++-- 11 files changed, 143 insertions(+), 85 deletions(-) diff --git a/package.json b/package.json index 119ff40..f17d8df 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "ellipsize": "^0.1.0", "express": "^4.17.1", "fastest-validator": "^1.11.0", - "filename-parser": "^1.0.0", + "filename-parser": "^1.0.1", "final-form": "^4.20.2", "final-form-arrays": "^3.0.2", "html-to-text": "^8.1.0", @@ -74,7 +74,7 @@ "sharp": "^0.28.1", "socket.io-client": "^4.3.2", "styled-components": "^5.3.3", - "threetwo-ui-typings": "^1.0.12", + "threetwo-ui-typings": "^1.0.13", "voca": "^1.4.0", "websocket": "^1.0.34", "ws": "^7.5.3", diff --git a/src/client/actions/comicinfo.actions.tsx b/src/client/actions/comicinfo.actions.tsx index 3da293c..68b3b6f 100644 --- a/src/client/actions/comicinfo.actions.tsx +++ b/src/client/actions/comicinfo.actions.tsx @@ -14,9 +14,11 @@ import { CV_ISSUES_METADATA_CALL_IN_PROGRESS, CV_CLEANUP, IMS_COMIC_BOOKS_DB_OBJECTS_FETCHED, + CV_ISSUES_MATCHES_IN_LIBRARY_FETCHED, + CV_ISSUES_FOR_VOLUME_IN_LIBRARY_SUCCESS, } from "../constants/action-types"; import { - COMICBOOKINFO_SERVICE_URI, + COMICVINE_SERVICE_URI, LIBRARY_SERVICE_BASE_URI, } from "../constants/endpoints"; @@ -32,7 +34,7 @@ export const comicinfoAPICall = (options) => async (dispatch) => { type: CV_API_CALL_IN_PROGRESS, inProgress: true, }); - const serviceURI = `${COMICBOOKINFO_SERVICE_URI}/${options.callURIAction}`; + const serviceURI = `${COMICVINE_SERVICE_URI}/${options.callURIAction}`; const response = await http(serviceURI, { method: options.callMethod, params: options.callParams, @@ -65,23 +67,54 @@ export const comicinfoAPICall = (options) => async (dispatch) => { }); } }; -export const findIssuesForSeriesInLibrary = - (comicObjectID: any) => async (dispatch) => { - dispatch({ - type: CV_ISSUES_METADATA_CALL_IN_PROGRESS, - }); - dispatch({ - type: CV_CLEANUP, - }); +export const getIssuesForSeries = (comicObjectID: any) => async (dispatch) => { + dispatch({ + type: CV_ISSUES_METADATA_CALL_IN_PROGRESS, + }); + dispatch({ + type: CV_CLEANUP, + }); - await axios({ - url: `${LIBRARY_SERVICE_BASE_URI}/findIssuesForSeriesInLibrary`, - method: "POST", - params: { - comicObjectID, - }, - }); - }; + const issues = await axios({ + url: `${COMICVINE_SERVICE_URI}/getIssuesForSeries`, + method: "POST", + params: { + comicObjectID, + }, + }); + + dispatch({ + type: CV_ISSUES_FOR_VOLUME_IN_LIBRARY_SUCCESS, + issues: issues.data, + }); +}; + +export const analyzeLibrary = (issues) => async (dispatch) => { + dispatch({ + type: CV_ISSUES_METADATA_CALL_IN_PROGRESS, + }); + const queryObjects = issues.map((issue) => { + const { id, name, issue_number } = issue; + return { + issueId: id, + issueName: name, + volumeName: issue.volume.name, + issueNumber: issue_number, + }; + }); + const foo = await axios({ + url: `${LIBRARY_SERVICE_BASE_URI}/findIssueForSeries`, + method: "POST", + data: { + queryObjects, + }, + }); + console.log(foo); + dispatch({ + type: CV_ISSUES_MATCHES_IN_LIBRARY_FETCHED, + matches: foo.data, + }); +}; export const getComicBookDetailById = (comicBookObjectId: string) => async (dispatch) => { diff --git a/src/client/actions/fileops.actions.tsx b/src/client/actions/fileops.actions.tsx index 8fdc61e..f263866 100644 --- a/src/client/actions/fileops.actions.tsx +++ b/src/client/actions/fileops.actions.tsx @@ -1,7 +1,7 @@ import axios from "axios"; import { IFolderData } from "threetwo-ui-typings"; import { - COMICBOOKINFO_SERVICE_URI, + COMICVINE_SERVICE_URI, LIBRARY_SERVICE_BASE_URI, } from "../constants/endpoints"; import { @@ -161,19 +161,19 @@ export const fetchComicVineMatches = console.log(seriesSearchQuery); axios .request({ - url: `${COMICBOOKINFO_SERVICE_URI}/volumeBasedSearch`, + url: `${COMICVINE_SERVICE_URI}/volumeBasedSearch`, method: "POST", data: { format: "json", // hack - query: issueSearchQuery.searchParams.searchTerms.name + query: issueSearchQuery.inferredIssueDetails.name .replace(/[^a-zA-Z0-9 ]/g, "") .trim(), limit: "100", page: 1, resources: "volume", scorerConfiguration: { - searchParams: issueSearchQuery.searchParams, + searchParams: issueSearchQuery.inferredIssueDetails, }, rawFileDetails: searchPayload.rawFileDetails, }, diff --git a/src/client/components/ComicDetail/ComicVineMatchPanel.tsx b/src/client/components/ComicDetail/ComicVineMatchPanel.tsx index 0022c19..d51a0a9 100644 --- a/src/client/components/ComicDetail/ComicVineMatchPanel.tsx +++ b/src/client/components/ComicDetail/ComicVineMatchPanel.tsx @@ -23,10 +23,7 @@ export const ComicVineMatchPanel = (comicVineData): ReactElement => {
Title - { - comicVineSearchQueryObject.issue.searchParams.searchTerms - .name - } + {comicVineSearchQueryObject.issue.inferredIssueDetails.name}
@@ -35,7 +32,7 @@ export const ComicVineMatchPanel = (comicVineData): ReactElement => { Number { - comicVineSearchQueryObject.issue.searchParams.searchTerms + comicVineSearchQueryObject.issue.inferredIssueDetails .number } diff --git a/src/client/components/Dashboard.tsx b/src/client/components/Dashboard.tsx index 6407904..09f1b5b 100644 --- a/src/client/components/Dashboard.tsx +++ b/src/client/components/Dashboard.tsx @@ -32,15 +32,7 @@ export const Dashboard = (): ReactElement => { {!isEmpty(recentComics) && !isEmpty(recentComics.docs) ? ( <> -
-
-
-

13,476 Books

-
-
-
- {!isNil(volumeGroups) ? : null} ) : ( diff --git a/src/client/components/RecentlyImported.tsx b/src/client/components/RecentlyImported.tsx index db7d583..973a0aa 100644 --- a/src/client/components/RecentlyImported.tsx +++ b/src/client/components/RecentlyImported.tsx @@ -24,7 +24,7 @@ export const RecentlyImported = ({ return ( <>
-

Recently Imported

+

Recently Imported

{ potentialMatchesInLibrary: { content: () => { const ids = map(matches, partialRight(pick, "_id")); - const matchIds = ids.map((id:any) => id._id); + const matchIds = ids.map((id: any) => id._id); return ; }, }, @@ -44,6 +45,10 @@ const VolumeDetails = (props): ReactElement => { setVisible(true); }, []); + const analyzeIssues = useCallback((issues) => { + dispatch(analyzeLibrary(issues)); + }, []); + const comicBookDetails = useSelector( (state: RootState) => state.comicInfo.comicBookDetail, ); @@ -53,45 +58,56 @@ const VolumeDetails = (props): ReactElement => { const dispatch = useDispatch(); useEffect(() => { - dispatch(findIssuesForSeriesInLibrary(comicObjectId)); + dispatch(getIssuesForSeries(comicObjectId)); dispatch(getComicBookDetailById(comicObjectId)); }, []); const { comicObjectId } = useParams<{ comicObjectId: string }>(); const IssuesInVolume = () => ( - - {!isUndefined(issuesForVolume) && !isEmpty(issuesForVolume) - ? issuesForVolume.map((issue) => { - return ( - openPotentialLibraryMatchesPanel(issue.matches)} - > - {!isEmpty(issue.matches) ? ( - <> - - - - - {"#" + issue.issue.issue_number} - - - ) : null} - - ); - }) - : "loading"} - + <> + {!isUndefined(issuesForVolume) ? ( +
analyzeIssues(issuesForVolume)}> + Analyze Library +
+ ) : null} + + {!isUndefined(issuesForVolume) && !isEmpty(issuesForVolume) + ? issuesForVolume.map((issue) => { + return ( + + openPotentialLibraryMatchesPanel(issue.matches) + } + > + {!isEmpty(issue.matches) ? ( + <> + + + + + {"#" + issue.issue_number} + + + ) : null} + + ); + }) + : "loading"} + + ); // Tab content and header details diff --git a/src/client/constants/action-types.ts b/src/client/constants/action-types.ts index 35b1430..dbabc89 100644 --- a/src/client/constants/action-types.ts +++ b/src/client/constants/action-types.ts @@ -28,7 +28,8 @@ export const IMS_DATA_FETCH_ERROR = "IMS_DATA_FETCH_ERROR"; // Single or multiple comic book mongo objects export const IMS_COMIC_BOOK_DB_OBJECT_FETCHED = "IMS_COMIC_BOOK_DB_OBJECT_FETCHED"; -export const IMS_COMIC_BOOKS_DB_OBJECTS_FETCHED = "IMS_COMIC_BOOKS_DB_OBJECTS_FETCHED"; +export const IMS_COMIC_BOOKS_DB_OBJECTS_FETCHED = + "IMS_COMIC_BOOKS_DB_OBJECTS_FETCHED"; export const IMS_COMIC_BOOK_DB_OBJECT_CALL_IN_PROGRESS = "IMS_COMIC_BOOK_DB_OBJECT_CALL_IN_PROGRESS"; export const IMS_COMIC_BOOK_DB_OBJECT_CALL_FAILED = @@ -50,6 +51,9 @@ export const CV_ISSUES_METADATA_FETCH_FAILED = "CV_ISSUES_METADATA_FETCH_FAILED"; export const CV_ISSUES_FOR_VOLUME_IN_LIBRARY_SUCCESS = "CV_ISSUES_FOR_VOLUME_IN_LIBRARY_SUCCESS"; +export const CV_ISSUES_FOR_VOLUME_IN_LIBRARY_UPDATED = + "CV_ISSUES_FOR_VOLUME_IN_LIBRARY_UPDATED"; +export const CV_ISSUES_MATCHES_IN_LIBRARY_FETCHED = "CV_ISSUES_MATCHES_IN_LIBRARY_FETCHED"; // extracted comic archive export const IMS_COMIC_BOOK_ARCHIVE_EXTRACTION_SUCCESS = diff --git a/src/client/constants/endpoints.ts b/src/client/constants/endpoints.ts index abbde84..81b05ab 100644 --- a/src/client/constants/endpoints.ts +++ b/src/client/constants/endpoints.ts @@ -16,7 +16,7 @@ export const CORS_PROXY_SERVER_URI = hostURIBuilder({ apiPath: "/", }); -export const COMICBOOKINFO_SERVICE_URI = hostURIBuilder({ +export const COMICVINE_SERVICE_URI = hostURIBuilder({ protocol: "http", host: process.env.UNDERLYING_HOSTNAME || "localhost", port: "3080", diff --git a/src/client/reducers/comicinfo.reducer.js b/src/client/reducers/comicinfo.reducer.js index 5d8f0fd..92c3b6a 100644 --- a/src/client/reducers/comicinfo.reducer.js +++ b/src/client/reducers/comicinfo.reducer.js @@ -1,3 +1,4 @@ +import { isEmpty, extend, each } from "lodash"; import { CV_API_CALL_IN_PROGRESS, CV_SEARCH_SUCCESS, @@ -7,8 +8,11 @@ import { IMS_COMIC_BOOK_DB_OBJECT_CALL_IN_PROGRESS, CV_ISSUES_METADATA_CALL_IN_PROGRESS, CV_ISSUES_METADATA_FETCH_SUCCESS, + CV_ISSUES_FOR_VOLUME_IN_LIBRARY_UPDATED, + CV_ISSUES_MATCHES_IN_LIBRARY_FETCHED, CV_ISSUES_FOR_VOLUME_IN_LIBRARY_SUCCESS, } from "../constants/action-types"; +import { refineQuery } from "filename-parser"; const initialState = { searchResults: [], @@ -67,12 +71,24 @@ function comicinfoReducer(state = initialState, action) { }; case CV_ISSUES_FOR_VOLUME_IN_LIBRARY_SUCCESS: - console.log("jagan", action); + // console.log("jagan", action); return { ...state, - issuesForVolume: [...state.issuesForVolume, action.result], + issuesForVolume: action.issues, inProgress: false, }; + case CV_ISSUES_MATCHES_IN_LIBRARY_FETCHED: + console.log(action); + const updatedState = [...state.issuesForVolume]; + + // updatedState[issueToUpdateIndex].matches = action.result.matches; + // console.log(issueToUpdateIndex); + // console.log(updatedState[issueToUpdateIndex]); + + return { + ...state, + issuesForVolume: updatedState, + }; default: return state; } diff --git a/yarn.lock b/yarn.lock index a5c72bf..8b346c2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5805,10 +5805,10 @@ filehound@^1.17.5: moment "^2.29.1" unit-compare "^1.0.1" -filename-parser@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/filename-parser/-/filename-parser-1.0.0.tgz#bad742add537ec075136cee49129e0146ed34596" - integrity sha512-3j7TgfElImSXhYcBzCP75+mC08IdRGmIBOm6XcJciI3xnQU6A4imzzUEJ2Ps717s5ycBkzQgUtjArGWGh/Gmkg== +filename-parser@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/filename-parser/-/filename-parser-1.0.1.tgz#cd54d9131913dd2bf96c2a1d19edf7c1ee75c4cc" + integrity sha512-MMzuklXc1r4N6uQXg8CQYxoiTX7w6QPeJE73L5lCTSoNR7CftCXHIA6tyINomkvWIUanrlqTB629DyTIqCucEA== dependencies: compromise "^13.11.4" compromise-dates "^2.2.1" @@ -12857,10 +12857,10 @@ text-table@^0.2.0, text-table@~0.2.0: resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ= -threetwo-ui-typings@^1.0.12: - version "1.0.12" - resolved "https://registry.yarnpkg.com/threetwo-ui-typings/-/threetwo-ui-typings-1.0.12.tgz#9f05542d7fa67b2349e20b0555ab196521fa8448" - integrity sha512-lKADNpD2Oa3Wmf6tdZhaPSNfIFa0KtstsZLE0yalTjqKmtQZM7Ct2OnlCkH7aonDuVn+jgcRMwkcP9krCqa2fw== +threetwo-ui-typings@^1.0.13: + version "1.0.13" + resolved "https://registry.yarnpkg.com/threetwo-ui-typings/-/threetwo-ui-typings-1.0.13.tgz#9437a8c08a6984ebd1dcdf308e06e404dee11c81" + integrity sha512-AQiY8/hbp+TobBoehNTEoNco97AoiKYQjAANSFDR3pSD5jFn5qjLlKntvqdNF9Fg5tcS0ReYe0AjsvKshKpixQ== dependencies: typescript "^4.3.2"