From 8ecbbab36994e1d01f74b3c9fa6f13990ff2975a Mon Sep 17 00:00:00 2001
From: William Wills
Date: Wed, 24 Apr 2024 17:26:59 -0400
Subject: [PATCH 1/2] feat: added commit action to staging table feat: hide
create button on tabs other than committed projects feat: added rtkQuery
endpoints for committing staged items feat: added commit staged items modal
to call commit endpoints
---
.../api/cadt/v1/staging/staging.api.ts | 40 +++++++++-
.../blocks/modals/CommitStagedItemsModal.tsx | 73 +++++++++++++++++++
.../blocks/modals/ConfirmDeleteModal.tsx | 6 +-
.../components/blocks/modals/index.ts | 1 +
src/renderer/pages/MyProjectsPage.tsx | 36 +++++++--
src/renderer/pages/MyUnitsPage.tsx | 29 ++++++--
src/renderer/translations/tokens/en-US.json | 10 ++-
7 files changed, 176 insertions(+), 19 deletions(-)
create mode 100644 src/renderer/components/blocks/modals/CommitStagedItemsModal.tsx
diff --git a/src/renderer/api/cadt/v1/staging/staging.api.ts b/src/renderer/api/cadt/v1/staging/staging.api.ts
index 6d665c13..179eec52 100644
--- a/src/renderer/api/cadt/v1/staging/staging.api.ts
+++ b/src/renderer/api/cadt/v1/staging/staging.api.ts
@@ -27,10 +27,48 @@ const stagingApi = cadtApi.injectEndpoints({
},
providesTags: [stagedUnitsTag],
}),
+
+ commitProjects: builder.mutation({
+ query: () => {
+ return {
+ url: `/v1/staging/commit`,
+ method: 'POST',
+ params: { table: 'Projects' },
+ };
+ },
+ invalidatesTags: [stagedProjectsTag],
+ }),
+
+ commitUnits: builder.mutation({
+ query: () => {
+ return {
+ url: `/v1/staging/commit`,
+ method: 'POST',
+ params: { table: 'Units' },
+ };
+ },
+ invalidatesTags: [stagedUnitsTag],
+ }),
+
+ commitAll: builder.mutation({
+ query: () => {
+ return {
+ url: `/v1/staging/commit`,
+ method: 'POST',
+ };
+ },
+ invalidatesTags: [stagedUnitsTag, stagedProjectsTag],
+ }),
}),
});
const invalidateStagingApiTag = stagingApi.util.invalidateTags;
export { invalidateStagingApiTag };
-export const { useGetStagedProjectsQuery, useGetStagedUnitsQuery } = stagingApi;
+export const {
+ useGetStagedProjectsQuery,
+ useGetStagedUnitsQuery,
+ useCommitProjectsMutation,
+ useCommitUnitsMutation,
+ useCommitAllMutation,
+} = stagingApi;
diff --git a/src/renderer/components/blocks/modals/CommitStagedItemsModal.tsx b/src/renderer/components/blocks/modals/CommitStagedItemsModal.tsx
new file mode 100644
index 00000000..f0c0ad46
--- /dev/null
+++ b/src/renderer/components/blocks/modals/CommitStagedItemsModal.tsx
@@ -0,0 +1,73 @@
+import React from 'react';
+import { Button, Modal } from '@/components';
+import { FormattedMessage } from 'react-intl';
+import { useCommitAllMutation, useCommitProjectsMutation, useCommitUnitsMutation } from '@/api/cadt/v1/staging';
+
+interface ModalProps {
+ numStagedItems: number;
+ onClose: () => void;
+}
+
+const CommitStagedItemsModal: React.FC = ({ onClose, numStagedItems }) => {
+ const [triggerCommitAll, { isLoading: commitAllLoading }] = useCommitAllMutation();
+ const [triggerCommitProjects, { isLoading: commitProjectsLoading }] = useCommitProjectsMutation();
+ const [triggerCommitUnits, { isLoading: commitUnitsLoading }] = useCommitUnitsMutation();
+ const handleClickClose = async () => {
+ onClose();
+ };
+
+ return (
+
+
+
+
+ {numStagedItems ? (
+ <>
+
+
+ ?
+
+
+
+
+
+
+
+
+ >
+ ) : (
+
+
+ .
+
+
+ )}
+
+ );
+};
+
+export { CommitStagedItemsModal };
diff --git a/src/renderer/components/blocks/modals/ConfirmDeleteModal.tsx b/src/renderer/components/blocks/modals/ConfirmDeleteModal.tsx
index 3c0b72f6..98ca2af5 100644
--- a/src/renderer/components/blocks/modals/ConfirmDeleteModal.tsx
+++ b/src/renderer/components/blocks/modals/ConfirmDeleteModal.tsx
@@ -46,9 +46,6 @@ const ConfirmDeleteModal: React.FC = ({
-
+
);
diff --git a/src/renderer/components/blocks/modals/index.ts b/src/renderer/components/blocks/modals/index.ts
index 64c2393c..b2821fd7 100644
--- a/src/renderer/components/blocks/modals/index.ts
+++ b/src/renderer/components/blocks/modals/index.ts
@@ -7,3 +7,4 @@ export * from './UpsertProjectModal';
export * from './UpsertUnitModal';
export * from './StagedProjectSuccessModal';
export * from './ConfirmDeleteModal';
+export * from './CommitStagedItemsModal';
diff --git a/src/renderer/pages/MyProjectsPage.tsx b/src/renderer/pages/MyProjectsPage.tsx
index 3dfe59ec..6b0fe7cb 100644
--- a/src/renderer/pages/MyProjectsPage.tsx
+++ b/src/renderer/pages/MyProjectsPage.tsx
@@ -4,16 +4,17 @@ import { useQueryParamState, useUrlHash, useWildCardUrlHash } from '@/hooks';
import { debounce } from 'lodash';
import {
Button,
+ CommitStagedItemsModal,
CommittedProjectsTab,
ComponentCenteredSpinner,
IndeterminateProgressOverlay,
OrgUidBadge,
SearchBox,
+ StagedProjectSuccessModal,
StagingTableTab,
SyncIndicator,
Tabs,
UpsertProjectModal,
- StagedProjectSuccessModal
} from '@/components';
import { FormattedMessage } from 'react-intl';
import { useGetOrganizationsMapQuery } from '@/api/cadt/v1/organizations';
@@ -42,6 +43,7 @@ const MyProjectsPage: React.FC = () => {
const [, editProjectModalActive] = useWildCardUrlHash('edit-project');
const [createProjectModalActive, setCreateProjectModalActive] = useUrlHash('create-project');
const [projectStagedSuccess, setProjectStagedSuccess] = useUrlHash('success-stage-project');
+ const [commitModalActive, setCommitModalActive] = useUrlHash('commit-staged-items');
const [activeTab, setActiveTab] = useState(TabTypes.COMMITTED);
const [committedDataLoading, setCommittedDataLoading] = useState(false);
const { data: organizationsMap } = useGetOrganizationsMapQuery(null, {
@@ -109,12 +111,23 @@ const MyProjectsPage: React.FC = () => {
{contentsLoading &&
}
-
- {activeTab === TabTypes.COMMITTED && }
- {orgUid && }
+ {activeTab === TabTypes.COMMITTED && (
+ <>
+
+
+ >
+ )}
+ {activeTab === TabTypes.STAGING && (
+ <>
+
+ >
+ )}
+ {orgUid && }
setActiveTab(tab)}>
@@ -155,8 +168,15 @@ const MyProjectsPage: React.FC = () => {
{(createProjectModalActive || editProjectModalActive) && }
- {projectStagedSuccess && setProjectStagedSuccess(false)} />}
- {createProjectModalActive && }
+ {commitModalActive && (
+ setCommitModalActive(false)}
+ />
+ )}
+ {projectStagedSuccess && (
+ setProjectStagedSuccess(false)} />
+ )}
>
);
};
diff --git a/src/renderer/pages/MyUnitsPage.tsx b/src/renderer/pages/MyUnitsPage.tsx
index b854a9f2..39522ba7 100644
--- a/src/renderer/pages/MyUnitsPage.tsx
+++ b/src/renderer/pages/MyUnitsPage.tsx
@@ -1,9 +1,10 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useGetOrganizationsListQuery } from '@/api';
-import { useQueryParamState, useWildCardUrlHash, useUrlHash } from '@/hooks';
+import { useQueryParamState, useUrlHash, useWildCardUrlHash } from '@/hooks';
import { debounce } from 'lodash';
import {
Button,
+ CommitStagedItemsModal,
CommittedUnitsTab,
ComponentCenteredSpinner,
IndeterminateProgressOverlay,
@@ -40,6 +41,7 @@ const MyUnitsPage: React.FC = () => {
const [search, setSearch] = useQueryParamState('search', undefined);
const [, editUnitModalActive, setEditUnitModalActive] = useWildCardUrlHash('edit-unit');
const [createUnitModalActive, setCreateUnitModalActive] = useUrlHash('create-unit');
+ const [commitModalActive, setCommitModalActive] = useUrlHash('commit-staged-items');
const [activeTab, setActiveTab] = useState(TabTypes.COMMITTED);
const [committedDataLoading, setCommittedDataLoading] = useState(false);
const { data: organizationsMap } = useGetOrganizationsMapQuery(null, {
@@ -108,10 +110,21 @@ const MyUnitsPage: React.FC = () => {
{contentsLoading &&
}
-
- {activeTab === TabTypes.COMMITTED && }
+ {activeTab === TabTypes.COMMITTED && (
+ <>
+
+
+ >
+ )}
+ {activeTab === TabTypes.STAGING && (
+ <>
+
+ >
+ )}
{orgUid && }
@@ -153,6 +166,12 @@ const MyUnitsPage: React.FC = () => {
}>todo transfers
+ {commitModalActive && (
+ setCommitModalActive(false)}
+ />
+ )}
{(createUnitModalActive || editUnitModalActive) && }
>
);
diff --git a/src/renderer/translations/tokens/en-US.json b/src/renderer/translations/tokens/en-US.json
index 029bb28f..c09ff98e 100644
--- a/src/renderer/translations/tokens/en-US.json
+++ b/src/renderer/translations/tokens/en-US.json
@@ -105,7 +105,6 @@
"issuances": "Issuances",
"project_locations": "Project Locations",
"labels": "Labels",
- "ratings": "Ratings",
"co-benefits": "Co-Benefits",
"related-projects": "Related Projects",
"delete": "Delete",
@@ -113,5 +112,12 @@
"confirm-delete": "Confirm Delete",
"this-action-cannot-be-undone": "This action cannot be undone",
"ratings": "Ratings",
- "edit-unit": "Edit Unit"
+ "edit-unit": "Edit Unit",
+ "commit": "Commit",
+ "commit-staged-changes": "Commit Staged Changes",
+ "what-would-you-like-to-commit": "What would you like to commit",
+ "commit-all": "Commit All",
+ "commit-projects-only": "Commit Projects Only",
+ "commit-units-only": "Commit Units Only",
+ "nothing-to-commit": "Nothing to commit"
}
From a719995d0a9231e987cd39be14d43545d22db7e5 Mon Sep 17 00:00:00 2001
From: William Wills
Date: Wed, 24 Apr 2024 17:44:47 -0400
Subject: [PATCH 2/2] feat: changed commit actions based on table feat:
disabled commit button if nothing to commit
---
.../blocks/modals/CommitStagedItemsModal.tsx | 99 ++++++++++---------
src/renderer/pages/MyProjectsPage.tsx | 12 +--
src/renderer/pages/MyUnitsPage.tsx | 12 +--
3 files changed, 64 insertions(+), 59 deletions(-)
diff --git a/src/renderer/components/blocks/modals/CommitStagedItemsModal.tsx b/src/renderer/components/blocks/modals/CommitStagedItemsModal.tsx
index f0c0ad46..d3c77fbe 100644
--- a/src/renderer/components/blocks/modals/CommitStagedItemsModal.tsx
+++ b/src/renderer/components/blocks/modals/CommitStagedItemsModal.tsx
@@ -4,11 +4,11 @@ import { FormattedMessage } from 'react-intl';
import { useCommitAllMutation, useCommitProjectsMutation, useCommitUnitsMutation } from '@/api/cadt/v1/staging';
interface ModalProps {
- numStagedItems: number;
+ type: 'project' | 'unit';
onClose: () => void;
}
-const CommitStagedItemsModal: React.FC = ({ onClose, numStagedItems }) => {
+const CommitStagedItemsModal: React.FC = ({ onClose, type }) => {
const [triggerCommitAll, { isLoading: commitAllLoading }] = useCommitAllMutation();
const [triggerCommitProjects, { isLoading: commitProjectsLoading }] = useCommitProjectsMutation();
const [triggerCommitUnits, { isLoading: commitUnitsLoading }] = useCommitUnitsMutation();
@@ -21,51 +21,56 @@ const CommitStagedItemsModal: React.FC = ({ onClose, numStagedItems
- {numStagedItems ? (
- <>
-
-
- ?
-
-
-
-
-
-
-
-
- >
- ) : (
-
-
- .
-
-
- )}
+
+
+ ?
+
+
+
+
+ {type === 'project' && (
+
+ )}
+ {type === 'unit' && (
+
+ )}
+
+
);
};
diff --git a/src/renderer/pages/MyProjectsPage.tsx b/src/renderer/pages/MyProjectsPage.tsx
index 6b0fe7cb..b15431b2 100644
--- a/src/renderer/pages/MyProjectsPage.tsx
+++ b/src/renderer/pages/MyProjectsPage.tsx
@@ -121,7 +121,10 @@ const MyProjectsPage: React.FC = () => {
)}
{activeTab === TabTypes.STAGING && (
<>
-