-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [TM-1531] add job service url and script * [TM-1531] apiSlice add job resource * [TM-1531] updates for job service * [TM-1531] sort alphabetical * [TM-1531] add connection for list the delayed jobs * [TM-1531] remove unnecesary code and consistency in selector and API request * [TM-1531] add bulk update call on clear * [TM-1531] add entityname and display data in notification * [TM-1531] use store and display only not acknowledged * [TM-1531] remove from apifetcher call and add continous call for delayed jobs * [TM-1531] rollback apifetcher functionality * [TM-1531] adding message to notification * [TM-1531] display error messages in notifications * [TM-1531] add error messages for failed jobs * [TM-1531] improve connection and remove awaits and asyncs * [TM-1531] changes and remove log * [TM-1531] yarn generate:services * [TM-1531] divide names loading for connections * [TM-1531] running with build * [TM-1531] only send not pending * [TM-1531] fix loaded delayedjobs and filter * [TM-1531] remove logs and unused variable * [TM-1531] join both connections * [TM-1531] transifex and fix selector
- Loading branch information
1 parent
9f57613
commit 2d6f02d
Showing
9 changed files
with
229 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { useEffect } from "react"; | ||
import { createSelector } from "reselect"; | ||
|
||
import { bulkUpdateJobs, listDelayedJobs } from "@/generated/v3/jobService/jobServiceComponents"; | ||
import { bulkUpdateJobsFetchFailed, bulkUpdateJobsIsFetching } from "@/generated/v3/jobService/jobServicePredicates"; | ||
import { DelayedJobData, DelayedJobDto } from "@/generated/v3/jobService/jobServiceSchemas"; | ||
import { useConnection } from "@/hooks/useConnection"; | ||
import { ApiDataStore } from "@/store/apiSlice"; | ||
import { Connection } from "@/types/connection"; | ||
|
||
type DelayedJobCombinedConnection = { | ||
delayedJobs?: DelayedJobDto[] | undefined; | ||
delayedJobsIsLoading: boolean; | ||
delayedJobsHasFailed: boolean; | ||
bulkUpdateJobsIsLoading: boolean; | ||
bulkUpdateJobsHasFailed: boolean; | ||
updatedJobsResponse?: DelayedJobDto[]; | ||
}; | ||
|
||
const delayedJobsSelector = (store: ApiDataStore) => store.delayedJobs; | ||
|
||
const combinedSelector = createSelector( | ||
[delayedJobsSelector, bulkUpdateJobsIsFetching, bulkUpdateJobsFetchFailed], | ||
(delayedJobs, bulkUpdateJobsIsLoading, bulkUpdateJobsFailure) => ({ | ||
delayedJobs: Object.values(delayedJobs ?? {}).map(resource => resource.attributes), | ||
delayedJobsIsLoading: delayedJobs == null && !bulkUpdateJobsFailure, | ||
delayedJobsHasFailed: Boolean(bulkUpdateJobsFailure), | ||
bulkUpdateJobsIsLoading, | ||
bulkUpdateJobsHasFailed: bulkUpdateJobsFailure != null, | ||
updatedJobsResponse: Object.values(delayedJobs ?? {}).map(resource => resource.attributes as DelayedJobDto) | ||
}) | ||
); | ||
|
||
const combinedLoad = (connection: DelayedJobCombinedConnection) => { | ||
if (!combinedIsLoaded(connection)) { | ||
listDelayedJobs(); | ||
} | ||
}; | ||
|
||
const combinedIsLoaded = ({ | ||
delayedJobs, | ||
delayedJobsHasFailed, | ||
bulkUpdateJobsIsLoading, | ||
bulkUpdateJobsHasFailed | ||
}: DelayedJobCombinedConnection) => | ||
(delayedJobs != null || delayedJobsHasFailed) && !bulkUpdateJobsIsLoading && !bulkUpdateJobsHasFailed; | ||
|
||
const delayedJobsCombinedConnection: Connection<DelayedJobCombinedConnection> = { | ||
load: combinedLoad, | ||
isLoaded: combinedIsLoaded, | ||
selector: combinedSelector | ||
}; | ||
|
||
export const useDelayedJobs = () => { | ||
const connection = useConnection(delayedJobsCombinedConnection); | ||
|
||
useEffect(() => { | ||
const intervalId = setInterval(() => { | ||
listDelayedJobs(); | ||
}, 1500); | ||
|
||
return () => { | ||
clearInterval(intervalId); | ||
}; | ||
}, []); | ||
|
||
return connection; | ||
}; | ||
export const triggerBulkUpdate = (jobs: DelayedJobData[]) => bulkUpdateJobs({ body: { data: jobs } }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.