Skip to content

Commit

Permalink
Merge branch 'main' into 16368-mui-x-pro
Browse files Browse the repository at this point in the history
  • Loading branch information
chiaberry committed Mar 25, 2024
2 parents 291e63f + 4ce9b7c commit 9be244e
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 20 deletions.
16 changes: 8 additions & 8 deletions moped-database/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2650,7 +2650,7 @@
- milestone_order
- project_id
- is_deleted
comment: No insert permissions on audit fields
comment: No insert permissions on audit fields
- role: moped-editor
permission:
check: {}
Expand All @@ -2666,7 +2666,7 @@
- milestone_order
- project_id
- is_deleted
comment: No insert permissions on audit fields
comment: No insert permissions on audit fields
select_permissions:
- role: moped-admin
permission:
Expand Down Expand Up @@ -2735,7 +2735,7 @@
check: {}
set:
updated_by_user_id: x-hasura-user-db-id
comment: No update permissions on audit fields
comment: No update permissions on audit fields
- role: moped-editor
permission:
columns:
Expand All @@ -2751,7 +2751,7 @@
check: {}
set:
updated_by_user_id: x-hasura-user-db-id
comment: No update permissions on audit fields
comment: No update permissions on audit fields
event_triggers:
- name: activity_log_moped_proj_milestones
definition:
Expand Down Expand Up @@ -2824,7 +2824,7 @@
- project_id
- project_note
- project_note_type
comment: No insert permissions on audit fields
comment: No insert permissions on audit fields
- role: moped-editor
permission:
check: {}
Expand All @@ -2837,7 +2837,7 @@
- project_id
- project_note
- project_note_type
comment: No insert permissions on audit fields
comment: No insert permissions on audit fields
select_permissions:
- role: moped-admin
permission:
Expand Down Expand Up @@ -2897,7 +2897,7 @@
check: null
set:
updated_by_user_id: x-hasura-user-db-id
comment: No update permissions on audit fields
comment: No update permissions on audit fields
- role: moped-editor
permission:
columns:
Expand All @@ -2910,7 +2910,7 @@
check: null
set:
updated_by_user_id: x-hasura-user-db-id
comment: No update permissions on audit fields
comment: No update permissions on audit fields
event_triggers:
- name: activity_log_moped_proj_notes
definition:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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 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 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$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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();

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$;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const RelatedComponentsList = ({
editState,
shouldShowRelatedProjects,
clickedComponent,
setClickedComponent,
makeClickedComponentUpdates,
onClickZoomToComponent,
allRelatedComponents,
setIsClickedComponentRelated,
Expand All @@ -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);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ export default function MapView({

useComponentLinkParams({
setClickedComponent,
setIsClickedComponentRelated,
projectComponents,
allRelatedComponents,
clickedComponent,
errorMessageDispatch,
mapRef,
Expand Down Expand Up @@ -177,14 +179,18 @@ export default function MapView({
if (clickedComponent === null) return;

const clickedComponentId = clickedComponent?.project_component_id;
const updatedClickedComponent = projectComponents.find(
(component) => component.project_component_id === clickedComponentId
);
const updatedClickedComponent =
projectComponents.find(
(component) => component.project_component_id === clickedComponentId
) ||
allRelatedComponents.find(
(component) => component.project_component_id === clickedComponentId
);

setClickedComponent(updatedClickedComponent);
}, [clickedComponent, projectComponents]);
}, [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 });
Expand Down Expand Up @@ -287,7 +293,7 @@ export default function MapView({
editState={editState}
shouldShowRelatedProjects={shouldShowRelatedProjects}
clickedComponent={clickedComponent}
setClickedComponent={setClickedComponent}
makeClickedComponentUpdates={makeClickedComponentUpdates}
onClickZoomToComponent={onClickZoomToComponent}
allRelatedComponents={allRelatedComponents}
setIsClickedComponentRelated={setIsClickedComponentRelated}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ const updateParamsWithoutRender = (queryKey, queryValue) => {
*/
export const useComponentLinkParams = ({
setClickedComponent,
setIsClickedComponentRelated,
projectComponents,
allRelatedComponents,
errorMessageDispatch,
mapRef,
}) => {
Expand All @@ -62,14 +64,24 @@ 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
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 };
Expand Down Expand Up @@ -104,6 +116,8 @@ export const useComponentLinkParams = ({
hasComponentSetFromUrl,
projectComponents,
setClickedComponent,
setIsClickedComponentRelated,
allRelatedComponents,
setHasComponentSetFromUrl,
errorMessageDispatch,
mapRef,
Expand Down

0 comments on commit 9be244e

Please sign in to comment.