Skip to content

Commit

Permalink
Merge pull request #1311 from cityofaustin/16650-secondary-name-activity
Browse files Browse the repository at this point in the history
Add secondary name to activity log
  • Loading branch information
chiaberry authored Apr 12, 2024
2 parents 208e063 + 6bb446b commit e65fe46
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions moped-database/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4235,6 +4235,7 @@
- project_website
- knack_project_id
- public_process_status_id
- project_name_secondary
retry_conf:
interval_sec: 10
num_retries: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import BeenhereOutlinedIcon from "@mui/icons-material/BeenhereOutlined";
import { ProjectActivityLogTableMaps } from "../../views/projects/projectView/ProjectActivityLogTableMaps";
import { isEqual } from "lodash";

export const formatProjectActivity = (change, lookupList) => {
const entryMap = ProjectActivityLogTableMaps["moped_project"];
Expand All @@ -19,6 +20,34 @@ export const formatProjectActivity = (change, lookupList) => {
};
}

const newRecord = changeData.new;
const oldRecord = changeData.old;
let changes = [];
const fieldsToSkip = [
"updated_at",
"updated_by_user_id",
"project_name_full",
];

// loop through fields to check for differences, push label onto changes Array
Object.keys(newRecord).forEach((field) => {
// typeof(null) === "object", check that field is not null before checking if object
if (!!newRecord[field] && typeof newRecord[field] === "object") {
if (!isEqual(newRecord[field], oldRecord[field])) {
changes.push(entryMap.fields[field]?.label);
}
} else if (
newRecord[field] !== oldRecord[field] &&
!fieldsToSkip.includes(field)
) {
changes.push(entryMap.fields[field]?.label);
}
});

// the only way to have more than one change in an update on the project table,
// is if the primary and secondary names have both been updated
const updatedFullName = changes.length > 1;

// the field that was changed in the activity
const changedField = change.description[0].field;

Expand Down Expand Up @@ -53,7 +82,7 @@ export const formatProjectActivity = (change, lookupList) => {
};
}

// if the new field is null or undefined, its because something was removed
// if the new field value is null or undefined, its because something was removed
if (!lookupList[changeData.new[changedField]]) {
return {
changeIcon,
Expand All @@ -65,7 +94,6 @@ export const formatProjectActivity = (change, lookupList) => {
],
};
}

// Changing a field, but need to use lookup table to display
return {
changeIcon,
Expand Down Expand Up @@ -112,6 +140,41 @@ export const formatProjectActivity = (change, lookupList) => {
};
}

// if both the project name and secondary name fields were updated
if (updatedFullName) {
return {
changeIcon,
changeText: [
{
text: "Changed full project name to ",
style: null,
},
{
text: changeData.new["project_name_full"],
style: "boldText",
},
],
};
}

// if only the name field was updated, the project name full field is still changed
// but this was due to the name being updated
if (changedField === "project_name_full") {
return {
changeIcon,
changeText: [
{
text: "Changed project name to ",
style: null,
},
{
text: changeData.new["project_name"],
style: "boldText",
},
],
};
}

// the update can be rendered as a string
const changeValue =
// check truthiness to prevent rendering String(null) as "null"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export const ProjectActivityLogTableMaps = {
is_retired: {
label: "is retired",
},
project_name_secondary: {
label: "secondary project name"
},
project_name_full: {
label: "full project name"
}
},
},
moped_proj_entities: {
Expand Down

0 comments on commit e65fe46

Please sign in to comment.