diff --git a/moped-database/metadata/tables.yaml b/moped-database/metadata/tables.yaml index e4341e898c..0559ad3973 100644 --- a/moped-database/metadata/tables.yaml +++ b/moped-database/metadata/tables.yaml @@ -1669,37 +1669,40 @@ - role: moped-admin permission: columns: + - date_added - department_id - entity_id - - organization_id - - workgroup_id - entity_name - - date_added - entity_uuid + - is_deleted + - organization_id + - workgroup_id filter: {} allow_aggregations: true - role: moped-editor permission: columns: + - date_added - department_id - entity_id - - organization_id - - workgroup_id - entity_name - - date_added - entity_uuid + - is_deleted + - organization_id + - workgroup_id filter: {} allow_aggregations: true - role: moped-viewer permission: columns: + - date_added - department_id - entity_id - - organization_id - - workgroup_id - entity_name - - date_added - entity_uuid + - is_deleted + - organization_id + - workgroup_id filter: {} allow_aggregations: true - table: @@ -5493,6 +5496,9 @@ - workgroup_name filter: {} allow_aggregations: true +- table: + name: project_funding_view + schema: public - table: name: project_geography schema: public diff --git a/moped-database/migrations/1735855851119_update_atd_project_owner_to_tpw_project_owner/down.sql b/moped-database/migrations/1735855851119_update_atd_project_owner_to_tpw_project_owner/down.sql new file mode 100644 index 0000000000..da1ea566a4 --- /dev/null +++ b/moped-database/migrations/1735855851119_update_atd_project_owner_to_tpw_project_owner/down.sql @@ -0,0 +1,10 @@ +INSERT INTO moped_project_roles (project_role_id, project_role_name, active_role, role_order, project_role_description) +VALUES (0, 'Unknown', TRUE, 999, 'Unknown Role'); + +UPDATE moped_project_roles +SET project_role_description = 'Supervises contractor activities for approval before invoicing; accepts work on behalf of ATD and coordinates with other divisions' +WHERE project_role_id = 12; + +UPDATE moped_project_roles +SET project_role_name = 'ATD Project Owner' +WHERE project_role_id = 5; diff --git a/moped-database/migrations/1735855851119_update_atd_project_owner_to_tpw_project_owner/up.sql b/moped-database/migrations/1735855851119_update_atd_project_owner_to_tpw_project_owner/up.sql new file mode 100644 index 0000000000..e7528156f8 --- /dev/null +++ b/moped-database/migrations/1735855851119_update_atd_project_owner_to_tpw_project_owner/up.sql @@ -0,0 +1,10 @@ +UPDATE moped_project_roles +SET project_role_name = 'TPW Project Owner' +WHERE project_role_id = 5; + +UPDATE moped_project_roles +SET project_role_description = 'Supervises contractor activities for approval before invoicing; accepts work on behalf of TPW and coordinates with other divisions' +WHERE project_role_id = 12; + +DELETE FROM moped_project_roles +WHERE project_role_id = 0; diff --git a/moped-database/migrations/1736291471358_add_proj_fund_view/down.sql b/moped-database/migrations/1736291471358_add_proj_fund_view/down.sql new file mode 100644 index 0000000000..6a7212b820 --- /dev/null +++ b/moped-database/migrations/1736291471358_add_proj_fund_view/down.sql @@ -0,0 +1 @@ +DROP VIEW project_funding_view; diff --git a/moped-database/migrations/1736291471358_add_proj_fund_view/up.sql b/moped-database/migrations/1736291471358_add_proj_fund_view/up.sql new file mode 100644 index 0000000000..859ef5f717 --- /dev/null +++ b/moped-database/migrations/1736291471358_add_proj_fund_view/up.sql @@ -0,0 +1,22 @@ +CREATE OR REPLACE VIEW project_funding_view AS +SELECT + mp.project_id, + mpf.proj_funding_id, + mpf.funding_amount, + mpf.funding_description, + mpf.fund_dept_unit, + mpf.created_at, + mpf.updated_at, + mfs.funding_source_name, + mfp.funding_program_name, + mfst.funding_status_name +FROM + moped_project AS mp +LEFT JOIN moped_proj_funding AS mpf ON mp.project_id = mpf.project_id +LEFT JOIN moped_fund_sources AS mfs ON mpf.funding_source_id = mfs.funding_source_id +LEFT JOIN moped_fund_programs AS mfp ON mpf.funding_program_id = mfp.funding_program_id +LEFT JOIN moped_fund_status AS mfst ON mpf.funding_status_id = mfst.funding_status_id +WHERE + TRUE + AND mp.is_deleted = FALSE + AND mpf.is_deleted = FALSE; diff --git a/moped-database/migrations/1736442550315_update_entities/down.sql b/moped-database/migrations/1736442550315_update_entities/down.sql new file mode 100644 index 0000000000..efe66439ec --- /dev/null +++ b/moped-database/migrations/1736442550315_update_entities/down.sql @@ -0,0 +1,3 @@ +-- Updating moped_entity table will be up only. If we need to revert, we will need do it manually or +-- update with a future migration. +SELECT 0; diff --git a/moped-database/migrations/1736442550315_update_entities/up.sql b/moped-database/migrations/1736442550315_update_entities/up.sql new file mode 100644 index 0000000000..173542c8e2 --- /dev/null +++ b/moped-database/migrations/1736442550315_update_entities/up.sql @@ -0,0 +1,251 @@ +-- Make is_deleted non-nullable in moped_workgroup and moped_department +ALTER TABLE moped_workgroup +ALTER COLUMN is_deleted SET NOT NULL; + +ALTER TABLE moped_department +ALTER COLUMN is_deleted SET NOT NULL; + +-- Add is_deleted to moped_entity +ALTER TABLE moped_entity +ADD COLUMN is_deleted BOOLEAN DEFAULT FALSE NOT NULL; + + +-- Soft delete the old entities +UPDATE moped_entity +SET is_deleted = TRUE +WHERE entity_name IN ('COA PWD Sidewalks & Special Projects', 'COA PWD Urban Trails', 'COA ATD', 'COA PWD'); + +-- Insert new COA TPW Sidewalks and Urban Trails entity with appropriate department_id, workgroup_id, and organization_id +WITH +workgroup AS ( + SELECT workgroup_id + FROM + moped_workgroup + WHERE + workgroup_name = 'Sidewalks and Urban Trails' +), + +organization AS ( + SELECT organization_id + FROM + moped_organization + WHERE + organization_name = 'City of Austin' +), + +department AS ( + SELECT department_id + FROM + moped_department + WHERE + department_name = 'Austin Transportation and Public Works' +) + +INSERT INTO +moped_entity (entity_name, department_id, workgroup_id, organization_id) +SELECT + 'COA TPW Sidewalks and Urban Trails' AS entity_name, + department.department_id, + workgroup.workgroup_id, + organization.organization_id +FROM + department, + workgroup, + organization; + +-- Insert new row for COA TPW with appropriate department_id and organization_id (no associated workgroup) +WITH organization AS ( + SELECT organization_id FROM moped_organization WHERE organization_name = 'City of Austin' +), + +department AS ( + SELECT department_id FROM moped_department WHERE department_name = 'Austin Transportation and Public Works' +) + +INSERT INTO moped_entity (entity_name, department_id, workgroup_id, organization_id, is_deleted) +SELECT + 'COA TPW' AS entity_name, + department.department_id, + NULL AS workgroup_id, + organization.organization_id, + FALSE AS is_deleted +FROM department, organization; + +-- Find any records (except the soft-deleted above) that have either ATD or PWD in them and replace with TPW +UPDATE moped_entity +SET + entity_name = REPLACE(REPLACE(entity_name, 'ATD', 'TPW'), 'PWD', 'TPW') +WHERE + ( + entity_name LIKE '%ATD%' + OR entity_name LIKE '%PWD%' + ) + AND (entity_name NOT IN ('COA PWD Sidewalks & Special Projects', 'COA PWD Urban Trails', 'COA ATD', 'COA PWD')); + +-- UPDATE PROJECT SPONSORS + +-- Find and update projects that need sponsor to be updated to COA TPW Sidewalks and Urban Trails +WITH project_sponsor_todos AS ( + SELECT entity_id AS ids + FROM + moped_entity + WHERE + entity_name IN ( + 'COA PWD Sidewalks & Special Projects', + 'COA PWD Urban Trails' + ) +), + +new_entity_row AS ( + SELECT entity_id AS id + FROM + moped_entity + WHERE + entity_name = 'COA TPW Sidewalks and Urban Trails' +) + +UPDATE +moped_project +SET + project_sponsor = (SELECT id FROM new_entity_row) +WHERE + project_sponsor IN (SELECT ids FROM project_sponsor_todos); + +-- Find and update projects that need sponsor to be updated to COA TPW +WITH project_sponsor_todos AS ( + SELECT entity_id AS ids + FROM + moped_entity + WHERE + entity_name IN ( + 'COA ATD', + 'COA PWD' + ) +), + +new_entity_row AS ( + SELECT entity_id AS id + FROM + moped_entity + WHERE + entity_name = 'COA TPW' +) + +UPDATE +moped_project +SET + project_sponsor = (SELECT id FROM new_entity_row) +WHERE + project_sponsor IN (SELECT ids FROM project_sponsor_todos); + +-- UPDATE PROJECT LEADS + +-- Find and update projects that need lead to be updated to COA TPW Sidewalks and Urban Trails +WITH project_lead_todos AS ( + SELECT entity_id AS ids + FROM + moped_entity + WHERE + entity_name IN ( + 'COA PWD Sidewalks & Special Projects', + 'COA PWD Urban Trails' + ) +), + +new_entity_row AS ( + SELECT entity_id AS id + FROM + moped_entity + WHERE + entity_name = 'COA TPW Sidewalks and Urban Trails' +) + +UPDATE +moped_project +SET + project_lead_id = (SELECT id FROM new_entity_row) +WHERE + project_lead_id IN (SELECT ids FROM project_lead_todos); + +-- Find and update projects that need lead to be updated to COA TPW +WITH project_lead_todos AS ( + SELECT entity_id AS ids + FROM + moped_entity + WHERE + entity_name IN ( + 'COA ATD', + 'COA PWD' + ) +), + +new_entity_row AS ( + SELECT entity_id AS id + FROM + moped_entity + WHERE + entity_name = 'COA TPW' +) + +UPDATE +moped_project +SET + project_lead_id = (SELECT id FROM new_entity_row) +WHERE + project_lead_id IN (SELECT ids FROM project_lead_todos); + +-- UPDATE PROJECT PARTNERS + +-- Find and update projects that need lead to be updated to COA TPW Sidewalks and Urban Trails +WITH project_partner_todos AS ( + SELECT entity_id AS ids + FROM + moped_entity + WHERE + entity_name IN ( + 'COA PWD Sidewalks & Special Projects', + 'COA PWD Urban Trails' + ) +), + +new_entity_row AS ( + SELECT entity_id AS id + FROM + moped_entity + WHERE + entity_name = 'COA TPW Sidewalks and Urban Trails' +) + +UPDATE +moped_proj_partners +SET + entity_id = (SELECT id FROM new_entity_row) +WHERE + entity_id IN (SELECT ids FROM project_partner_todos); + +-- Find and update projects that need lead to be updated to COA TPW +WITH project_partner_todos AS ( + SELECT entity_id AS ids + FROM + moped_entity + WHERE + entity_name IN ( + 'COA ATD', + 'COA PWD' + ) +), + +new_entity_row AS ( + SELECT entity_id AS id + FROM + moped_entity + WHERE + entity_name = 'COA TPW' +) + +UPDATE +moped_proj_partners +SET + entity_id = (SELECT id FROM new_entity_row) +WHERE + entity_id IN (SELECT ids FROM project_partner_todos); diff --git a/moped-database/recipes/copy_component_work_types_from_other_component.sql b/moped-database/recipes/copy_component_work_types_from_other_component.sql new file mode 100644 index 0000000000..8654776555 --- /dev/null +++ b/moped-database/recipes/copy_component_work_types_from_other_component.sql @@ -0,0 +1,26 @@ +-- This example inserts the same moped_component_work_types work types as the Trail - Shared Use Path (Paved) component +-- into the new Trail - Shared Use Path (Paved Dual Trail) component. +-- This is useful when creating a new component that is similar to an existing component. +-- See https://github.com/cityofaustin/atd-moped/pull/1191 +WITH inserts_todo AS ( + SELECT + work_type_id, + 'Trail' AS component_name, + 'Shared Use Path (Paved Dual Trail)' AS component_subtype + FROM + moped_component_work_types AS mcwt + LEFT JOIN moped_work_types AS mwt ON mcwt.work_type_id = mwt.id + LEFT JOIN moped_components AS mc ON mcwt.component_id = mc.component_id + WHERE + mc.component_subtype LIKE 'Shared Use Path (Paved)' +) + +INSERT INTO moped_component_work_types (component_id, work_type_id) +SELECT + mc.component_id, + inserts_todo.work_type_id +FROM + inserts_todo + -- gets the component id of the new component we created +LEFT JOIN moped_components AS mc ON inserts_todo.component_name = mc.component_name + AND inserts_todo.component_subtype = mc.component_subtype; diff --git a/moped-database/recipes/update_merged_funding_sources.sql b/moped-database/recipes/update_merged_funding_sources.sql new file mode 100644 index 0000000000..ac8324e2d4 --- /dev/null +++ b/moped-database/recipes/update_merged_funding_sources.sql @@ -0,0 +1,28 @@ +-- This example finds existing project funding sources that are associated with the sources that merged +-- and updates them to the new funding source. +-- See https://github.com/cityofaustin/atd-moped/pull/1486 +WITH funding_source_todos AS ( + SELECT funding_source_id AS ids + FROM + moped_fund_sources + WHERE + funding_source_name IN ( + 'Austin Transportation', + 'Public Works' + ) +), + +new_funding_source_row AS ( + SELECT funding_source_id AS id + FROM + moped_fund_sources + WHERE + funding_source_name = 'Austin Transportation and Public Works' +) + +UPDATE +moped_proj_funding +SET + funding_source_id = (SELECT id FROM new_funding_source_row) +WHERE + funding_source_id IN (SELECT ids FROM funding_source_todos); diff --git a/moped-database/recipes/update_merged_workgroups.sql b/moped-database/recipes/update_merged_workgroups.sql new file mode 100644 index 0000000000..502aed9385 --- /dev/null +++ b/moped-database/recipes/update_merged_workgroups.sql @@ -0,0 +1,29 @@ +-- This example finds all users who were previously in the 'Sidewalks' or 'Urban Trails' workgroups and sets their +-- workgroup to the new, merged workgroup called 'Sidewalks and Urban Trails'. +-- This is useful when merging workgroups and needing to update all users associated with the old workgroups. +-- See https://github.com/cityofaustin/atd-moped/pull/1515 +WITH user_todos AS ( + SELECT workgroup_id AS ids + FROM + moped_workgroup + WHERE + workgroup_name IN ( + 'Sidewalks', + 'Urban Trails' + ) +), + +new_workgroup_row AS ( + SELECT workgroup_id AS id + FROM + moped_workgroup + WHERE + workgroup_name = 'Sidewalks and Urban Trails' +) + +UPDATE +moped_users +SET + workgroup_id = (SELECT id FROM new_workgroup_row) +WHERE + workgroup_id IN (SELECT ids FROM user_todos); diff --git a/moped-database/views/project_funding_view.sql b/moped-database/views/project_funding_view.sql new file mode 100644 index 0000000000..ffe0ef676c --- /dev/null +++ b/moped-database/views/project_funding_view.sql @@ -0,0 +1,19 @@ +-- Most recent migration: moped-database/migrations/1736291471358_add_proj_fund_view/up.sql + +CREATE OR REPLACE VIEW project_funding_view AS SELECT + mp.project_id, + mpf.proj_funding_id, + mpf.funding_amount, + mpf.funding_description, + mpf.fund_dept_unit, + mpf.created_at, + mpf.updated_at, + mfs.funding_source_name, + mfp.funding_program_name, + mfst.funding_status_name +FROM moped_project mp +LEFT JOIN moped_proj_funding mpf ON mp.project_id = mpf.project_id +LEFT JOIN moped_fund_sources mfs ON mpf.funding_source_id = mfs.funding_source_id +LEFT JOIN moped_fund_programs mfp ON mpf.funding_program_id = mfp.funding_program_id +LEFT JOIN moped_fund_status mfst ON mpf.funding_status_id = mfst.funding_status_id +WHERE true AND mp.is_deleted = false AND mpf.is_deleted = false; diff --git a/moped-editor/package.json b/moped-editor/package.json index 9e13b90b23..3e28c7f8ae 100644 --- a/moped-editor/package.json +++ b/moped-editor/package.json @@ -2,7 +2,7 @@ "name": "atd-moped-editor", "author": "ATD Data & Technology Services", "license": "CC0-1.0", - "version": "2.27.0", + "version": "2.28.0", "homepage": "/moped", "private": false, "repository": { diff --git a/moped-editor/src/App.js b/moped-editor/src/App.js index 7fff5068fe..b3cff0137a 100644 --- a/moped-editor/src/App.js +++ b/moped-editor/src/App.js @@ -66,9 +66,6 @@ const useClient = (user) => moped_phases: { keyFields: ["phase_id"], }, - moped_types: { - keyFields: ["type_id"], - }, }, }), }); diff --git a/moped-editor/src/queries/project.js b/moped-editor/src/queries/project.js index 082c0b919f..e36327616d 100644 --- a/moped-editor/src/queries/project.js +++ b/moped-editor/src/queries/project.js @@ -13,9 +13,6 @@ export const ADD_PROJECT = gql` phase_id is_current_phase } - moped_project_types { - project_type_id - } } } `; @@ -65,13 +62,6 @@ export const SUMMARY_QUERY = gql` } created_at } - moped_project_types(where: { is_deleted: { _eq: false } }) { - id - moped_type { - type_name - type_id - } - } moped_entity { entity_name entity_id @@ -108,7 +98,10 @@ export const SUMMARY_QUERY = gql` phase_name phase_order } - moped_entity(order_by: { entity_name: asc }) { + moped_entity( + order_by: { entity_name: asc } + where: { is_deleted: { _eq: false } } + ) { entity_id entity_name } @@ -116,10 +109,6 @@ export const SUMMARY_QUERY = gql` id name } - moped_types(order_by: { type_name: asc }) { - type_id - type_name - } moped_user_followed_projects( where: { project_id: { _eq: $projectId }, user_id: { _eq: $userId } } ) { @@ -158,15 +147,6 @@ export const SUMMARY_QUERY = gql` } `; -export const TYPES_QUERY = gql` - query TypeQuery { - moped_types(order_by: { type_name: asc }) { - type_id - type_name - } - } -`; - export const TEAM_QUERY = gql` query TeamQuery($projectId: Int!) { moped_project_by_pk(project_id: $projectId) { @@ -204,7 +184,7 @@ export const TEAM_QUERY = gql` } moped_project_roles( order_by: { project_role_name: asc } - where: { project_role_id: { _gt: 0 }, active_role: { _eq: true } } + where: { active_role: { _eq: true } } ) { project_role_id project_role_name @@ -842,23 +822,6 @@ export const PROJECT_UPDATE_DESCRIPTION = gql` } `; -export const PROJECT_UPDATE_TYPES = gql` - mutation UpdateMopedProjectTypes( - $types: [moped_project_types_insert_input!]! - $deleteList: [Int!]! - ) { - insert_moped_project_types(objects: $types) { - affected_rows - } - update_moped_project_types( - where: { id: { _in: $deleteList } } - _set: { is_deleted: true } - ) { - affected_rows - } - } -`; - export const PROJECT_UPDATE_ECAPRIS_SUBPROJECT_ID = gql` mutation UpdateProjectECapris($projectId: Int!, $eCapris: String!) { update_moped_project( @@ -964,11 +927,10 @@ export const LOOKUP_TABLES_QUERY = gql` funding_program_id funding_program_name } - moped_types(order_by: { type_name: asc }) { - type_id - type_name - } - moped_entity(order_by: { entity_id: asc }) { + moped_entity( + order_by: { entity_id: asc } + where: { is_deleted: { _eq: false } } + ) { entity_id entity_name } diff --git a/moped-editor/src/queries/tableLookups.js b/moped-editor/src/queries/tableLookups.js index dc34f69d9d..0a17ee5828 100644 --- a/moped-editor/src/queries/tableLookups.js +++ b/moped-editor/src/queries/tableLookups.js @@ -55,7 +55,10 @@ export const TABLE_LOOKUPS_QUERY = gql` slug type } - moped_entity(order_by: { entity_name: asc }) { + moped_entity( + order_by: { entity_name: asc } + where: { is_deleted: { _eq: false } } + ) { entity_id entity_name } diff --git a/moped-editor/src/utils/activityLogFormatters/mopedPartnersActivity.js b/moped-editor/src/utils/activityLogFormatters/mopedPartnersActivity.js index aff1ed4710..67d04012ec 100644 --- a/moped-editor/src/utils/activityLogFormatters/mopedPartnersActivity.js +++ b/moped-editor/src/utils/activityLogFormatters/mopedPartnersActivity.js @@ -16,11 +16,28 @@ export const formatPartnersActivity = (change, entityList) => { ], }; } else { - // Soft deleting a partner is the only update a user can do (is_deleted is set to true) + const description = change?.description?.[0]; + const changedField = description?.field; + + // If the changed field is is_deleted, then the partner was removed + if (changedField === "is_deleted") { + return { + changeIcon, + changeText: [ + { text: "Removed project partner ", style: null }, + { + text: entityList[change.record_data.event.data.new.entity_id], + style: "boldText", + }, + ], + }; + } + + // Otherwise, the partner was changed. For example, the partner's name was changed. return { changeIcon, changeText: [ - { text: "Removed project partner ", style: null }, + { text: "Changed project partner ", style: null }, { text: entityList[change.record_data.event.data.new.entity_id], style: "boldText", diff --git a/moped-editor/src/views/projects/projectView/ProjectStatusBadge.js b/moped-editor/src/views/projects/projectView/ProjectStatusBadge.js index 825764b165..42ed86a45b 100644 --- a/moped-editor/src/views/projects/projectView/ProjectStatusBadge.js +++ b/moped-editor/src/views/projects/projectView/ProjectStatusBadge.js @@ -77,8 +77,8 @@ export const styleMapping = { icon: PlayCircleOutlineOutlinedIcon, }, construction: { - color: white, - background: backgroundColors.success, + color: primary, + background: backgroundColors.warning, icon: PlayCircleOutlineOutlinedIcon, }, post_construction: { @@ -88,7 +88,7 @@ export const styleMapping = { }, potential: { color: primary, - background: backgroundColors.warning, + background: backgroundColors.default, icon: RemoveCircleOutlineOutlinedIcon, }, canceled: { diff --git a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js index 9c98b3c2d3..53ef40fc88 100644 --- a/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js +++ b/moped-editor/src/views/projects/projectView/ProjectSummary/ProjectSummary.js @@ -13,7 +13,6 @@ import ProjectSummaryProjectWebsite from "./ProjectSummaryProjectWebsite"; import ProjectSummaryProjectDescription from "./ProjectSummaryProjectDescription"; import ProjectSummaryParentProjectLink from "./ProjectSummaryParentProjectLink"; import ProjectSummaryProjectECapris from "./ProjectSummaryProjectECapris"; -import ProjectSummaryProjectTypes from "./ProjectSummaryProjectTypes"; import ProjectSummaryDataTrackerSignals from "./ProjectSummaryDataTrackerSignals"; import ProjectSummaryWorkOrders from "./ProjectSummaryWorkOrders"; import ProjectSummaryInterimID from "./ProjectSummaryInterimID"; @@ -225,15 +224,6 @@ const ProjectSummary = ({ loading, error, data, refetch, listViewQuery }) => { tooltipText="Other internal or external workgroups participating in the project" /> - - - { - /** - * 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 = originalTypes.map(t => t?.moped_type?.type_id); - - /** - * Edit Mode and selected Types states - */ - const [editMode, setEditMode] = useState(false); - const [selectedTypes, setSelectedTypes] = useState(originalTypesIds); - - // 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 types list back to the original state, closes edit mode - */ - const handleProjectTypesClose = () => { - setSelectedTypes(originalTypesIds); - setEditMode(false); - }; - - /** - * Saves the new project types - */ - const handleProjectTypesSave = () => { - // 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)); - // 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: projectId, - project_type_id: type_id, - })); - - // List of primary keys to delete - const typePksToDelete = originalTypes - .filter(t => typeIdsToDelete.includes(t?.moped_type.type_id)) - .map(t => t.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); - }; - - // join selected type names in a comma separated string - // used to display when not editing - - return ( - - Project type - - {editMode ? ( - <> - - - check - - - close - - - ) : ( - typeDict[t]) - } - classes={classes} - onClickEdit={() => setEditMode(true)} - /> - )} - - - ); -}; - -export default ProjectSummaryProjectTypes; diff --git a/moped-editor/src/views/projects/projectView/ProjectTeam/ProjectTeamTable.js b/moped-editor/src/views/projects/projectView/ProjectTeam/ProjectTeamTable.js index e13565048a..63499573af 100644 --- a/moped-editor/src/views/projects/projectView/ProjectTeam/ProjectTeamTable.js +++ b/moped-editor/src/views/projects/projectView/ProjectTeam/ProjectTeamTable.js @@ -115,7 +115,7 @@ const useColumns = ({
Role{" "} diff --git a/moped-editor/src/views/projects/projectView/ProjectTeam/ProjectTeamToolbar.js b/moped-editor/src/views/projects/projectView/ProjectTeam/ProjectTeamToolbar.js index a70d3528bd..b0c8e8f323 100644 --- a/moped-editor/src/views/projects/projectView/ProjectTeam/ProjectTeamToolbar.js +++ b/moped-editor/src/views/projects/projectView/ProjectTeam/ProjectTeamToolbar.js @@ -5,7 +5,7 @@ import AddCircleIcon from "@mui/icons-material/AddCircle"; const ProjectTeamToolbar = ({ addAction }) => ( - Project Team + Project team