-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MDS-6118] FE extract permits - DRAFT (#3236)
* make a button on the FE call the BE. Write reducer for permit service covering basic functionality * stub out extraction method on core-api, tweak logic on view permit page * adjust FE to better match anticipated BE. Get rid of key error on overview * migration to store task id in a table. Stub in BE but I am getting NOT FOUND so namespace config must be wrong * stub in BE functions * MDS-6118 Added working permit condition flow * MDS-6118 Fixed tasks + added tests * MDS-6118 Fixed tests * Mock celery task * fix some front-end issues * tidy up files * update snaps --------- Co-authored-by: Tara Epp <102187683+taraepp@users.noreply.github.com>
- Loading branch information
1 parent
3de545f
commit 4ed5561
Showing
36 changed files
with
1,758 additions
and
174 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
21 changes: 21 additions & 0 deletions
21
migrations/sql/V2024.09.03.19.58__add_permit_extraction_task_table.sql
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,21 @@ | ||
-- This file was generated by the generate_table_ddl command | ||
-- The file contains the corresponding history table definition for the permit_extraction_task table | ||
CREATE TABLE permit_extraction_task ( | ||
create_user VARCHAR(60) NOT NULL, | ||
create_timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL, | ||
update_user VARCHAR(60) NOT NULL, | ||
update_timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL, | ||
permit_extraction_task_id UUID NOT NULL, | ||
task_id VARCHAR(255) NOT NULL, | ||
task_status VARCHAR(255) NOT NULL, | ||
task_meta JSON, | ||
task_result JSON, | ||
core_status_task_id VARCHAR(255), | ||
permit_amendment_guid UUID NOT NULL, | ||
permit_amendment_document_guid UUID NOT NULL, | ||
PRIMARY KEY (permit_extraction_task_id), | ||
FOREIGN KEY(permit_amendment_guid) REFERENCES permit_amendment (permit_amendment_guid), | ||
FOREIGN KEY(permit_amendment_document_guid) REFERENCES permit_amendment_document (permit_amendment_document_guid) | ||
); | ||
CREATE INDEX IF NOT EXISTS permit_extraction_task_id_idx ON permit_extraction_task (task_id); | ||
CREATE INDEX IF NOT EXISTS permit_extraction_amend_guid_idx ON permit_extraction_task (permit_amendment_guid); |
1 change: 1 addition & 0 deletions
1
migrations/sql/V2024.09.03.20.58__add_permit_condition_step_column.sql
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 @@ | ||
ALTER TABLE permit_conditions ADD COLUMN step VARCHAR(50); |
1 change: 1 addition & 0 deletions
1
migrations/sql/V2024.09.03.20.59__add_permit_condition_step_column_version.sql
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 @@ | ||
ALTER TABLE permit_conditions_version ADD COLUMN step VARCHAR(50); |
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,203 @@ | ||
import { createAppSlice, rejectHandler } from "@mds/common/redux/createAppSlice"; | ||
import { hideLoading, showLoading } from "react-redux-loading-bar"; | ||
import CustomAxios from "@mds/common/redux/customAxios"; | ||
import { ItemMap } from "@mds/common/interfaces"; | ||
import { | ||
ENVIRONMENT, | ||
PERMIT_SERVICE_EXTRACTION, | ||
POLL_PERMIT_SERVICE_EXTRACTION, | ||
} from "@mds/common/constants"; | ||
import { createSelector } from "@reduxjs/toolkit"; | ||
|
||
const createRequestHeader = REQUEST_HEADER.createRequestHeader; | ||
|
||
export const permitServiceReducerType = "permitService"; | ||
|
||
export enum PermitExtractionStatus { | ||
not_started = "Not Started", | ||
in_progress = "In Progress", | ||
complete = "Extraction Complete", | ||
error = "Error Extracting", | ||
} | ||
|
||
const permitExtractionStatusMap = { | ||
PENDING: PermitExtractionStatus.in_progress, | ||
RECEIVED: PermitExtractionStatus.in_progress, | ||
PROGRESS: PermitExtractionStatus.in_progress, | ||
RETRY: PermitExtractionStatus.in_progress, | ||
STARTED: PermitExtractionStatus.in_progress, | ||
REVOKED: PermitExtractionStatus.error, | ||
FAILURE: PermitExtractionStatus.error, | ||
SUCCESS: PermitExtractionStatus.complete, | ||
}; | ||
|
||
interface PermitExtraction { | ||
task_status: PermitExtractionStatus; | ||
task_id: string; | ||
} | ||
|
||
interface PermitServiceState { | ||
// object of: permit_amendment_id: {status: x, task_id: y} | ||
extractions: ItemMap<PermitExtraction>; | ||
} | ||
|
||
const initialState: PermitServiceState = { | ||
extractions: {}, | ||
}; | ||
|
||
const permitServiceSlice = createAppSlice({ | ||
name: permitServiceReducerType, | ||
initialState, | ||
reducers: (create) => ({ | ||
initiatePermitExtraction: create.asyncThunk( | ||
async ( | ||
payload: { permit_amendment_id: number; permit_amendment_document_guid: string }, | ||
thunkAPI | ||
) => { | ||
const headers = createRequestHeader(); | ||
thunkAPI.dispatch(showLoading()); | ||
|
||
const response = await CustomAxios({ | ||
errorToastMessage: "default", | ||
}).post(`${ENVIRONMENT.apiUrl}${PERMIT_SERVICE_EXTRACTION}`, payload, headers); | ||
thunkAPI.dispatch(hideLoading()); | ||
|
||
return response.data; | ||
}, | ||
{ | ||
fulfilled: (state, action) => { | ||
const { permit_amendment_id } = action.meta.arg; | ||
const { task_id, task_status } = action.payload; | ||
state.extractions[permit_amendment_id] = { | ||
task_id, | ||
task_status: permitExtractionStatusMap[task_status], | ||
}; | ||
}, | ||
pending: (state, action) => { | ||
const { permit_amendment_id } = action.meta.arg; | ||
state.extractions[permit_amendment_id] = { | ||
task_status: PermitExtractionStatus.in_progress, | ||
task_id: null, | ||
}; | ||
}, | ||
rejected: (state, action) => { | ||
const { permit_amendment_id } = action.meta.arg; | ||
state.extractions[permit_amendment_id] = { | ||
task_status: PermitExtractionStatus.error, | ||
task_id: null, | ||
}; | ||
rejectHandler(action); | ||
}, | ||
} | ||
), | ||
fetchPermitExtractionTasks: create.asyncThunk( | ||
async (payload: { permit_amendment_id: number }, thunkAPI) => { | ||
const { permit_amendment_id } = payload; | ||
const headers = createRequestHeader(); | ||
thunkAPI.dispatch(showLoading()); | ||
|
||
const response = await CustomAxios({ | ||
errorToastMessage: "default", | ||
}).get( | ||
`${ENVIRONMENT.apiUrl}${PERMIT_SERVICE_EXTRACTION}?permit_amendment_id=${permit_amendment_id}`, | ||
headers | ||
); | ||
|
||
thunkAPI.dispatch(hideLoading()); | ||
return response.data.tasks[0]; | ||
}, | ||
{ | ||
fulfilled: (state, action) => { | ||
if (!action.payload) return; | ||
const { permit_amendment_id } = action.meta.arg; | ||
const { task_id, task_status } = action.payload; | ||
state.extractions[permit_amendment_id] = { | ||
task_id: task_id, | ||
task_status: permitExtractionStatusMap[task_status], | ||
}; | ||
}, | ||
rejected: (state, action) => { | ||
rejectHandler(action); | ||
}, | ||
} | ||
), | ||
|
||
fetchPermitExtractionStatus: create.asyncThunk( | ||
async (payload: { permit_amendment_id: number; task_id: string }, thunkAPI) => { | ||
const { task_id } = payload; | ||
|
||
const headers = createRequestHeader(); | ||
thunkAPI.dispatch(showLoading()); | ||
|
||
const response = await CustomAxios({ | ||
errorToastMessage: "default", | ||
}).get(`${ENVIRONMENT.apiUrl}${POLL_PERMIT_SERVICE_EXTRACTION(task_id)}`, headers); | ||
|
||
thunkAPI.dispatch(hideLoading()); | ||
return response.data; | ||
}, | ||
{ | ||
fulfilled: (state, action) => { | ||
const { permit_amendment_id } = action.meta.arg; | ||
const { task_id, task_status } = action.payload; | ||
state.extractions[permit_amendment_id] = { | ||
task_id: task_id, | ||
task_status: permitExtractionStatusMap[task_status], | ||
}; | ||
}, | ||
rejected: (state, action) => { | ||
rejectHandler(action); | ||
}, | ||
} | ||
), | ||
deletePermitConditions: create.asyncThunk( | ||
async (payload: { permit_amendment_id: number }, thunkAPI) => { | ||
const headers = createRequestHeader(); | ||
thunkAPI.dispatch(showLoading()); | ||
const { permit_amendment_id } = payload; | ||
const response = await CustomAxios({ | ||
errorToastMessage: "default", | ||
}).delete( | ||
`${ENVIRONMENT.apiUrl}${PERMIT_SERVICE_EXTRACTION}?permit_amendment_id=${permit_amendment_id}`, | ||
headers | ||
); | ||
|
||
thunkAPI.dispatch(hideLoading()); | ||
return response.data; | ||
}, | ||
{ | ||
fulfilled: (state, action) => { | ||
const { permit_amendment_id } = action.meta.arg; | ||
state.extractions[permit_amendment_id] = { | ||
task_status: PermitExtractionStatus.not_started, | ||
task_id: null, | ||
}; | ||
}, | ||
rejected: (state, action) => { | ||
rejectHandler(action); | ||
}, | ||
} | ||
), | ||
}), | ||
selectors: { | ||
getPermitExtractionState: (state: PermitServiceState) => { | ||
return state.extractions; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { getPermitExtractionState } = permitServiceSlice.selectors; | ||
export const { | ||
initiatePermitExtraction, | ||
fetchPermitExtractionStatus, | ||
fetchPermitExtractionTasks, | ||
deletePermitConditions, | ||
} = permitServiceSlice.actions; | ||
|
||
export const getPermitExtractionByGuid = (permit_amendment_id: number) => | ||
createSelector([getPermitExtractionState], (extractions) => { | ||
return extractions[permit_amendment_id]; | ||
}); | ||
|
||
const permitServiceReducer = permitServiceSlice.reducer; | ||
export default permitServiceReducer; |
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.