Skip to content

Commit

Permalink
Merge pull request activepieces#6431 from activepieces/feat/bulk-push…
Browse files Browse the repository at this point in the history
…-git

feat: support bulk push to git-sync
  • Loading branch information
abuaboud authored Dec 31, 2024
2 parents 5c830c3 + 3a7f83e commit 67daa4b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/ee/shared/src/lib/git-repo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const PushGitRepoRequest = Type.Object({
commitMessage: Type.String({
minLength: 1,
}),
flowId: Type.String()
flowIds: Type.Array(Type.String())
})

export type PushGitRepoRequest = Static<typeof PushGitRepoRequest>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ui/src/app/components/flow-actions-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const FlowActionMenu: React.FC<FlowActionMenuProps> = ({
</PermissionNeededTooltip>
)}
<PermissionNeededTooltip hasPermission={userHasPermissionToPushToGit}>
<PushToGitDialog flowId={flow.id}>
<PushToGitDialog flowIds={[flow.id]}>
<DropdownMenuItem
disabled={!userHasPermissionToPushToGit}
onSelect={(e) => e.preventDefault()}
Expand Down
22 changes: 22 additions & 0 deletions packages/react-ui/src/app/routes/flows/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Import,
Plus,
Trash2,
UploadCloud,
Workflow,
} from 'lucide-react';
import { useMemo, useState } from 'react';
Expand Down Expand Up @@ -46,6 +47,7 @@ import {
folderIdParamName,
} from '@/features/folders/component/folder-filter-list';
import { foldersApi } from '@/features/folders/lib/folders-api';
import { PushToGitDialog } from '@/features/git-sync/components/push-to-git-dialog';
import { gitSyncHooks } from '@/features/git-sync/lib/git-sync-hooks';
import { PieceIconList } from '@/features/pieces/components/piece-icon-list';
import { useAuthorization } from '@/hooks/authorization-hooks';
Expand Down Expand Up @@ -98,6 +100,7 @@ const FlowsPage = () => {
platform.environmentsEnabled,
);
const userHasPermissionToUpdateFlow = checkAccess(Permission.WRITE_FLOW);
const userHasPermissionToPushToGit = checkAccess(Permission.WRITE_GIT_REPO);
const isDevelopmentBranch =
gitSync && gitSync.branchType === GitBranchType.DEVELOPMENT;

Expand Down Expand Up @@ -396,6 +399,25 @@ const FlowsPage = () => {
) : null}

<DropdownMenuContent>
<PermissionNeededTooltip
hasPermission={userHasPermissionToPushToGit}
>
<PushToGitDialog
flowIds={selectedRows.map((flow) => flow.id)}
>
<DropdownMenuItem
disabled={!userHasPermissionToPushToGit}
onSelect={(e) => {
e.preventDefault();
}}
>
<div className="flex cursor-pointer flex-row gap-2 items-center">
<UploadCloud className="h-4 w-4" />
<span>{t('Push to Git')}</span>
</div>
</DropdownMenuItem>
</PushToGitDialog>
</PermissionNeededTooltip>
{!embedState.hideFolders && (
<PermissionNeededTooltip
hasPermission={userHasPermissionToUpdateFlow}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import { gitSyncApi } from '../lib/git-sync-api';
import { gitSyncHooks } from '../lib/git-sync-hooks';

type PushToGitDialogProps = {
flowId: string;
flowIds: string[];
children?: React.ReactNode;
};

const PushToGitDialog = ({ children, flowId }: PushToGitDialogProps) => {
const PushToGitDialog = ({ children, flowIds }: PushToGitDialogProps) => {
const [open, setOpen] = React.useState(false);

const { platform } = platformHooks.useCurrentPlatform();
Expand All @@ -52,15 +52,15 @@ const PushToGitDialog = ({ children, flowId }: PushToGitDialogProps) => {
defaultValues: {
type: GitPushOperationType.PUSH_FLOW,
commitMessage: '',
flowId: '',
flowIds: [],
},
resolver: typeboxResolver(PushGitRepoRequest),
});

const { mutate, isPending } = useMutation({
mutationFn: async (request: PushGitRepoRequest) => {
assertNotNullOrUndefined(gitSync, 'gitSync');
await gitSyncApi.push(gitSync.id, { ...request, flowId });
await gitSyncApi.push(gitSync.id, { ...request, flowIds });
},
onSuccess: () => {
toast({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const gitRepoService = (_log: FastifyBaseLogger) => ({
request: {
type: GitPushOperationType.DELETE_FLOW,
commitMessage: `chore: deleted flow ${flowId}`,
flowId,
flowIds: [flowId],
},
log,
})
Expand All @@ -99,20 +99,22 @@ export const gitRepoService = (_log: FastifyBaseLogger) => ({
const { git, flowFolderPath } = await gitHelper.createGitRepoAndReturnPaths(gitRepo, userId)
switch (request.type) {
case GitPushOperationType.PUSH_FLOW: {
const flow = await flowService(log).getOnePopulatedOrThrow({
id: request.flowId,
projectId: gitRepo.projectId,
removeConnectionsName: false,
removeSampleData: true,
})
const flowName = request.flowId
await gitSyncHelper(log).upsertFlowToGit(flowName, flow, flowFolderPath)
await gitHelper.commitAndPush(git, gitRepo, request.commitMessage ?? `chore: updated flow ${flow.id}`)
for (const flowId of request.flowIds) {
const flow = await flowService(log).getOnePopulatedOrThrow({
id: flowId,
projectId: gitRepo.projectId,
removeConnectionsName: false,
removeSampleData: true,
})
const flowName = flowId
await gitSyncHelper(log).upsertFlowToGit(flowName, flow, flowFolderPath)
}
await gitHelper.commitAndPush(git, gitRepo, request.commitMessage ?? `chore: updated flows ${request.flowIds.join(', ')}`)
break
}
case GitPushOperationType.DELETE_FLOW: {
const flow = await flowService(log).getOnePopulatedOrThrow({
id: request.flowId,
id: request.flowIds[0],
projectId: gitRepo.projectId,
})
const externalId = flow.externalId
Expand All @@ -121,7 +123,7 @@ export const gitRepoService = (_log: FastifyBaseLogger) => ({
}
const deleted = await gitSyncHelper(log).deleteFlowFromGit(externalId, flowFolderPath)
if (deleted) {
await gitHelper.commitAndPush(git, gitRepo, request.commitMessage ?? `chore: deleted flow ${request.flowId} from user interface`)
await gitHelper.commitAndPush(git, gitRepo, request.commitMessage ?? `chore: deleted flow ${request.flowIds[0]} from user interface`)
}
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const projectStateHelper = (log: FastifyBaseLogger) => ({
displayName: flow.version.displayName,
projectId,
},
externalId: flow.id,
})
return this.updateFlowInProject(createdFlow, flow, projectId)
},
Expand Down

0 comments on commit 67daa4b

Please sign in to comment.