From 4ed55616affcb54443b50d0fae4b00f21c136eeb Mon Sep 17 00:00:00 2001 From: Simen Fivelstad Smaaberg <66635118+simensma-fresh@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:11:40 -0700 Subject: [PATCH] [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> --- Makefile | 7 + ...9.58__add_permit_extraction_task_table.sql | 21 ++ ...0.58__add_permit_condition_step_column.sql | 1 + ...d_permit_condition_step_column_version.sql | 1 + .../src/components/common/ActionMenu.tsx | 1 + .../common/CoreTableCommonColumns.tsx | 1 + services/common/src/constants/API.ts | 4 + .../src/redux/reducers/rootReducerShared.ts | 2 + .../src/redux/slices/permitServiceSlice.ts | 203 ++++++++++++++++ .../resources/download_token.py | 18 +- services/core-api/app/api/mines/namespace.py | 226 +++++++++++++----- .../models/permit_conditions.py | 20 +- .../permits/permit_extraction/__init__.py | 0 .../create_permit_conditions.py | 162 +++++++++++++ .../models/permit_condition_result.py | 39 +++ .../models/permit_extraction_task.py | 39 +++ .../models/response_model.py | 20 ++ .../permit_condition_extraction_resource.py | 137 +++++++++++ .../mines/permits/permit_extraction/tasks.py | 23 ++ .../search/search/permit_search_service.py | 104 +++++++- .../api/services/document_manager_service.py | 60 ++++- .../generate_history_table_migration.py | 46 +++- services/core-api/app/commands.py | 54 ++++- services/core-api/requirements.txt | 3 +- .../test_mine_document_list_resource.py | 29 ++- ...st_permit_condition_extraction_resource.py | 209 ++++++++++++++++ ...test_create_permit_conditions_from_task.py | 162 +++++++++++++ .../permits/permit_extraction/test_tasks.py | 56 +++++ .../mine/Permit/PermitConditionExtraction.tsx | 56 +++++ .../mine/Permit/PermitConditions.tsx | 26 ++ .../src/components/mine/Permit/ViewPermit.tsx | 143 +++++++++-- .../mine/Permit/ViewPermitOverview.tsx | 1 + .../__snapshots__/ViewPermit.spec.tsx.snap | 35 +-- .../ViewPermitOverview.spec.tsx.snap | 1 + services/document-manager/backend/celery.sh | 4 +- services/permits/tests/test_tasks.py | 18 -- 36 files changed, 1758 insertions(+), 174 deletions(-) create mode 100644 migrations/sql/V2024.09.03.19.58__add_permit_extraction_task_table.sql create mode 100644 migrations/sql/V2024.09.03.20.58__add_permit_condition_step_column.sql create mode 100644 migrations/sql/V2024.09.03.20.59__add_permit_condition_step_column_version.sql create mode 100644 services/common/src/redux/slices/permitServiceSlice.ts create mode 100644 services/core-api/app/api/mines/permits/permit_extraction/__init__.py create mode 100644 services/core-api/app/api/mines/permits/permit_extraction/create_permit_conditions.py create mode 100644 services/core-api/app/api/mines/permits/permit_extraction/models/permit_condition_result.py create mode 100644 services/core-api/app/api/mines/permits/permit_extraction/models/permit_extraction_task.py create mode 100644 services/core-api/app/api/mines/permits/permit_extraction/models/response_model.py create mode 100644 services/core-api/app/api/mines/permits/permit_extraction/resources/permit_condition_extraction_resource.py create mode 100644 services/core-api/app/api/mines/permits/permit_extraction/tasks.py create mode 100644 services/core-api/tests/permits/permit_extraction/resources/test_permit_condition_extraction_resource.py create mode 100644 services/core-api/tests/permits/permit_extraction/test_create_permit_conditions_from_task.py create mode 100644 services/core-api/tests/permits/permit_extraction/test_tasks.py create mode 100644 services/core-web/src/components/mine/Permit/PermitConditionExtraction.tsx delete mode 100644 services/permits/tests/test_tasks.py diff --git a/Makefile b/Makefile index 851c1978f5..7e959dcac0 100644 --- a/Makefile +++ b/Makefile @@ -147,6 +147,13 @@ generate_history_table_migration: @echo "+\n++ Generating history table migration ...\n+" @docker compose $(DC_FILE) exec backend bash -c "flask generate_history_table_migration $(TABLE)" + +# Generates a migration file for the specified table +# Usage: make generate_migration TABLE= +generate_table_migration: + @echo "+\n++ Generating history table migration ...\n+" + @docker compose $(DC_FILE) exec backend bash -c "flask generate_table_migration $(TABLE)" + # initial project setup for local/codespaces development init: @./bin/setup_codespaces.sh diff --git a/migrations/sql/V2024.09.03.19.58__add_permit_extraction_task_table.sql b/migrations/sql/V2024.09.03.19.58__add_permit_extraction_task_table.sql new file mode 100644 index 0000000000..90605edabb --- /dev/null +++ b/migrations/sql/V2024.09.03.19.58__add_permit_extraction_task_table.sql @@ -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); \ No newline at end of file diff --git a/migrations/sql/V2024.09.03.20.58__add_permit_condition_step_column.sql b/migrations/sql/V2024.09.03.20.58__add_permit_condition_step_column.sql new file mode 100644 index 0000000000..b7127d9fa9 --- /dev/null +++ b/migrations/sql/V2024.09.03.20.58__add_permit_condition_step_column.sql @@ -0,0 +1 @@ +ALTER TABLE permit_conditions ADD COLUMN step VARCHAR(50); \ No newline at end of file diff --git a/migrations/sql/V2024.09.03.20.59__add_permit_condition_step_column_version.sql b/migrations/sql/V2024.09.03.20.59__add_permit_condition_step_column_version.sql new file mode 100644 index 0000000000..9fb7df4eb4 --- /dev/null +++ b/migrations/sql/V2024.09.03.20.59__add_permit_condition_step_column_version.sql @@ -0,0 +1 @@ +ALTER TABLE permit_conditions_version ADD COLUMN step VARCHAR(50); \ No newline at end of file diff --git a/services/common/src/components/common/ActionMenu.tsx b/services/common/src/components/common/ActionMenu.tsx index 9112214a61..d0eff8ceae 100644 --- a/services/common/src/components/common/ActionMenu.tsx +++ b/services/common/src/components/common/ActionMenu.tsx @@ -24,6 +24,7 @@ export const generateActionMenuItems = (actionItems: ITableAction[], record) => label: (