Skip to content

Commit

Permalink
Merge pull request #1128 from cityofaustin/jc-comp-activity-v2
Browse files Browse the repository at this point in the history
Adds activity log event for moving component to another project
  • Loading branch information
johnclary authored Sep 14, 2023
2 parents 4d075b0 + 91e46c1 commit 1ba7917
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
46 changes: 46 additions & 0 deletions moped-database/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,52 @@
paused: true
schedule: 0 0 * * *
timeout: 60
- name: activity_log_moped_proj_components_update
definition:
enable_manual: false
update:
columns:
- 'project_id'
retry_conf:
interval_sec: 10
num_retries: 0
timeout_sec: 60
webhook_from_env: HASURA_ENDPOINT
headers:
- name: x-hasura-admin-secret
value_from_env: ACTIVITY_LOG_API_SECRET
request_transform:
body:
action: transform
template: |-
{
"query": "mutation InsertActivity($object: moped_activity_log_insert_input!, $project_id:Int!, $updated_at:timestamptz ) { insert_moped_activity_log_one(object: $object) { activity_id } update_moped_project_by_pk(pk_columns: {project_id: $project_id}, _set: {updated_at: $updated_at}) { updated_at }}",
"variables": {
"object": {
"record_id": {{ $body.event.data.new.project_component_id }},
"record_type": {{ $body.table.name }},
"activity_id": {{ $body.id }},
"record_project_id": {{ $body.event.data.old.project_id }},
"record_data": {"event": {{ $body.event }}},
"description": [{"newSchema": "true"}],
"operation_type": {{ $body.event.op }},
"updated_by_user_id": {{ $session_variables?['x-hasura-user-db-id'] ?? 1}}
},
"updated_at": {{$body.created_at}},
"project_id": {{$body.event.data.old.project_id}}
}
}
method: POST
query_params: {}
template_engine: Kriti
version: 2
cleanup_config:
batch_size: 10000
clean_invocation_logs: false
clear_older_than: 168
paused: true
schedule: 0 0 * * *
timeout: 60
- table:
name: moped_proj_components_subcomponents
schema: public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export const formatComponentsActivity = (
change,
componentList,
phaseList,
subphaseList
subphaseList,
projectId
) => {
const entryMap = ProjectActivityLogTableMaps["moped_proj_components"];

Expand Down Expand Up @@ -47,6 +48,35 @@ export const formatComponentsActivity = (
};
}

if (change.description[0].field === "project_id") {
if (change.record_data.event.data.old.project_id === parseInt(projectId)) {
// a component was moved from this project to another project
return {
changeIcon,
changeText: [
{ text: "Moved component ", style: null },
componentText,
{
text: ` to project #${change.record_data.event.data.new.project_id}`,
style: null,
},
],
};
} else {
// a component was moved here from another project
return {
changeIcon,
changeText: [
{ text: "Added component ", style: null },
componentText,
{
text: ` from project #${change.record_data.event.data.old.project_id}`,
style: null,
},
],
};
}
}
// add a new component phase
if (phase && !previousPhase) {
return {
Expand Down
5 changes: 3 additions & 2 deletions moped-editor/src/utils/activityLogHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { formatFilesActivity } from "./activityLogFormatters/mopedFilesActivity"
import { formatContractsActivity } from "./activityLogFormatters/mopedContractsActivity";
import { formatMigratedProjectActivity } from "./activityLogFormatters/mopedProjectMigrationActivity";

export const formatActivityLogEntry = (change, lookupData) => {
export const formatActivityLogEntry = (change, lookupData, projectId) => {
const changeText = [{ text: "Project was updated", style: null }];
const changeIcon = (
<span className="material-symbols-outlined">summarize</span>
Expand Down Expand Up @@ -59,7 +59,8 @@ export const formatActivityLogEntry = (change, lookupData) => {
change,
lookupData.componentList,
lookupData.phaseList,
lookupData.subphaseList
lookupData.subphaseList,
projectId
);
case "moped_project_types":
return formatProjectTypesActivity(change, lookupData.projectTypeList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ const ProjectActivityLog = () => {
{activityLogData.map((change) => {
const { changeIcon, changeText } = formatActivityLogEntry(
change,
lookupData
lookupData,
projectId
);
return (
<TableRow key={change.activity_id}>
Expand Down

0 comments on commit 1ba7917

Please sign in to comment.