From 2cb084725dc6b5d7a756661a8e72dbe85262b8f8 Mon Sep 17 00:00:00 2001 From: Tilly Whitson <35410637+tillyw@users.noreply.github.com> Date: Fri, 1 Mar 2024 18:06:05 -0600 Subject: [PATCH 01/15] makes audit field timestamps match --- moped-database/metadata/tables.yaml | 8 -------- .../down.sql | 1 + .../up.sql | 10 ++++++++++ 3 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql create mode 100644 moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql diff --git a/moped-database/metadata/tables.yaml b/moped-database/metadata/tables.yaml index 55592318c6..608c69f58e 100644 --- a/moped-database/metadata/tables.yaml +++ b/moped-database/metadata/tables.yaml @@ -2650,7 +2650,6 @@ - milestone_order - project_id - is_deleted - comment: No insert permissions on audit fields - role: moped-editor permission: check: {} @@ -2666,7 +2665,6 @@ - milestone_order - project_id - is_deleted - comment: No insert permissions on audit fields select_permissions: - role: moped-admin permission: @@ -2735,7 +2733,6 @@ check: {} set: updated_by_user_id: x-hasura-user-db-id - comment: No update permissions on audit fields - role: moped-editor permission: columns: @@ -2751,7 +2748,6 @@ check: {} set: updated_by_user_id: x-hasura-user-db-id - comment: No update permissions on audit fields event_triggers: - name: activity_log_moped_proj_milestones definition: @@ -2824,7 +2820,6 @@ - project_id - project_note - project_note_type - comment: No insert permissions on audit fields - role: moped-editor permission: check: {} @@ -2837,7 +2832,6 @@ - project_id - project_note - project_note_type - comment: No insert permissions on audit fields select_permissions: - role: moped-admin permission: @@ -2897,7 +2891,6 @@ check: null set: updated_by_user_id: x-hasura-user-db-id - comment: No update permissions on audit fields - role: moped-editor permission: columns: @@ -2910,7 +2903,6 @@ check: null set: updated_by_user_id: x-hasura-user-db-id - comment: No update permissions on audit fields event_triggers: - name: activity_log_moped_proj_notes definition: diff --git a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql new file mode 100644 index 0000000000..2af3d5fca0 --- /dev/null +++ b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql @@ -0,0 +1 @@ +ALTER TABLE "public"."moped_proj_phases" ALTER COLUMN "updated_at" drop default; diff --git a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql new file mode 100644 index 0000000000..fb390d305a --- /dev/null +++ b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql @@ -0,0 +1,10 @@ +alter table "public"."moped_proj_phases" alter column "updated_at" set default clock_timestamp(); + +DROP TRIGGER update_moped_proj_phases_and_project_audit_fields ON moped_proj_phases; + +CREATE TRIGGER update_moped_proj_phases_and_project_audit_fields + BEFORE UPDATE ON moped_proj_phases + FOR EACH ROW + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields (); + +COMMENT ON TRIGGER update_moped_proj_phases_and_project_audit_fields ON moped_proj_phases IS 'Trigger to execute the update_self_and_project_updated_audit_fields function before each update operation on the moped_proj_phases table.'; From b83f34175b49b1013ed5a5fa91c3200b710b3cc1 Mon Sep 17 00:00:00 2001 From: Moped View Bot Date: Sat, 2 Mar 2024 00:07:31 +0000 Subject: [PATCH 02/15] =?UTF-8?q?=F0=9F=A4=96=20Export=20view=20for=201604?= =?UTF-8?q?7=5Fmake=5Faudit=5Ffield=5Ftimestamps=5Fmatch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- moped-database/views/project_list_view.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moped-database/views/project_list_view.sql b/moped-database/views/project_list_view.sql index f3674b4b76..0143a47ab2 100644 --- a/moped-database/views/project_list_view.sql +++ b/moped-database/views/project_list_view.sql @@ -219,10 +219,10 @@ LEFT JOIN project_district_association districts ON mp.project_id = districts.pr LEFT JOIN LATERAL ( SELECT mpn.project_note, - mpn.date_created + mpn.created_at AS date_created FROM moped_proj_notes mpn WHERE mpn.project_id = mp.project_id AND mpn.project_note_type = 2 AND mpn.is_deleted = false - ORDER BY mpn.date_created DESC + ORDER BY mpn.created_at DESC LIMIT 1 ) proj_status_update ON true WHERE mp.is_deleted = false From 64af29568c1e80747e3ab8e69db3734650da3769 Mon Sep 17 00:00:00 2001 From: Tilly Whitson <35410637+tillyw@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:01:42 -0500 Subject: [PATCH 03/15] fixes fields --- .../up.sql | 89 ++++++++++++++++++- 1 file changed, 85 insertions(+), 4 deletions(-) diff --git a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql index fb390d305a..1f79632849 100644 --- a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql +++ b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql @@ -1,10 +1,91 @@ -alter table "public"."moped_proj_phases" alter column "updated_at" set default clock_timestamp(); +alter table feature_drawn_lines alter column updated_at set default now(); +alter table feature_drawn_points alter column updated_at set default now(); +alter table feature_intersections alter column updated_at set default now(); +alter table feature_signals alter column updated_at set default now(); +alter table feature_street_segments alter column updated_at set default now(); +alter table moped_project alter column created_at set default now(); +alter table moped_project alter column updated_at set default now(); +alter table moped_proj_components alter column updated_at set default now(); +alter table moped_proj_funding alter column created_at set default now(); +alter table moped_proj_funding alter column updated_at set default now(); +alter table moped_proj_milestones alter column created_at set default now(); +alter table moped_proj_milestones alter column updated_at set default now(); +alter table moped_proj_notes alter column created_at set default now(); +alter table moped_proj_notes alter column updated_at set default now(); +alter table moped_proj_phases alter column created_at set default now(); +alter table moped_proj_phases alter column updated_at set default now(); +alter table moped_proj_work_activity alter column updated_at set default now(); -DROP TRIGGER update_moped_proj_phases_and_project_audit_fields ON moped_proj_phases; +DROP TRIGGER set_feature_drawn_lines_updated_at ON feature_drawn_lines; +DROP TRIGGER set_feature_drawn_points_updated_at ON feature_drawn_points; +DROP TRIGGER set_feature_intersections_updated_at ON feature_intersections; +DROP TRIGGER set_feature_signals_updated_at ON feature_signals; +DROP TRIGGER set_feature_street_segments_updated_at ON feature_street_segments; +DROP TRIGGER set_moped_project_updated_at ON moped_project; +DROP TRIGGER update_moped_proj_components_and_project_audit_fields ON moped_proj_components; +DROP TRIGGER update_moped_proj_funding_and_project_audit_fields ON moped_proj_funding; +DROP TRIGGER update_moped_proj_milestones_and_project_audit_fields ON moped_proj_milestones; +DROP TRIGGER update_moped_proj_notes_and_project_audit_fields ON moped_proj_notes; +DROP TRIGGER update_moped_proj_phases_and_project_audit_fields ON moped_proj_phases; +DROP TRIGGER update_moped_proj_work_activity_and_project_audit_fields ON moped_proj_work_activity; + +CREATE TRIGGER set_feature_drawn_lines_updated_at + BEFORE UPDATE ON feature_drawn_lines + FOR EACH ROW + EXECUTE FUNCTION public.set_updated_at(); + +CREATE TRIGGER set_feature_drawn_points_updated_at + BEFORE UPDATE ON feature_drawn_points + FOR EACH ROW + EXECUTE FUNCTION public.set_updated_at(); + +CREATE TRIGGER set_feature_intersections_updated_at + BEFORE UPDATE ON feature_intersections + FOR EACH ROW + EXECUTE FUNCTION public.set_updated_at(); + +CREATE TRIGGER set_feature_signals_updated_at + BEFORE UPDATE ON feature_signals + FOR EACH ROW + EXECUTE FUNCTION public.set_updated_at(); + +CREATE TRIGGER set_feature_street_segments_updated_at + BEFORE UPDATE ON feature_street_segments + FOR EACH ROW + EXECUTE FUNCTION public.set_updated_at(); + +CREATE TRIGGER set_moped_project_updated_at + BEFORE UPDATE ON moped_project + FOR EACH ROW + EXECUTE FUNCTION public.set_updated_at(); + +CREATE TRIGGER update_moped_proj_components_and_project_audit_fields + BEFORE UPDATE ON moped_proj_components + FOR EACH ROW + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); + +CREATE TRIGGER update_moped_proj_funding_and_project_audit_fields + BEFORE UPDATE ON moped_proj_funding + FOR EACH ROW + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); + +CREATE TRIGGER update_moped_proj_milestones_and_project_audit_fields + BEFORE UPDATE ON moped_proj_milestones + FOR EACH ROW + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); + +CREATE TRIGGER update_moped_proj_notes_and_project_audit_fields + BEFORE UPDATE ON moped_proj_notes + FOR EACH ROW + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); CREATE TRIGGER update_moped_proj_phases_and_project_audit_fields BEFORE UPDATE ON moped_proj_phases FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields (); + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); + +CREATE TRIGGER update_moped_proj_work_activity_and_project_audit_fields + BEFORE UPDATE ON moped_proj_work_activity + FOR EACH ROW + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); -COMMENT ON TRIGGER update_moped_proj_phases_and_project_audit_fields ON moped_proj_phases IS 'Trigger to execute the update_self_and_project_updated_audit_fields function before each update operation on the moped_proj_phases table.'; From 986316b5289791ee8fc0b65c607d8e217feb2065 Mon Sep 17 00:00:00 2001 From: Tilly Whitson <35410637+tillyw@users.noreply.github.com> Date: Wed, 20 Mar 2024 15:00:25 -0500 Subject: [PATCH 04/15] adds down migration --- .../down.sql | 78 ++++++++++++++++++- .../up.sql | 8 -- 2 files changed, 77 insertions(+), 9 deletions(-) diff --git a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql index 2af3d5fca0..0acbcf4aa2 100644 --- a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql +++ b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql @@ -1 +1,77 @@ -ALTER TABLE "public"."moped_proj_phases" ALTER COLUMN "updated_at" drop default; +alter table feature_drawn_lines alter column updated_at drop default; +alter table feature_drawn_points alter column updated_at drop default; +alter table feature_intersections alter column updated_at drop default; +alter table feature_signals alter column updated_at drop default; +alter table feature_street_segments alter column updated_at drop default; +alter table moped_proj_components alter column updated_at drop default; +alter table moped_proj_funding alter column created_at set default clock_timestamp(); +alter table moped_proj_funding alter column updated_at drop default; +alter table moped_proj_milestones alter column created_at set default clock_timestamp(); +alter table moped_proj_milestones alter column updated_at set drop default; +alter table moped_proj_notes alter column created_at set default clock_timestamp(); +alter table moped_proj_notes alter column updated_at drop default; +alter table moped_proj_phases alter column created_at set default clock_timestamp(); +alter table moped_proj_phases alter column updated_at drop default; +alter table moped_proj_work_activity alter column updated_at drop default; + +CREATE TRIGGER set_feature_drawn_lines_updated_at + BEFORE UPDATE ON feature_drawn_lines + FOR EACH ROW + EXECUTE FUNCTION public.set_updated_at(); + +CREATE TRIGGER set_feature_drawn_points_updated_at + BEFORE UPDATE ON feature_drawn_points + FOR EACH ROW + EXECUTE FUNCTION public.set_updated_at(); + +CREATE TRIGGER set_feature_intersections_updated_at + BEFORE UPDATE ON feature_intersections + FOR EACH ROW + EXECUTE FUNCTION public.set_updated_at(); + +CREATE TRIGGER set_feature_signals_updated_at + BEFORE UPDATE ON feature_signals + FOR EACH ROW + EXECUTE FUNCTION public.set_updated_at(); + +CREATE TRIGGER set_feature_street_segments_updated_at + BEFORE UPDATE ON feature_street_segments + FOR EACH ROW + EXECUTE FUNCTION public.set_updated_at(); + +CREATE TRIGGER update_moped_proj_components_and_project_audit_fields + BEFORE INSERT + OR UPDATE ON moped_proj_components + FOR EACH ROW + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); + +CREATE TRIGGER update_moped_proj_funding_and_project_audit_fields + BEFORE INSERT + OR UPDATE ON moped_proj_funding + FOR EACH ROW + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); + +CREATE TRIGGER update_moped_proj_milestones_and_project_audit_fields + BEFORE INSERT + OR UPDATE ON moped_proj_milestones + FOR EACH ROW + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); + +CREATE TRIGGER update_moped_proj_notes_and_project_audit_fields + BEFORE INSERT + OR UPDATE ON moped_proj_notes + FOR EACH ROW + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); + +CREATE TRIGGER update_moped_proj_phases_and_project_audit_fields + BEFORE INSERT + OR UPDATE ON moped_proj_phases + FOR EACH ROW + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); + +CREATE TRIGGER update_moped_proj_work_activity_and_project_audit_fields + BEFORE INSERT + OR UPDATE ON moped_proj_work_activity + FOR EACH ROW + EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); + \ No newline at end of file diff --git a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql index 1f79632849..799cdd6b8e 100644 --- a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql +++ b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql @@ -3,8 +3,6 @@ alter table feature_drawn_points alter column updated_at set default now(); alter table feature_intersections alter column updated_at set default now(); alter table feature_signals alter column updated_at set default now(); alter table feature_street_segments alter column updated_at set default now(); -alter table moped_project alter column created_at set default now(); -alter table moped_project alter column updated_at set default now(); alter table moped_proj_components alter column updated_at set default now(); alter table moped_proj_funding alter column created_at set default now(); alter table moped_proj_funding alter column updated_at set default now(); @@ -21,7 +19,6 @@ DROP TRIGGER set_feature_drawn_points_updated_at ON feature_drawn_points; DROP TRIGGER set_feature_intersections_updated_at ON feature_intersections; DROP TRIGGER set_feature_signals_updated_at ON feature_signals; DROP TRIGGER set_feature_street_segments_updated_at ON feature_street_segments; -DROP TRIGGER set_moped_project_updated_at ON moped_project; DROP TRIGGER update_moped_proj_components_and_project_audit_fields ON moped_proj_components; DROP TRIGGER update_moped_proj_funding_and_project_audit_fields ON moped_proj_funding; DROP TRIGGER update_moped_proj_milestones_and_project_audit_fields ON moped_proj_milestones; @@ -54,11 +51,6 @@ CREATE TRIGGER set_feature_street_segments_updated_at FOR EACH ROW EXECUTE FUNCTION public.set_updated_at(); -CREATE TRIGGER set_moped_project_updated_at - BEFORE UPDATE ON moped_project - FOR EACH ROW - EXECUTE FUNCTION public.set_updated_at(); - CREATE TRIGGER update_moped_proj_components_and_project_audit_fields BEFORE UPDATE ON moped_proj_components FOR EACH ROW From bdfbf029c8234a9a7b3336a1dd85e95690166d51 Mon Sep 17 00:00:00 2001 From: Tilly Whitson <35410637+tillyw@users.noreply.github.com> Date: Wed, 20 Mar 2024 18:04:56 -0500 Subject: [PATCH 05/15] delete extra line --- .../up.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql index 799cdd6b8e..4f471d308c 100644 --- a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql +++ b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql @@ -80,4 +80,3 @@ CREATE TRIGGER update_moped_proj_work_activity_and_project_audit_fields BEFORE UPDATE ON moped_proj_work_activity FOR EACH ROW EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); - From b7a112f5669e46d424855915bf539cadf7c2aa1e Mon Sep 17 00:00:00 2001 From: Tilly Whitson <35410637+tillyw@users.noreply.github.com> Date: Wed, 20 Mar 2024 18:05:42 -0500 Subject: [PATCH 06/15] fixes line --- .../down.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql index 0acbcf4aa2..ad2b849d3c 100644 --- a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql +++ b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql @@ -74,4 +74,3 @@ CREATE TRIGGER update_moped_proj_work_activity_and_project_audit_fields OR UPDATE ON moped_proj_work_activity FOR EACH ROW EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); - \ No newline at end of file From 396ac062b65063e3b7a4ceda7e7e03e1cc0c82cd Mon Sep 17 00:00:00 2001 From: Tilly Whitson <35410637+tillyw@users.noreply.github.com> Date: Wed, 20 Mar 2024 18:15:38 -0500 Subject: [PATCH 07/15] fix comments --- moped-database/metadata/tables.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/moped-database/metadata/tables.yaml b/moped-database/metadata/tables.yaml index 608c69f58e..0ad18f5814 100644 --- a/moped-database/metadata/tables.yaml +++ b/moped-database/metadata/tables.yaml @@ -2650,6 +2650,7 @@ - milestone_order - project_id - is_deleted + comment: No insert permissions on audit fields - role: moped-editor permission: check: {} @@ -2665,6 +2666,7 @@ - milestone_order - project_id - is_deleted + comment: No insert permissions on audit fields select_permissions: - role: moped-admin permission: @@ -2733,6 +2735,7 @@ check: {} set: updated_by_user_id: x-hasura-user-db-id + comment: No update permissions on audit fields - role: moped-editor permission: columns: @@ -2748,6 +2751,7 @@ check: {} set: updated_by_user_id: x-hasura-user-db-id + comment: No update permissions on audit fields event_triggers: - name: activity_log_moped_proj_milestones definition: @@ -2820,6 +2824,7 @@ - project_id - project_note - project_note_type + comment: No insert permissions on audit fields - role: moped-editor permission: check: {} @@ -2832,6 +2837,7 @@ - project_id - project_note - project_note_type + comment: No insert permissions on audit fields select_permissions: - role: moped-admin permission: @@ -2891,6 +2897,7 @@ check: null set: updated_by_user_id: x-hasura-user-db-id + comment: No update permissions on audit fields - role: moped-editor permission: columns: @@ -2903,6 +2910,7 @@ check: null set: updated_by_user_id: x-hasura-user-db-id + comment: No update permissions on audit fields event_triggers: - name: activity_log_moped_proj_notes definition: From f044bcf1d4ab591c772e10da6aaa4e746aade634 Mon Sep 17 00:00:00 2001 From: chiaberry Date: Thu, 21 Mar 2024 14:25:42 -0500 Subject: [PATCH 08/15] if there is not a clicked component check in the related components --- .../projects/projectView/ProjectComponents/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/moped-editor/src/views/projects/projectView/ProjectComponents/index.js b/moped-editor/src/views/projects/projectView/ProjectComponents/index.js index d85c69c2f4..d4f991b6d1 100644 --- a/moped-editor/src/views/projects/projectView/ProjectComponents/index.js +++ b/moped-editor/src/views/projects/projectView/ProjectComponents/index.js @@ -181,10 +181,17 @@ export default function MapView({ (component) => component.project_component_id === clickedComponentId ); - setClickedComponent(updatedClickedComponent); - }, [clickedComponent, projectComponents]); + if (!!updatedClickedComponent) { + setClickedComponent(updatedClickedComponent) + } else { + const updatedrelatedClickedComponent = allRelatedComponents.find( + (component) => component.project_component_id === clickedComponentId + ); + setClickedComponent(updatedrelatedClickedComponent); + } + }, [clickedComponent, projectComponents, allRelatedComponents]); - // Keep draft component state in sync wiht clicked component (when editing) + // Keep draft component state in sync with clicked component (when editing) useEffect(() => { if (clickedComponent && !editState.isEditingComponent) { editDispatch({ type: "set_draft_component", payload: clickedComponent }); From 88b11dc55594a673d6bf4c8f7f226e6956c5e85f Mon Sep 17 00:00:00 2001 From: chiaberry Date: Thu, 21 Mar 2024 15:19:02 -0500 Subject: [PATCH 09/15] check related components in the params as well --- .../projectView/ProjectComponents/index.js | 18 ++++++++---------- .../utils/useComponentLinkParams.js | 11 ++++++++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/moped-editor/src/views/projects/projectView/ProjectComponents/index.js b/moped-editor/src/views/projects/projectView/ProjectComponents/index.js index d4f991b6d1..bf60fff27f 100644 --- a/moped-editor/src/views/projects/projectView/ProjectComponents/index.js +++ b/moped-editor/src/views/projects/projectView/ProjectComponents/index.js @@ -130,6 +130,7 @@ export default function MapView({ useComponentLinkParams({ setClickedComponent, projectComponents, + allRelatedComponents, clickedComponent, errorMessageDispatch, mapRef, @@ -177,18 +178,15 @@ export default function MapView({ if (clickedComponent === null) return; const clickedComponentId = clickedComponent?.project_component_id; - const updatedClickedComponent = projectComponents.find( - (component) => component.project_component_id === clickedComponentId - ); - - if (!!updatedClickedComponent) { - setClickedComponent(updatedClickedComponent) - } else { - const updatedrelatedClickedComponent = allRelatedComponents.find( + const updatedClickedComponent = + projectComponents.find( + (component) => component.project_component_id === clickedComponentId + ) || + allRelatedComponents.find( (component) => component.project_component_id === clickedComponentId ); - setClickedComponent(updatedrelatedClickedComponent); - } + + setClickedComponent(updatedClickedComponent); }, [clickedComponent, projectComponents, allRelatedComponents]); // Keep draft component state in sync with clicked component (when editing) diff --git a/moped-editor/src/views/projects/projectView/ProjectComponents/utils/useComponentLinkParams.js b/moped-editor/src/views/projects/projectView/ProjectComponents/utils/useComponentLinkParams.js index bea48ff1ad..24a7beff76 100644 --- a/moped-editor/src/views/projects/projectView/ProjectComponents/utils/useComponentLinkParams.js +++ b/moped-editor/src/views/projects/projectView/ProjectComponents/utils/useComponentLinkParams.js @@ -39,6 +39,7 @@ const updateParamsWithoutRender = (queryKey, queryValue) => { export const useComponentLinkParams = ({ setClickedComponent, projectComponents, + allRelatedComponents, errorMessageDispatch, mapRef, }) => { @@ -62,9 +63,13 @@ export const useComponentLinkParams = ({ // Set clicked component from search parameter once projectComponents data loads if (projectComponents.length > 0) { - const componentFromParams = projectComponents.find( - (component) => component.project_component_id === componentParamId - ); + const componentFromParams = + projectComponents.find( + (component) => component.project_component_id === componentParamId + ) || + allRelatedComponents.find( + (component) => component.project_component_id === componentParamId + ); if (componentFromParams) { // Set clickedComponent found from params From 4fa194791ba6d59e2a36632c5b37e7e413f75931 Mon Sep 17 00:00:00 2001 From: chiaberry Date: Thu, 21 Mar 2024 15:23:31 -0500 Subject: [PATCH 10/15] add to the dependency array --- .../ProjectComponents/utils/useComponentLinkParams.js | 1 + 1 file changed, 1 insertion(+) diff --git a/moped-editor/src/views/projects/projectView/ProjectComponents/utils/useComponentLinkParams.js b/moped-editor/src/views/projects/projectView/ProjectComponents/utils/useComponentLinkParams.js index 24a7beff76..a9b45d23f7 100644 --- a/moped-editor/src/views/projects/projectView/ProjectComponents/utils/useComponentLinkParams.js +++ b/moped-editor/src/views/projects/projectView/ProjectComponents/utils/useComponentLinkParams.js @@ -109,6 +109,7 @@ export const useComponentLinkParams = ({ hasComponentSetFromUrl, projectComponents, setClickedComponent, + allRelatedComponents, setHasComponentSetFromUrl, errorMessageDispatch, mapRef, From d74b91665c33f599dfbe3b50e6a4b67c188e93c2 Mon Sep 17 00:00:00 2001 From: chiaberry Date: Thu, 21 Mar 2024 16:35:54 -0500 Subject: [PATCH 11/15] also update the url params when clicking on the list --- .../projectView/ProjectComponents/RelatedComponentsList.js | 6 +++--- .../views/projects/projectView/ProjectComponents/index.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/moped-editor/src/views/projects/projectView/ProjectComponents/RelatedComponentsList.js b/moped-editor/src/views/projects/projectView/ProjectComponents/RelatedComponentsList.js index 365239acc6..269938f71f 100644 --- a/moped-editor/src/views/projects/projectView/ProjectComponents/RelatedComponentsList.js +++ b/moped-editor/src/views/projects/projectView/ProjectComponents/RelatedComponentsList.js @@ -8,7 +8,7 @@ const RelatedComponentsList = ({ editState, shouldShowRelatedProjects, clickedComponent, - setClickedComponent, + makeClickedComponentUpdates, onClickZoomToComponent, allRelatedComponents, setIsClickedComponentRelated, @@ -21,10 +21,10 @@ const RelatedComponentsList = ({ const onListItemClick = (component) => { if (isExpanded(component)) { - setClickedComponent(null); + makeClickedComponentUpdates(null); setIsClickedComponentRelated(false); } else if (isNotCreatingOrEditing) { - setClickedComponent(component); + makeClickedComponentUpdates(component); setIsClickedComponentRelated(true); } }; diff --git a/moped-editor/src/views/projects/projectView/ProjectComponents/index.js b/moped-editor/src/views/projects/projectView/ProjectComponents/index.js index bf60fff27f..57e5f10f3a 100644 --- a/moped-editor/src/views/projects/projectView/ProjectComponents/index.js +++ b/moped-editor/src/views/projects/projectView/ProjectComponents/index.js @@ -292,7 +292,7 @@ export default function MapView({ editState={editState} shouldShowRelatedProjects={shouldShowRelatedProjects} clickedComponent={clickedComponent} - setClickedComponent={setClickedComponent} + makeClickedComponentUpdates={makeClickedComponentUpdates} onClickZoomToComponent={onClickZoomToComponent} allRelatedComponents={allRelatedComponents} setIsClickedComponentRelated={setIsClickedComponentRelated} From 04267aa2ed622fd505f58bf509a62430a568d066 Mon Sep 17 00:00:00 2001 From: Tilly Whitson <35410637+tillyw@users.noreply.github.com> Date: Thu, 21 Mar 2024 17:42:55 -0500 Subject: [PATCH 12/15] rewrite trigger function --- .../down.sql | 82 ++++------------- .../up.sql | 90 ++++--------------- 2 files changed, 36 insertions(+), 136 deletions(-) diff --git a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql index ad2b849d3c..70630246c6 100644 --- a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql +++ b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql @@ -1,8 +1,3 @@ -alter table feature_drawn_lines alter column updated_at drop default; -alter table feature_drawn_points alter column updated_at drop default; -alter table feature_intersections alter column updated_at drop default; -alter table feature_signals alter column updated_at drop default; -alter table feature_street_segments alter column updated_at drop default; alter table moped_proj_components alter column updated_at drop default; alter table moped_proj_funding alter column created_at set default clock_timestamp(); alter table moped_proj_funding alter column updated_at drop default; @@ -14,63 +9,20 @@ alter table moped_proj_phases alter column created_at set default clock_timestam alter table moped_proj_phases alter column updated_at drop default; alter table moped_proj_work_activity alter column updated_at drop default; -CREATE TRIGGER set_feature_drawn_lines_updated_at - BEFORE UPDATE ON feature_drawn_lines - FOR EACH ROW - EXECUTE FUNCTION public.set_updated_at(); - -CREATE TRIGGER set_feature_drawn_points_updated_at - BEFORE UPDATE ON feature_drawn_points - FOR EACH ROW - EXECUTE FUNCTION public.set_updated_at(); - -CREATE TRIGGER set_feature_intersections_updated_at - BEFORE UPDATE ON feature_intersections - FOR EACH ROW - EXECUTE FUNCTION public.set_updated_at(); - -CREATE TRIGGER set_feature_signals_updated_at - BEFORE UPDATE ON feature_signals - FOR EACH ROW - EXECUTE FUNCTION public.set_updated_at(); - -CREATE TRIGGER set_feature_street_segments_updated_at - BEFORE UPDATE ON feature_street_segments - FOR EACH ROW - EXECUTE FUNCTION public.set_updated_at(); - -CREATE TRIGGER update_moped_proj_components_and_project_audit_fields - BEFORE INSERT - OR UPDATE ON moped_proj_components - FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); - -CREATE TRIGGER update_moped_proj_funding_and_project_audit_fields - BEFORE INSERT - OR UPDATE ON moped_proj_funding - FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); - -CREATE TRIGGER update_moped_proj_milestones_and_project_audit_fields - BEFORE INSERT - OR UPDATE ON moped_proj_milestones - FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); - -CREATE TRIGGER update_moped_proj_notes_and_project_audit_fields - BEFORE INSERT - OR UPDATE ON moped_proj_notes - FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); - -CREATE TRIGGER update_moped_proj_phases_and_project_audit_fields - BEFORE INSERT - OR UPDATE ON moped_proj_phases - FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); - -CREATE TRIGGER update_moped_proj_work_activity_and_project_audit_fields - BEFORE INSERT - OR UPDATE ON moped_proj_work_activity - FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); +CREATE OR REPLACE FUNCTION public.update_self_and_project_updated_audit_fields() + RETURNS trigger + LANGUAGE plpgsql +AS $function$ +BEGIN + -- Update the updated_at field in the current row of the triggering table + NEW.updated_at := NOW(); + + -- Update the updated_at and updated_by_user_id fields in the related row of moped_project + UPDATE moped_project + SET updated_at = NEW.updated_at, + updated_by_user_id = NEW.updated_by_user_id + WHERE project_id = NEW.project_id; + + RETURN NEW; +END; +$function$; \ No newline at end of file diff --git a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql index 4f471d308c..c92deac09c 100644 --- a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql +++ b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/up.sql @@ -1,8 +1,3 @@ -alter table feature_drawn_lines alter column updated_at set default now(); -alter table feature_drawn_points alter column updated_at set default now(); -alter table feature_intersections alter column updated_at set default now(); -alter table feature_signals alter column updated_at set default now(); -alter table feature_street_segments alter column updated_at set default now(); alter table moped_proj_components alter column updated_at set default now(); alter table moped_proj_funding alter column created_at set default now(); alter table moped_proj_funding alter column updated_at set default now(); @@ -14,69 +9,22 @@ alter table moped_proj_phases alter column created_at set default now(); alter table moped_proj_phases alter column updated_at set default now(); alter table moped_proj_work_activity alter column updated_at set default now(); -DROP TRIGGER set_feature_drawn_lines_updated_at ON feature_drawn_lines; -DROP TRIGGER set_feature_drawn_points_updated_at ON feature_drawn_points; -DROP TRIGGER set_feature_intersections_updated_at ON feature_intersections; -DROP TRIGGER set_feature_signals_updated_at ON feature_signals; -DROP TRIGGER set_feature_street_segments_updated_at ON feature_street_segments; -DROP TRIGGER update_moped_proj_components_and_project_audit_fields ON moped_proj_components; -DROP TRIGGER update_moped_proj_funding_and_project_audit_fields ON moped_proj_funding; -DROP TRIGGER update_moped_proj_milestones_and_project_audit_fields ON moped_proj_milestones; -DROP TRIGGER update_moped_proj_notes_and_project_audit_fields ON moped_proj_notes; -DROP TRIGGER update_moped_proj_phases_and_project_audit_fields ON moped_proj_phases; -DROP TRIGGER update_moped_proj_work_activity_and_project_audit_fields ON moped_proj_work_activity; - -CREATE TRIGGER set_feature_drawn_lines_updated_at - BEFORE UPDATE ON feature_drawn_lines - FOR EACH ROW - EXECUTE FUNCTION public.set_updated_at(); - -CREATE TRIGGER set_feature_drawn_points_updated_at - BEFORE UPDATE ON feature_drawn_points - FOR EACH ROW - EXECUTE FUNCTION public.set_updated_at(); - -CREATE TRIGGER set_feature_intersections_updated_at - BEFORE UPDATE ON feature_intersections - FOR EACH ROW - EXECUTE FUNCTION public.set_updated_at(); - -CREATE TRIGGER set_feature_signals_updated_at - BEFORE UPDATE ON feature_signals - FOR EACH ROW - EXECUTE FUNCTION public.set_updated_at(); - -CREATE TRIGGER set_feature_street_segments_updated_at - BEFORE UPDATE ON feature_street_segments - FOR EACH ROW - EXECUTE FUNCTION public.set_updated_at(); - -CREATE TRIGGER update_moped_proj_components_and_project_audit_fields - BEFORE UPDATE ON moped_proj_components - FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); - -CREATE TRIGGER update_moped_proj_funding_and_project_audit_fields - BEFORE UPDATE ON moped_proj_funding - FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); - -CREATE TRIGGER update_moped_proj_milestones_and_project_audit_fields - BEFORE UPDATE ON moped_proj_milestones - FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); - -CREATE TRIGGER update_moped_proj_notes_and_project_audit_fields - BEFORE UPDATE ON moped_proj_notes - FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); - -CREATE TRIGGER update_moped_proj_phases_and_project_audit_fields - BEFORE UPDATE ON moped_proj_phases - FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); - -CREATE TRIGGER update_moped_proj_work_activity_and_project_audit_fields - BEFORE UPDATE ON moped_proj_work_activity - FOR EACH ROW - EXECUTE FUNCTION public.update_self_and_project_updated_audit_fields(); +CREATE OR REPLACE FUNCTION public.update_self_and_project_updated_audit_fields() + RETURNS trigger + LANGUAGE plpgsql +AS $function$ +BEGIN + -- Update the updated_at field in the current row of the triggering table only on update + IF (TG_OP = 'UPDATE') THEN + NEW.updated_at := NOW(); + END IF; + + -- Update the updated_at and updated_by_user_id fields in the related row of moped_project + UPDATE moped_project + SET updated_at = NEW.updated_at, + updated_by_user_id = NEW.updated_by_user_id + WHERE project_id = NEW.project_id; + + RETURN NEW; +END; +$function$; From a1f1c83bd9916635db79a0e56a6e7c13cca7b91e Mon Sep 17 00:00:00 2001 From: Tilly Whitson <35410637+tillyw@users.noreply.github.com> Date: Thu, 21 Mar 2024 18:08:25 -0500 Subject: [PATCH 13/15] add newline --- .../down.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql index 70630246c6..51c967e480 100644 --- a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql +++ b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql @@ -25,4 +25,4 @@ BEGIN RETURN NEW; END; -$function$; \ No newline at end of file +$function$; From 3ada0e00423b827038e6ce96e216d57ad932f993 Mon Sep 17 00:00:00 2001 From: Tilly Whitson <35410637+tillyw@users.noreply.github.com> Date: Fri, 22 Mar 2024 12:36:22 -0500 Subject: [PATCH 14/15] fix down migration --- .../down.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql index 51c967e480..dcfa162f0c 100644 --- a/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql +++ b/moped-database/migrations/1709335308607_alter_table_public_moped_proj_phases_alter_column_updated_at/down.sql @@ -2,7 +2,7 @@ alter table moped_proj_components alter column updated_at drop default; alter table moped_proj_funding alter column created_at set default clock_timestamp(); alter table moped_proj_funding alter column updated_at drop default; alter table moped_proj_milestones alter column created_at set default clock_timestamp(); -alter table moped_proj_milestones alter column updated_at set drop default; +alter table moped_proj_milestones alter column updated_at drop default; alter table moped_proj_notes alter column created_at set default clock_timestamp(); alter table moped_proj_notes alter column updated_at drop default; alter table moped_proj_phases alter column created_at set default clock_timestamp(); From ac53e452b0b1b7d5fbbd80c66d26a89457ec7ff4 Mon Sep 17 00:00:00 2001 From: chiaberry Date: Mon, 25 Mar 2024 11:22:23 -0500 Subject: [PATCH 15/15] find if component in params is related --- .../views/projects/projectView/ProjectComponents/index.js | 1 + .../ProjectComponents/utils/useComponentLinkParams.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/moped-editor/src/views/projects/projectView/ProjectComponents/index.js b/moped-editor/src/views/projects/projectView/ProjectComponents/index.js index 57e5f10f3a..9fb68f1b13 100644 --- a/moped-editor/src/views/projects/projectView/ProjectComponents/index.js +++ b/moped-editor/src/views/projects/projectView/ProjectComponents/index.js @@ -129,6 +129,7 @@ export default function MapView({ useComponentLinkParams({ setClickedComponent, + setIsClickedComponentRelated, projectComponents, allRelatedComponents, clickedComponent, diff --git a/moped-editor/src/views/projects/projectView/ProjectComponents/utils/useComponentLinkParams.js b/moped-editor/src/views/projects/projectView/ProjectComponents/utils/useComponentLinkParams.js index a9b45d23f7..d4326af23d 100644 --- a/moped-editor/src/views/projects/projectView/ProjectComponents/utils/useComponentLinkParams.js +++ b/moped-editor/src/views/projects/projectView/ProjectComponents/utils/useComponentLinkParams.js @@ -38,6 +38,7 @@ const updateParamsWithoutRender = (queryKey, queryValue) => { */ export const useComponentLinkParams = ({ setClickedComponent, + setIsClickedComponentRelated, projectComponents, allRelatedComponents, errorMessageDispatch, @@ -75,6 +76,12 @@ export const useComponentLinkParams = ({ // Set clickedComponent found from params setClickedComponent(componentFromParams); + const isComponentRelated = allRelatedComponents.find( + (component) => component.project_component_id === componentParamId + ); + // if component is related, the highlight color is green + setIsClickedComponentRelated(isComponentRelated); + // Zoom to its extent const features = getAllComponentFeatures(componentFromParams); const featureCollection = { type: "FeatureCollection", features }; @@ -109,6 +116,7 @@ export const useComponentLinkParams = ({ hasComponentSetFromUrl, projectComponents, setClickedComponent, + setIsClickedComponentRelated, allRelatedComponents, setHasComponentSetFromUrl, errorMessageDispatch,