-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MDS-6118] FE extract permits - DRAFT #3236
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dc7464a
make a button on the FE call the BE. Write reducer for permit service…
taraepp 8805240
stub out extraction method on core-api, tweak logic on view permit page
taraepp 5e37631
adjust FE to better match anticipated BE. Get rid of key error on ove…
taraepp 9d99706
migration to store task id in a table. Stub in BE but I am getting NO…
taraepp 32b0163
stub in BE functions
taraepp e4dcf1d
MDS-6118 Added working permit condition flow
simensma-fresh c5e59a2
MDS-6118 Fixed tasks + added tests
simensma-fresh fa04ccb
MDS-6118 Fixed tests
simensma-fresh 0c8d8ee
Mock celery task
simensma-fresh 0f2df56
fix some front-end issues
taraepp 9f10e86
Merge branch 'develop' into mds-6118-fe-extract-permits
taraepp add481d
tidy up files
taraepp d969c99
update snaps
taraepp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
import { createAppSlice, rejectHandler } from "@mds/common/redux/createAppSlice"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @taraepp Put in actual implementations here for the
|
||
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 { permit_amendment_id, 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a little script to auto-generate a CREATE TABLE migration for new tables.
Pretty much the same as the history table creation scripts, just with creating the actual table instead of a
_version
table