From 45d07630204f4e93abe334bb7c855f0a634f1e55 Mon Sep 17 00:00:00 2001 From: Chia Berry Date: Fri, 19 Nov 2021 16:29:55 -0600 Subject: [PATCH 01/10] add component for summary project types --- moped-editor/src/queries/project.js | 27 +++ .../ProjectSummary/ProjectSummary.js | 9 +- .../ProjectSummaryProjectTypes.js | 202 ++++++++++++++++++ 3 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js diff --git a/moped-editor/src/queries/project.js b/moped-editor/src/queries/project.js index 825aed4f26..eac257eca5 100644 --- a/moped-editor/src/queries/project.js +++ b/moped-editor/src/queries/project.js @@ -51,6 +51,12 @@ export const SUMMARY_QUERY = gql` project_note_id project_note } + moped_project_types { + moped_type { + type_name + type_id + } + } } moped_proj_partners( where: { project_id: { _eq: $projectId }, status_id: { _eq: 1 } } @@ -84,6 +90,10 @@ export const SUMMARY_QUERY = gql` entity_id entity_name } + moped_types { + type_id + type_name + } moped_status( where: { status_id: { _gt: 0 } } order_by: { status_order: asc } @@ -803,6 +813,23 @@ export const PROJECT_UPDATE_CURRENT_STATUS = gql` } `; +export const PROJECT_UPDATE_TYPES = gql` + mutation UpdateMopedProjectTypes( + $types: [moped_proj_partners_insert_input!]! + $deleteList: [Int!]! + ) { + insert_moped_project_types(objects: $types) { + affected_rows + } + update_moped_project_types( + where: { project_type_id: { _in: $deleteList } } + _set: { status_id: 0 } + ) { + affected_rows + } + } +`; + export const PROJECT_UPDATE_ECAPRIS_SUBPROJECT_ID = gql` mutation UpdateProjectECapris( $projectId: Int! diff --git a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js index d916ded4fd..c1d826c721 100644 --- a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js +++ b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js @@ -23,6 +23,7 @@ import ProjectSummaryProjectWebsite from "./ProjectSummaryProjectWebsite"; import ProjectSummaryProjectDescription from "./ProjectSummaryProjectDescription"; import ProjectSummaryCurrentStatus from "./ProjectSummaryCurrentStatus"; import ProjectSummaryProjectECapris from "./ProjectSummaryProjectECapris"; +import ProjectSummaryProjectTypes from "./ProjectSummaryProjectTypes"; const useStyles = makeStyles(theme => ({ fieldGridItem: { @@ -185,7 +186,13 @@ const ProjectSummary = ({ loading, error, data, refetch }) => { /> - {null} + diff --git a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js new file mode 100644 index 0000000000..ec7824d931 --- /dev/null +++ b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js @@ -0,0 +1,202 @@ +import React, { useState } from "react"; +import { + Box, + Checkbox, + Grid, + Icon, + Input, + ListItemText, + MenuItem, + Select, + Typography, +} from "@material-ui/core"; + +import ProjectSummaryLabel from "./ProjectSummaryLabel"; +import { useMutation } from "@apollo/client"; +import { PROJECT_UPDATE_TYPES } from "../../../../queries/project"; + +/** + * ProjectSummaryProjectTypes Component + * @param {Number} projectId - The id of the current project being viewed + * @param {Object} data - The data object from the GraphQL query + * @param {function} refetch - The refetch function from apollo + * @param {Object} classes - The shared style settings + * @param {function} snackbarHandle - The function to show the snackbar + * @returns {JSX.Element} + * @constructor + */ +const ProjectSummaryProjectTypes = ({ + projectId, + data, + refetch, + classes, + snackbarHandle, +}) => { + /** + * Helper initial state lists + */ + const typeList = data?.moped_types ?? []; + const typeDict = typeList.reduce( + (prev, curr) => ({ + ...prev, + ...{ [curr.type_id]: curr.type_name }, + }), + {} + ); + + // Original Types: array of moped_type objects + const originalTypes = data?.moped_project[0]?.moped_project_types ?? []; + // Original Types Ids: array of ids (ints) + const originalTypesIds = originalTypesA.map(t => t?.moped_type?.type_id); + console.log(originalTypesA, originalTypesIds) + /** + * Edit Mode and selected Types states + */ + const [editMode, setEditMode] = useState(false); + const [selectedTypes, setSelectedTypes] = useState(originalTypes); + + // The mutation and mutation function + const [updateProjectTypes] = useMutation(PROJECT_UPDATE_TYPES); + + /** + * Handles whenever there is a click in any of the menu items + * @param {Object} event - The event object + */ + const handleChange = event => { + setSelectedTypes(event.target.value); + }; + + /** + * Resets the partners list back to the original state, closes edit mode + */ + const handleProjectTypesClose = () => { + setSelectedTypes(originalTypes); + setEditMode(false); + }; + + /** + * Saves the new project partner + */ + const handleProjectTypesSave = () => { + // Retrieve types list (original list) + const oldTypesList = originalTypes; + // The new types list is just the selected entities ids + const newTypesList = selectedTypes; + // Retrieves the ids of oldTypesList that are not present in newTypesList + const typeIdsToDelete = oldTypesList.filter( + p => !newTypesList.includes(p) + ); + // Retrieves the ids of newTypesList that are not present in oldTypesList + const typeIdsToInsert = newTypesList.filter( + p => !oldTypesList.includes(p) + ); + // We need a final list of objects to insert + const typeObjectsToInsert = typeIdsToInsert.map(id => ({ + project_id: projectId, + type_id: id, + status_id: 1, + })); + // We need a final list of primary keys to delete + const typePksToDelete = originalTypes + .filter(t => typeIdsToDelete.includes(t.type_id)) + .map(t => t.proj_partner_id); + + updateProjectTypes({ + variables: { + types: typeObjectsToInsert, + deleteList: typePksToDelete, + }, + }) + .then(() => { + refetch(); + setEditMode(false); + snackbarHandle(true, "Update successful", "success"); + }) + .catch(err => { + snackbarHandle( + true, + "Failed to update types: " + String(err), + "error" + ); + handleProjectTypesClose(); + }); + setEditMode(false); + }; + + const selectedTypesJoint = selectedTypes + .map(t => typeDict[t]) + .join(", "); + + return ( + + Project types + + {editMode && ( + <> + + + check + + + close + + + )} + {!editMode && ( + setEditMode(true)} + /> + )} + + + ); +}; + +export default ProjectSummaryProjectTypes; From c3a5ff0f27449d68f2b381427c409388d5bb66d4 Mon Sep 17 00:00:00 2001 From: Chia Berry Date: Mon, 22 Nov 2021 12:44:26 -0600 Subject: [PATCH 02/10] switch to ids --- .../ProjectSummaryProjectTypes.js | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js index ec7824d931..0d349c54e4 100644 --- a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js +++ b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js @@ -47,13 +47,13 @@ const ProjectSummaryProjectTypes = ({ // Original Types: array of moped_type objects const originalTypes = data?.moped_project[0]?.moped_project_types ?? []; // Original Types Ids: array of ids (ints) - const originalTypesIds = originalTypesA.map(t => t?.moped_type?.type_id); - console.log(originalTypesA, originalTypesIds) + const originalTypesIds = originalTypes.map(t => t?.moped_type?.type_id); + console.log(originalTypes, originalTypesIds) /** * Edit Mode and selected Types states */ const [editMode, setEditMode] = useState(false); - const [selectedTypes, setSelectedTypes] = useState(originalTypes); + const [selectedTypes, setSelectedTypes] = useState(originalTypesIds); // The mutation and mutation function const [updateProjectTypes] = useMutation(PROJECT_UPDATE_TYPES); @@ -67,28 +67,28 @@ const ProjectSummaryProjectTypes = ({ }; /** - * Resets the partners list back to the original state, closes edit mode + * Resets the types list back to the original state, closes edit mode */ const handleProjectTypesClose = () => { - setSelectedTypes(originalTypes); + setSelectedTypes(originalTypesIds); setEditMode(false); }; /** - * Saves the new project partner + * Saves the new project types */ const handleProjectTypesSave = () => { // Retrieve types list (original list) - const oldTypesList = originalTypes; - // The new types list is just the selected entities ids + const oldTypesList = originalTypesIds + // Get selected types ids const newTypesList = selectedTypes; // Retrieves the ids of oldTypesList that are not present in newTypesList const typeIdsToDelete = oldTypesList.filter( - p => !newTypesList.includes(p) + t => !newTypesList.includes(t) ); // Retrieves the ids of newTypesList that are not present in oldTypesList const typeIdsToInsert = newTypesList.filter( - p => !oldTypesList.includes(p) + t => !oldTypesList.includes(t) ); // We need a final list of objects to insert const typeObjectsToInsert = typeIdsToInsert.map(id => ({ @@ -99,7 +99,8 @@ const ProjectSummaryProjectTypes = ({ // We need a final list of primary keys to delete const typePksToDelete = originalTypes .filter(t => typeIdsToDelete.includes(t.type_id)) - .map(t => t.proj_partner_id); + + console.log(typePksToDelete); updateProjectTypes({ variables: { @@ -160,14 +161,16 @@ const ProjectSummaryProjectTypes = ({ }} className={classes.fieldSelectItem} > - {typeList.map(type => ( + {typeList.map(type => { + console.log("TYPE ", type) + return ( - ))} + )})} Date: Mon, 22 Nov 2021 15:29:02 -0600 Subject: [PATCH 03/10] add status id and id columns to moped project types --- moped-database/metadata/tables.yaml | 47 ++++++++++++------- .../down.sql | 1 + .../up.sql | 1 + .../down.sql | 4 ++ .../up.sql | 4 ++ .../down.sql | 1 + .../up.sql | 1 + 7 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 moped-database/migrations/1637616024807_alter_table_public_moped_project_types_add_column_id/down.sql create mode 100644 moped-database/migrations/1637616024807_alter_table_public_moped_project_types_add_column_id/up.sql create mode 100644 moped-database/migrations/1637616037336_modify_primarykey_public_moped_project_types/down.sql create mode 100644 moped-database/migrations/1637616037336_modify_primarykey_public_moped_project_types/up.sql create mode 100644 moped-database/migrations/1637616169562_alter_table_public_moped_project_types_add_column_status_id/down.sql create mode 100644 moped-database/migrations/1637616169562_alter_table_public_moped_project_types_add_column_status_id/up.sql diff --git a/moped-database/metadata/tables.yaml b/moped-database/metadata/tables.yaml index 252e9a5242..297977f7c2 100644 --- a/moped-database/metadata/tables.yaml +++ b/moped-database/metadata/tables.yaml @@ -4109,64 +4109,77 @@ permission: check: {} columns: + - added_by + - date_added + - id - project_id - project_type_id - - date_added - - added_by + - status_id backend_only: false - role: moped-editor permission: check: {} columns: + - added_by + - date_added + - id - project_id - project_type_id - - date_added - - added_by - backend_only: false + - status_id select_permissions: - role: moped-admin permission: columns: + - added_by + - date_added + - id - project_id - project_type_id - - date_added - - added_by + - status_id filter: {} - role: moped-editor permission: columns: + - added_by + - date_added + - id - project_id - project_type_id - - date_added - - added_by + - status_id filter: {} - role: moped-viewer permission: columns: + - added_by + - date_added + - id - project_id - project_type_id - - date_added - - added_by + - status_id filter: {} update_permissions: - role: moped-admin permission: columns: + - added_by + - date_added + - id - project_id - project_type_id - - date_added - - added_by + - status_id filter: {} - check: {} + check: null - role: moped-editor permission: columns: + - added_by + - date_added + - id - project_id - project_type_id - - date_added - - added_by + - status_id filter: {} - check: {} + check: null event_triggers: - name: activity_log_moped_project_types definition: diff --git a/moped-database/migrations/1637616024807_alter_table_public_moped_project_types_add_column_id/down.sql b/moped-database/migrations/1637616024807_alter_table_public_moped_project_types_add_column_id/down.sql new file mode 100644 index 0000000000..f2c5ea960f --- /dev/null +++ b/moped-database/migrations/1637616024807_alter_table_public_moped_project_types_add_column_id/down.sql @@ -0,0 +1 @@ +ALTER TABLE "public"."moped_project_types" DROP COLUMN "id"; diff --git a/moped-database/migrations/1637616024807_alter_table_public_moped_project_types_add_column_id/up.sql b/moped-database/migrations/1637616024807_alter_table_public_moped_project_types_add_column_id/up.sql new file mode 100644 index 0000000000..c78267bac3 --- /dev/null +++ b/moped-database/migrations/1637616024807_alter_table_public_moped_project_types_add_column_id/up.sql @@ -0,0 +1 @@ +ALTER TABLE "public"."moped_project_types" ADD COLUMN "id" serial NOT NULL UNIQUE; diff --git a/moped-database/migrations/1637616037336_modify_primarykey_public_moped_project_types/down.sql b/moped-database/migrations/1637616037336_modify_primarykey_public_moped_project_types/down.sql new file mode 100644 index 0000000000..c9b64dcfcd --- /dev/null +++ b/moped-database/migrations/1637616037336_modify_primarykey_public_moped_project_types/down.sql @@ -0,0 +1,4 @@ +alter table "public"."moped_project_types" drop constraint "moped_project_types_pkey"; +alter table "public"."moped_project_types" + add constraint "moped_project_types_pkey" + primary key ( "project_type_id" ); diff --git a/moped-database/migrations/1637616037336_modify_primarykey_public_moped_project_types/up.sql b/moped-database/migrations/1637616037336_modify_primarykey_public_moped_project_types/up.sql new file mode 100644 index 0000000000..84ea0fc8e2 --- /dev/null +++ b/moped-database/migrations/1637616037336_modify_primarykey_public_moped_project_types/up.sql @@ -0,0 +1,4 @@ +alter table "public"."moped_project_types" drop constraint "moped_project_types_pkey"; +alter table "public"."moped_project_types" + add constraint "moped_project_types_pkey" + primary key ( "id" ); diff --git a/moped-database/migrations/1637616169562_alter_table_public_moped_project_types_add_column_status_id/down.sql b/moped-database/migrations/1637616169562_alter_table_public_moped_project_types_add_column_status_id/down.sql new file mode 100644 index 0000000000..49c7c44d27 --- /dev/null +++ b/moped-database/migrations/1637616169562_alter_table_public_moped_project_types_add_column_status_id/down.sql @@ -0,0 +1 @@ +ALTER TABLE "public"."moped_project_types" DROP COLUMN "status_id"; diff --git a/moped-database/migrations/1637616169562_alter_table_public_moped_project_types_add_column_status_id/up.sql b/moped-database/migrations/1637616169562_alter_table_public_moped_project_types_add_column_status_id/up.sql new file mode 100644 index 0000000000..3282514726 --- /dev/null +++ b/moped-database/migrations/1637616169562_alter_table_public_moped_project_types_add_column_status_id/up.sql @@ -0,0 +1 @@ +ALTER TABLE "public"."moped_project_types" ADD COLUMN "status_id" integer NOT NULL DEFAULT 0; From 1cccea0c5952a7c08527ee5a57bdbe020eeb5c77 Mon Sep 17 00:00:00 2001 From: Chia Berry Date: Mon, 29 Nov 2021 09:20:35 -0600 Subject: [PATCH 04/10] update status id when deleting or adding --- moped-editor/src/queries/project.js | 8 ++- .../ProjectSummaryProjectTypes.js | 59 +++++++------------ 2 files changed, 27 insertions(+), 40 deletions(-) diff --git a/moped-editor/src/queries/project.js b/moped-editor/src/queries/project.js index eac257eca5..799c79eec8 100644 --- a/moped-editor/src/queries/project.js +++ b/moped-editor/src/queries/project.js @@ -51,7 +51,9 @@ export const SUMMARY_QUERY = gql` project_note_id project_note } - moped_project_types { + moped_project_types(where: { status_id: { _eq: 1 } }) { + id + status_id moped_type { type_name type_id @@ -815,14 +817,14 @@ export const PROJECT_UPDATE_CURRENT_STATUS = gql` export const PROJECT_UPDATE_TYPES = gql` mutation UpdateMopedProjectTypes( - $types: [moped_proj_partners_insert_input!]! + $types: [moped_project_types_insert_input!]! $deleteList: [Int!]! ) { insert_moped_project_types(objects: $types) { affected_rows } update_moped_project_types( - where: { project_type_id: { _in: $deleteList } } + where: { id: { _in: $deleteList } } _set: { status_id: 0 } ) { affected_rows diff --git a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js index 0d349c54e4..176d93b205 100644 --- a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js +++ b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js @@ -48,7 +48,7 @@ const ProjectSummaryProjectTypes = ({ const originalTypes = data?.moped_project[0]?.moped_project_types ?? []; // Original Types Ids: array of ids (ints) const originalTypesIds = originalTypes.map(t => t?.moped_type?.type_id); - console.log(originalTypes, originalTypesIds) + /** * Edit Mode and selected Types states */ @@ -78,29 +78,25 @@ const ProjectSummaryProjectTypes = ({ * Saves the new project types */ const handleProjectTypesSave = () => { - // Retrieve types list (original list) - const oldTypesList = originalTypesIds + // Original type Ids + const oldTypesList = originalTypesIds; // Get selected types ids const newTypesList = selectedTypes; // Retrieves the ids of oldTypesList that are not present in newTypesList - const typeIdsToDelete = oldTypesList.filter( - t => !newTypesList.includes(t) - ); + const typeIdsToDelete = oldTypesList.filter(t => !newTypesList.includes(t)); // Retrieves the ids of newTypesList that are not present in oldTypesList - const typeIdsToInsert = newTypesList.filter( - t => !oldTypesList.includes(t) - ); - // We need a final list of objects to insert - const typeObjectsToInsert = typeIdsToInsert.map(id => ({ + const typeIdsToInsert = newTypesList.filter(t => !oldTypesList.includes(t)); + // List of objects to insert + const typeObjectsToInsert = typeIdsToInsert.map(type_id => ({ project_id: projectId, - type_id: id, + project_type_id: type_id, status_id: 1, })); - // We need a final list of primary keys to delete - const typePksToDelete = originalTypes - .filter(t => typeIdsToDelete.includes(t.type_id)) - console.log(typePksToDelete); + // List of primary keys to delete + const typePksToDelete = originalTypes + .filter(t => typeIdsToDelete.includes(t?.moped_type.type_id)) + .map(t => t.id); updateProjectTypes({ variables: { @@ -114,19 +110,15 @@ const ProjectSummaryProjectTypes = ({ snackbarHandle(true, "Update successful", "success"); }) .catch(err => { - snackbarHandle( - true, - "Failed to update types: " + String(err), - "error" - ); + snackbarHandle(true, "Failed to update types: " + String(err), "error"); handleProjectTypesClose(); }); setEditMode(false); }; - const selectedTypesJoint = selectedTypes - .map(t => typeDict[t]) - .join(", "); + // join selected type names in a comma separated string + // used to display when not editing + const selectedTypesJoint = selectedTypes.map(t => typeDict[t]).join(", "); return ( @@ -136,7 +128,7 @@ const ProjectSummaryProjectTypes = ({ justifyContent="flex-start" className={classes.fieldBox} > - {editMode && ( + {editMode ? ( <> - )} - {!editMode && ( + ) : ( setEditMode(true)} From a56f47f7c2fa22745a726abca64fe0e747f964e9 Mon Sep 17 00:00:00 2001 From: Chia Berry Date: Tue, 30 Nov 2021 09:14:40 -0600 Subject: [PATCH 05/10] include project types dropdown in table --- moped-editor/src/queries/signals.js | 9 ++- .../signalProjectTable/SignalProjectTable.js | 79 ++++++++++++++++++- 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/moped-editor/src/queries/signals.js b/moped-editor/src/queries/signals.js index fe06210896..388eff5530 100644 --- a/moped-editor/src/queries/signals.js +++ b/moped-editor/src/queries/signals.js @@ -31,9 +31,12 @@ export const SIGNAL_PROJECTS_QUERY = gql` funding_source_name } } - moped_project_types { + moped_project_types(where: { status_id: { _eq: 1 } }) { + id + status_id moped_type { type_name + type_id } } moped_proj_personnel(where: {status_id: {_eq: 1}}) { @@ -48,6 +51,10 @@ export const SIGNAL_PROJECTS_QUERY = gql` entity_id entity_name } + moped_types { + type_id + type_name + } } `; diff --git a/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js b/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js index d56c64c397..05d44fbede 100644 --- a/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js +++ b/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js @@ -1,9 +1,14 @@ -import React from "react"; +import React, {useState} from "react"; import { useQuery, useMutation } from "@apollo/client"; import { CardContent, + Checkbox, CircularProgress, Grid, + Input, + ListItemText, + MenuItem, + Select, TextField, Typography, makeStyles, @@ -44,8 +49,11 @@ const SignalProjectTable = () => { fontSize: "14px", }; + const [selectedTypes, setSelectedTypes] = useState([]); + const [updateSignalProject] = useMutation(UPDATE_SIGNAL_PROJECT); const [updateProjectSponsor] = useMutation(PROJECT_UPDATE_SPONSOR); + if (error) { console.log(error); @@ -54,7 +62,16 @@ const SignalProjectTable = () => { return ; } + // lists needed for dropdown options const entityList = data?.moped_entity ?? []; + const typeList = data?.moped_types ?? []; + const typeDict = typeList.reduce( + (prev, curr) => ({ + ...prev, + ...{ [curr.type_id]: curr.type_name }, + }), + {} + ); /** * Build data needed in Signals Material Table @@ -163,6 +180,8 @@ const SignalProjectTable = () => { project["project_inspector"] = inspectors.join(", "); }); + console.log(data.moped_project) + /** * Column configuration for */ @@ -188,9 +207,20 @@ const SignalProjectTable = () => { }, { title: "Project types", - field: "project_types", - editable: "never", - render: entry => entry.project_types.join(", "), + field: "moped_project_types", + customEdit: "projectTypes", + render: entry => { + const project_types = []; + if (entry?.moped_project_types?.length) { + entry.moped_project_types.forEach(projType => { + project_types.push(projType?.moped_type?.type_name); + }) + return {project_types.join(", ")} + }; + return None + } + + }, { title: "Current phase", @@ -326,6 +356,10 @@ const SignalProjectTable = () => { }, ]; + + /** + * projectActions functions object + */ const projectActions = { update: (newData, oldData) => { // initialize update object with old data @@ -384,6 +418,9 @@ const SignalProjectTable = () => { }, }; + /** + * Custom edit components + */ const cellEditComponents = { projectSponsor: props => ( { )} /> ), + projectTypes: props => { + const originalTypesIds = props.value.map(t => t?.moped_type?.type_id); + console.log(props, props.value, selectedTypes) + return ( + } + renderValue={type_ids => + type_ids.map(t => typeDict[t]).join(", ") + } + /* + There appears to be a problem with MenuProps in version 4.x (which is fixed in 5.0), + this is fixed by overriding the function "getContentAnchorEl". + Source: https://github.com/mui-org/material-ui/issues/19245#issuecomment-620488016 + */ + MenuProps={{ + getContentAnchorEl: () => null, + style: { + maxHeight: 500, + width: 450, + }, + }} + > + {typeList.map(type => ( + + + + + ))} + + )} }; return ( From 01dea52669758b54624e50e5accd414f41f30ce3 Mon Sep 17 00:00:00 2001 From: Chia Berry Date: Tue, 30 Nov 2021 15:18:50 -0600 Subject: [PATCH 06/10] cell edit works for signal dashboard proj types --- moped-editor/src/queries/signals.js | 11 +++ .../signalProjectTable/SignalProjectTable.js | 74 +++++++++++-------- 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/moped-editor/src/queries/signals.js b/moped-editor/src/queries/signals.js index 388eff5530..b998af7bb9 100644 --- a/moped-editor/src/queries/signals.js +++ b/moped-editor/src/queries/signals.js @@ -64,6 +64,8 @@ export const UPDATE_SIGNAL_PROJECT = gql` $contractor: String $purchase_order_number: String $entity_id: Int + $projectTypes: [moped_project_types_insert_input!] + $typesDeleteList: [Int!] ) { update_moped_project_by_pk( pk_columns: { project_id: $project_id } @@ -75,5 +77,14 @@ export const UPDATE_SIGNAL_PROJECT = gql` ) { project_id } + insert_moped_project_types(objects: $projectTypes) { + affected_rows + } + update_moped_project_types( + where: { id: { _in: $typesDeleteList } } + _set: { status_id: 0 } + ) { + affected_rows + } } `; diff --git a/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js b/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js index 05d44fbede..18b464ec0b 100644 --- a/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js +++ b/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js @@ -1,4 +1,4 @@ -import React, {useState} from "react"; +import React from "react"; import { useQuery, useMutation } from "@apollo/client"; import { CardContent, @@ -22,7 +22,10 @@ import { SIGNAL_PROJECTS_QUERY, UPDATE_SIGNAL_PROJECT, } from "../../../queries/signals"; -import { PROJECT_UPDATE_SPONSOR } from "../../../queries/project"; +import { + PROJECT_UPDATE_SPONSOR, + PROJECT_UPDATE_TYPES, +} from "../../../queries/project"; import { PAGING_DEFAULT_COUNT } from "../../../constants/tables"; import RenderFieldLink from "./RenderFieldLink"; import RenderSignalLink from "./RenderSignalLink"; @@ -49,11 +52,9 @@ const SignalProjectTable = () => { fontSize: "14px", }; - const [selectedTypes, setSelectedTypes] = useState([]); - const [updateSignalProject] = useMutation(UPDATE_SIGNAL_PROJECT); const [updateProjectSponsor] = useMutation(PROJECT_UPDATE_SPONSOR); - + const [updateProjectTypes] = useMutation(PROJECT_UPDATE_TYPES); if (error) { console.log(error); @@ -106,7 +107,7 @@ const SignalProjectTable = () => { const project_types = []; if (project?.moped_project_types?.length) { project.moped_project_types.forEach(projType => { - project_types.push(projType?.moped_type?.type_name); + project_types.push(projType?.moped_type?.type_id); }); } project["project_types"] = project_types; @@ -180,7 +181,7 @@ const SignalProjectTable = () => { project["project_inspector"] = inspectors.join(", "); }); - console.log(data.moped_project) + console.log(data.moped_project); /** * Column configuration for @@ -207,20 +208,20 @@ const SignalProjectTable = () => { }, { title: "Project types", - field: "moped_project_types", + field: "project_types", customEdit: "projectTypes", render: entry => { - const project_types = []; - if (entry?.moped_project_types?.length) { - entry.moped_project_types.forEach(projType => { - project_types.push(projType?.moped_type?.type_name); - }) - return {project_types.join(", ")} - }; - return None - } - - + if (entry?.project_types?.length) { + return ( + + {entry.project_types.map(t => typeDict[t]).join(", ")} + + ); + } + return ( + None + ); + }, }, { title: "Current phase", @@ -356,7 +357,6 @@ const SignalProjectTable = () => { }, ]; - /** * projectActions functions object */ @@ -397,6 +397,24 @@ const SignalProjectTable = () => { entityId: newData.entity_id, }, }); + } else if (columnDef.customEdit === "projectTypes") { + const typeIdsToDelete = oldData.filter(t => !newData.includes(t)); + const typeIdsToInsert = newData.filter(t => !oldData.includes(t)); + const typeObjectsToInsert = typeIdsToInsert.map(type_id => ({ + project_id: rowData.project_id, + project_type_id: type_id, + status_id: 1, + })); + // List of primary keys to delete + const typePksToDelete = rowData.moped_project_types + .filter(t => typeIdsToDelete.includes(t?.moped_type.type_id)) + .map(t => t.id); + return updateProjectTypes({ + variables: { + types: typeObjectsToInsert, + deleteList: typePksToDelete, + }, + }); } else { const updatedProjectObject = { ...rowData, @@ -438,18 +456,13 @@ const SignalProjectTable = () => { /> ), projectTypes: props => { - const originalTypesIds = props.value.map(t => t?.moped_type?.type_id); - console.log(props, props.value, selectedTypes) return ( } - renderValue={type_ids => - type_ids.map(t => typeDict[t]).join(", ") - } + renderValue={type_ids => type_ids.map(t => typeDict[t]).join(", ")} /* There appears to be a problem with MenuProps in version 4.x (which is fixed in 5.0), this is fixed by overriding the function "getContentAnchorEl". @@ -465,12 +478,13 @@ const SignalProjectTable = () => { > {typeList.map(type => ( - + ))} - )} + ); + }, }; return ( From 6f76bd84a0761851296edde0273eb5c0b454c2f9 Mon Sep 17 00:00:00 2001 From: Chia Berry Date: Tue, 30 Nov 2021 15:44:17 -0600 Subject: [PATCH 07/10] include update to moped project types in row update --- moped-editor/src/queries/signals.js | 2 +- .../signalProjectTable/SignalProjectTable.js | 28 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/moped-editor/src/queries/signals.js b/moped-editor/src/queries/signals.js index b998af7bb9..115db545b7 100644 --- a/moped-editor/src/queries/signals.js +++ b/moped-editor/src/queries/signals.js @@ -64,7 +64,7 @@ export const UPDATE_SIGNAL_PROJECT = gql` $contractor: String $purchase_order_number: String $entity_id: Int - $projectTypes: [moped_project_types_insert_input!] + $projectTypes: [moped_project_types_insert_input!]! $typesDeleteList: [Int!] ) { update_moped_project_by_pk( diff --git a/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js b/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js index 18b464ec0b..eaaa8c3183 100644 --- a/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js +++ b/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js @@ -181,8 +181,6 @@ const SignalProjectTable = () => { project["project_inspector"] = inspectors.join(", "); }); - console.log(data.moped_project); - /** * Column configuration for */ @@ -384,6 +382,32 @@ const SignalProjectTable = () => { updatedProjectObject["entity_id"] = updatedProjectObject.project_sponsor.entity_id; + // compare moped project types + const oldTypesList = oldData.project_types; + const newTypesList = newData.project_types; + // Retrieves the ids of oldTypesList that are not present in newTypesList + const typeIdsToDelete = oldTypesList.filter( + t => !newTypesList.includes(t) + ); + // Retrieves the ids of newTypesList that are not present in oldTypesList + const typeIdsToInsert = newTypesList.filter( + t => !oldTypesList.includes(t) + ); + // List of objects to insert + const typeObjectsToInsert = typeIdsToInsert.map(type_id => ({ + project_id: oldData.project_id, + project_type_id: type_id, + status_id: 1, + })); + + // List of primary keys to delete + const typePksToDelete = oldData.moped_project_types + .filter(t => typeIdsToDelete.includes(t?.moped_type.type_id)) + .map(t => t.id); + + updatedProjectObject["projectTypes"] = typeObjectsToInsert; + updatedProjectObject["typesDeleteList"] = typePksToDelete; + return updateSignalProject({ variables: updatedProjectObject, }); From 8af73184dfc511c81ebd6992c1d2488a2b881178 Mon Sep 17 00:00:00 2001 From: Chia Berry Date: Wed, 1 Dec 2021 09:41:32 -0600 Subject: [PATCH 08/10] rearrange fields on project summary page --- .../ProjectSummary/ProjectSummary.js | 27 +++++-------------- .../ProjectSummaryProjectPartners.js | 2 +- .../ProjectSummaryProjectSponsor.js | 2 +- .../ProjectSummaryProjectTypes.js | 2 +- .../ProjectSummaryProjectWebsite.js | 2 +- 5 files changed, 11 insertions(+), 24 deletions(-) diff --git a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js index e063d42b26..2cef325f2b 100644 --- a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js +++ b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js @@ -3,7 +3,6 @@ import { useParams } from "react-router-dom"; import ProjectSummaryMap from "./ProjectSummaryMap"; import ProjectSummaryStatusUpdate from "./ProjectSummaryStatusUpdate"; -import ProjectSummaryCurrentPhase from "./ProjectSummaryCurrentPhase"; import { createFeatureCollectionFromProjectFeatures } from "../../../../utils/mapHelpers"; import { Grid, CardContent, CircularProgress } from "@material-ui/core"; @@ -21,7 +20,6 @@ import makeStyles from "@material-ui/core/styles/makeStyles"; import ProjectSummarySnackbar from "./ProjectSummarySnackbar"; import ProjectSummaryProjectWebsite from "./ProjectSummaryProjectWebsite"; import ProjectSummaryProjectDescription from "./ProjectSummaryProjectDescription"; -import ProjectSummaryCurrentStatus from "./ProjectSummaryCurrentStatus"; import ProjectSummaryProjectECapris from "./ProjectSummaryProjectECapris"; import ProjectSummaryProjectTypes from "./ProjectSummaryProjectTypes"; @@ -130,14 +128,9 @@ const ProjectSummary = ({ loading, error, data, refetch }) => { refetch={refetch} classes={classes} /> - - { /> - { - { /> - { /> - + - { /> - + {null} diff --git a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectPartners.js b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectPartners.js index bd7bc0d2ed..3de0e0014d 100644 --- a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectPartners.js +++ b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectPartners.js @@ -129,7 +129,7 @@ const ProjectSummaryProjectPartners = ({ return ( - Project partners + Partners - Project sponsor + Sponsor - Project types + Project type - Project website + Website Date: Wed, 1 Dec 2021 09:57:46 -0600 Subject: [PATCH 09/10] fix spacing with prettier --- .../projects/projectView/ProjectSummary/ProjectSummary.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js index 2cef325f2b..832c1374c8 100644 --- a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js +++ b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js @@ -150,7 +150,7 @@ const ProjectSummary = ({ loading, error, data, refetch }) => { - { /> - + Date: Fri, 3 Dec 2021 10:51:29 -0600 Subject: [PATCH 10/10] change checkmarks to use primary color instead of secondary: --- .../ProjectSummary/ProjectSummaryProjectPartners.js | 1 + .../projectView/ProjectSummary/ProjectSummaryProjectTypes.js | 5 ++++- .../views/projects/signalProjectTable/SignalProjectTable.js | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectPartners.js b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectPartners.js index 3de0e0014d..a456ae6a20 100644 --- a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectPartners.js +++ b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectPartners.js @@ -164,6 +164,7 @@ const ProjectSummaryProjectPartners = ({ diff --git a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js index f833b874c9..11ba5eaf29 100644 --- a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js +++ b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummaryProjectTypes.js @@ -155,7 +155,10 @@ const ProjectSummaryProjectTypes = ({ > {typeList.map(type => ( - + ))} diff --git a/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js b/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js index 48d4e85fc6..0d5ec5bf7e 100644 --- a/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js +++ b/moped-editor/src/views/projects/signalProjectTable/SignalProjectTable.js @@ -503,7 +503,10 @@ const SignalProjectTable = () => { > {typeList.map(type => ( - + ))}