@@ -8,10 +8,10 @@ import {API_PREFIX} from '../../common/constants'
88import { isExtensionEnabled } from '../../common/util/config'
99import { fetchDeployment } from './deployments'
1010import { fetchFeedSource } from './feeds'
11- import { downloadMergedFeedViaToken } from './projects'
11+ import { downloadMergedFeedViaToken , fetchProjectWithFeeds } from './projects'
1212import { downloadSnapshotViaCredentials } from '../../editor/actions/snapshots'
1313
14- import type { DataToolsConfig , ServerJob } from '../../types'
14+ import type { DataToolsConfig , MergeFeedsResult , ServerJob } from '../../types'
1515import type { dispatchFn , getStateFn } from '../../types/reducers'
1616
1717type ErrorMessage = {
@@ -21,6 +21,13 @@ type ErrorMessage = {
2121 title ?: string
2222}
2323
24+ type ModalContent = {
25+ action ?: any ,
26+ body : string ,
27+ detail ?: any ,
28+ title : string
29+ }
30+
2431export const clearStatusModal = createVoidPayloadAction ( 'CLEAR_STATUS_MODAL' )
2532const handlingFinishedJob = createAction (
2633 'HANDLING_FINISHED_JOB' ,
@@ -57,12 +64,7 @@ const setAppInfo = createAction(
5764
5865const setStatusModal = createAction (
5966 'SET_STATUS_MODAL' ,
60- ( payload : {
61- action ? : any ,
62- body : string ,
63- detail ? : any ,
64- title : string
65- } ) => payload
67+ ( payload : ModalContent ) => payload
6668)
6769
6870export type StatusActions = ActionType < typeof clearStatusModal > |
@@ -134,6 +136,51 @@ export async function fetchAppInfo () {
134136 }
135137}
136138
139+ function getMergeFeedModalContent ( result : MergeFeedsResult ) : ModalContent {
140+ const details = [ ]
141+ // Do nothing or show merged feed modal? Feed version is be created
142+ details . push ( 'Remapped ID count: ' + result . remappedReferences )
143+ if ( Object . keys ( result . remappedIds ) . length > 0 ) {
144+ const remappedIdStrings = [ ]
145+ for ( let key in result . remappedIds ) {
146+ // Modify key to remove feed name.
147+ const split = key . split ( ':' )
148+ const tableAndId = split . splice ( 1 , 1 )
149+ remappedIdStrings . push ( `${ tableAndId . join ( ':' ) } -> ${ result . remappedIds [ key ] } ` )
150+ }
151+ details . push ( 'Remapped IDs: ' + remappedIdStrings . join ( ', ' ) )
152+ }
153+ if ( result . skippedIds . length > 0 ) {
154+ const skippedRecordsForTables = { }
155+ result . skippedIds . forEach ( id => {
156+ const table = id . split ( ':' ) [ 0 ]
157+ if ( skippedRecordsForTables [ table ] ) {
158+ skippedRecordsForTables [ table ] = skippedRecordsForTables [ table ] + 1
159+ } else {
160+ skippedRecordsForTables [ table ] = 1
161+ }
162+ } )
163+ const skippedRecordsStrings = [ ]
164+ for ( let key in skippedRecordsForTables ) {
165+ skippedRecordsStrings . push ( `${ key } - ${ skippedRecordsForTables [ key ] } ` )
166+ }
167+ details . push ( 'Skipped records: ' + skippedRecordsStrings . join ( ', ' ) )
168+ }
169+ if ( result . idConflicts . length > 0 ) {
170+ // const conflicts = result.idConflicts
171+ details . push ( 'ID conflicts: ' + result . idConflicts . join ( ', ' ) )
172+ }
173+ return {
174+ title : result . failed
175+ ? 'Warning: Errors encountered during feed merge!'
176+ : 'Feed merge was successful!' ,
177+ body : result . failed
178+ ? `Merge failed with ${ result . errorCount } errors. ${ result . failureReasons . join ( ', ' ) } `
179+ : `Merge was completed successfully. A new version will be processed/validated containing the resulting feed.` ,
180+ detail : details . join ( '\n' )
181+ }
182+ }
183+
137184/* eslint-disable complexity */
138185export function handleFinishedJob ( job : ServerJob ) {
139186 return function ( dispatch : dispatchFn , getState : getStateFn ) {
@@ -203,60 +250,21 @@ export function handleFinishedJob (job: ServerJob) {
203250 // If merging feeds for the project, end result is to download zip.
204251 if ( ! job . projectId ) {
205252 // FIXME use setErrorMessage instead?
206- console . warn ( 'No project found on job' )
207- return
253+ throw new Error ( 'No project found on job' )
208254 }
209- dispatch ( downloadMergedFeedViaToken ( job . projectId , false ) )
255+ // FIXME
256+ dispatch ( fetchProjectWithFeeds ( job . projectId ) )
210257 } else {
211258 const result = job . mergeFeedsResult
212- const details = [ ]
213259 if ( result ) {
214- // Do nothing or show merged feed modal? Feed version is be created
215- details . push ( 'Remapped ID count: ' + result . remappedReferences )
216- if ( Object . keys ( result . remappedIds ) . length > 0 ) {
217- const remappedIdStrings = [ ]
218- for ( let key in result . remappedIds ) {
219- // Modify key to remove feed name.
220- const split = key . split ( ':' )
221- const tableAndId = split . splice ( 1 , 1 )
222- remappedIdStrings . push ( `${ tableAndId . join ( ':' ) } -> ${ result . remappedIds [ key ] } ` )
223- }
224- details . push ( 'Remapped IDs: ' + remappedIdStrings . join ( ', ' ) )
225- }
226- if ( result . skippedIds . length > 0 ) {
227- const skippedRecordsForTables = { }
228- result . skippedIds . forEach ( id => {
229- const table = id . split ( ':' ) [ 0 ]
230- if ( skippedRecordsForTables [ table ] ) {
231- skippedRecordsForTables [ table ] = skippedRecordsForTables [ table ] + 1
232- } else {
233- skippedRecordsForTables [ table ] = 1
234- }
235- } )
236- const skippedRecordsStrings = [ ]
237- for ( let key in skippedRecordsForTables ) {
238- skippedRecordsStrings . push ( `${ key } - ${ skippedRecordsForTables [ key ] } ` )
239- }
240- details . push ( 'Skipped records: ' + skippedRecordsStrings . join ( ', ' ) )
241- }
242- if ( result . idConflicts . length > 0 ) {
243- // const conflicts = result.idConflicts
244- details. push ( 'ID conflicts: ' + result . idConflicts . join ( ', ' ) )
245- }
246- dispatch ( setStatusModal ( {
247- title : result . failed
248- ? 'Warning: Errors encountered during feed merge!'
249- : 'Feed merge was successful!' ,
250- body : result . failed
251- ? `Merge failed with ${ result . errorCount } errors. ${ result . failureReasons . join ( ', ' ) } `
252- : `Merge was completed successfully. A new version will be processed/validated containing the resulting feed.` ,
253- detail : details . join ( '\n' )
254- } ) )
260+ const modalContent = getMergeFeedModalContent ( result )
261+ dispatch ( setStatusModal ( modalContent ) )
255262 }
256263 }
257264 break
258265 default :
259266 console . warn ( `No completion step defined for job type ${ job . type } ` )
267+ break
260268 }
261269 }
262270}
0 commit comments