## Description Removing the bulk delete applications feature as it not generally used by many users and this was creating some UI conflicts rather than giving us some valuable output. Please follow this thread for more context : https://theappsmith.slack.com/archives/C02Q4B2AGM8/p1706249168968689 #### PR fixes following issue(s) Fixes #30660 > if no issue exists, please create an issue and ask the maintainers about this first > > #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] JUnit - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Streamlined the application deletion process to handle multiple deletions more efficiently. - **Bug Fixes** - Removed redundant code and unused features related to the multiple selection and deletion of applications. - **Chores** - Cleaned up various files by removing unused imports, constants, and state variables. - **Documentation** - Adjusted code comments and documentation to reflect removal of multiple application deletion features and related UI elements. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
517 lines
15 KiB
TypeScript
517 lines
15 KiB
TypeScript
import React, {
|
|
useEffect,
|
|
useState,
|
|
useContext,
|
|
useCallback,
|
|
useMemo,
|
|
} from "react";
|
|
import styled, { ThemeContext } from "styled-components";
|
|
import type { ApplicationPayload } from "@appsmith/constants/ReduxActionConstants";
|
|
import {
|
|
hasDeleteApplicationPermission,
|
|
isPermitted,
|
|
PERMISSION_TYPE,
|
|
} from "@appsmith/utils/permissionHelpers";
|
|
import {
|
|
getInitialsAndColorCode,
|
|
getApplicationIcon,
|
|
getRandomPaletteColor,
|
|
} from "utils/AppsmithUtils";
|
|
import type { AppIconName } from "design-system-old";
|
|
import {
|
|
ColorSelector,
|
|
EditableText,
|
|
EditInteractionKind,
|
|
IconSelector,
|
|
SavingState,
|
|
} from "design-system-old";
|
|
import type { MenuItemProps } from "design-system";
|
|
import {
|
|
Button,
|
|
Menu,
|
|
Divider,
|
|
MenuContent,
|
|
MenuItem,
|
|
MenuTrigger,
|
|
} from "design-system";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
import type {
|
|
ApplicationPagePayload,
|
|
UpdateApplicationPayload,
|
|
} from "@appsmith/api/ApplicationApi";
|
|
import {
|
|
getIsSavingAppName,
|
|
getIsErroredSavingAppName,
|
|
} from "@appsmith/selectors/applicationSelectors";
|
|
import ForkApplicationModal from "./ForkApplicationModal";
|
|
import { getExportAppAPIRoute } from "@appsmith/constants/ApiConstants";
|
|
import { builderURL, viewerURL } from "@appsmith/RouteBuilder";
|
|
import history from "utils/history";
|
|
import urlBuilder from "@appsmith/entities/URLRedirect/URLAssembly";
|
|
import { toast } from "design-system";
|
|
import { getAppsmithConfigs } from "@appsmith/configs";
|
|
import { addItemsInContextMenu } from "@appsmith/utils";
|
|
import { getCurrentUser } from "actions/authActions";
|
|
import Card, { ContextMenuTrigger } from "components/common/Card";
|
|
import { generateEditedByText } from "./helpers";
|
|
import { noop } from "lodash";
|
|
|
|
const { cloudHosting } = getAppsmithConfigs();
|
|
|
|
interface ApplicationCardProps {
|
|
application: ApplicationPayload;
|
|
share?: (applicationId: string) => void;
|
|
delete?: (applicationId: string) => void;
|
|
update?: (id: string, data: UpdateApplicationPayload) => void;
|
|
enableImportExport?: boolean;
|
|
isMobile?: boolean;
|
|
isFetchingApplications: boolean;
|
|
permissions?: {
|
|
hasCreateNewApplicationPermission?: boolean;
|
|
hasManageWorkspacePermissions?: boolean;
|
|
canInviteToWorkspace?: boolean;
|
|
};
|
|
workspaceId: string;
|
|
}
|
|
|
|
const IconScrollWrapper = styled.div`
|
|
position: relative;
|
|
.t--icon-selected {
|
|
background-color: var(--ads-v2-color-bg-muted);
|
|
border: var(--ads-v2-border-color);
|
|
svg {
|
|
path {
|
|
fill: var(--ads-v2-color-fg);
|
|
}
|
|
}
|
|
}
|
|
svg {
|
|
path {
|
|
fill: var(--ads-v2-color-fg);
|
|
}
|
|
}
|
|
`;
|
|
|
|
export interface ModifiedMenuItemProps extends MenuItemProps {
|
|
key?: string;
|
|
"data-testid"?: string;
|
|
}
|
|
|
|
export function ApplicationCard(props: ApplicationCardProps) {
|
|
const { isFetchingApplications } = props;
|
|
const theme = useContext(ThemeContext);
|
|
const isSavingName = useSelector(getIsSavingAppName);
|
|
const isErroredSavingName = useSelector(getIsErroredSavingAppName);
|
|
const initialsAndColorCode = getInitialsAndColorCode(
|
|
props.application.name,
|
|
theme.colors.appCardColors,
|
|
);
|
|
let initials = initialsAndColorCode[0];
|
|
const [showOverlay, setShowOverlay] = useState(false);
|
|
const [selectedColor, setSelectedColor] = useState<string>("");
|
|
const [moreActionItems, setMoreActionItems] = useState<
|
|
ModifiedMenuItemProps[]
|
|
>([]);
|
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
|
const [isDeleting, setIsDeleting] = useState(false);
|
|
const [isForkApplicationModalopen, setForkApplicationModalOpen] =
|
|
useState(false);
|
|
const [lastUpdatedValue, setLastUpdatedValue] = useState("");
|
|
const dispatch = useDispatch();
|
|
|
|
const applicationId = props.application?.id;
|
|
const showGitBadge = props.application?.gitApplicationMetadata?.branchName;
|
|
|
|
useEffect(() => {
|
|
let colorCode;
|
|
if (props.application.color) {
|
|
colorCode = props.application.color;
|
|
} else {
|
|
colorCode = getRandomPaletteColor(theme.colors.appCardColors);
|
|
}
|
|
setSelectedColor(colorCode);
|
|
}, [props.application.color]);
|
|
|
|
useEffect(() => {
|
|
if (props.share) {
|
|
moreActionItems.push({
|
|
onSelect: shareApp,
|
|
children: "Share",
|
|
key: "share",
|
|
startIcon: "share",
|
|
"data-testid": "t--share",
|
|
});
|
|
}
|
|
// add fork app option to menu
|
|
if (hasEditPermission) {
|
|
moreActionItems.push({
|
|
onSelect: forkApplicationInitiate,
|
|
children: "Fork",
|
|
key: "fork",
|
|
startIcon: "fork-2",
|
|
"data-testid": "t--fork-app",
|
|
});
|
|
}
|
|
if (!!props.enableImportExport && hasExportPermission) {
|
|
moreActionItems.push({
|
|
onSelect: exportApplicationAsJSONFile,
|
|
children: "Export",
|
|
key: "export",
|
|
startIcon: "download",
|
|
"data-testid": "t--export-app",
|
|
});
|
|
}
|
|
const updatedMoreActionItems: ModifiedMenuItemProps[] =
|
|
addItemsInContextMenu(
|
|
[
|
|
props.permissions?.hasManageWorkspacePermissions || false,
|
|
props.permissions?.canInviteToWorkspace || false,
|
|
!cloudHosting,
|
|
],
|
|
history,
|
|
props.workspaceId,
|
|
moreActionItems,
|
|
);
|
|
setMoreActionItems(updatedMoreActionItems);
|
|
addDeleteOption();
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
const appIcon = (props.application?.icon ||
|
|
getApplicationIcon(applicationId)) as AppIconName;
|
|
const hasEditPermission = isPermitted(
|
|
props.application?.userPermissions ?? [],
|
|
PERMISSION_TYPE.MANAGE_APPLICATION,
|
|
);
|
|
const hasReadPermission = isPermitted(
|
|
props.application?.userPermissions ?? [],
|
|
PERMISSION_TYPE.READ_APPLICATION,
|
|
);
|
|
const hasExportPermission = isPermitted(
|
|
props.application?.userPermissions ?? [],
|
|
PERMISSION_TYPE.EXPORT_APPLICATION,
|
|
);
|
|
const hasDeletePermission = hasDeleteApplicationPermission(
|
|
props.application?.userPermissions,
|
|
);
|
|
|
|
const updateColor = (color: string) => {
|
|
props.update &&
|
|
props.update(applicationId, {
|
|
color: color,
|
|
});
|
|
};
|
|
const updateIcon = (icon: AppIconName) => {
|
|
props.update &&
|
|
props.update(applicationId, {
|
|
icon: icon,
|
|
});
|
|
};
|
|
const shareApp = () => {
|
|
props.share && props.share(applicationId);
|
|
};
|
|
const exportApplicationAsJSONFile = () => {
|
|
// export api response comes with content-disposition header.
|
|
// there is no straightforward way to handle it with axios/fetch
|
|
const id = `t--export-app-link`;
|
|
const existingLink = document.getElementById(id);
|
|
existingLink && existingLink.remove();
|
|
const link = document.createElement("a");
|
|
|
|
const branchName = props.application.gitApplicationMetadata?.branchName;
|
|
link.href = getExportAppAPIRoute(applicationId, branchName);
|
|
link.id = id;
|
|
document.body.appendChild(link);
|
|
// @ts-expect-error: Types are not available
|
|
if (!window.Cypress) {
|
|
link.click();
|
|
}
|
|
setIsMenuOpen(false);
|
|
toast.show(`Successfully exported ${props.application.name}`, {
|
|
kind: "success",
|
|
});
|
|
};
|
|
const forkApplicationInitiate = () => {
|
|
// open fork application modal
|
|
// on click on an workspace, create app and take to app
|
|
setForkApplicationModalOpen(true);
|
|
};
|
|
const deleteApp = () => {
|
|
setShowOverlay(false);
|
|
props.delete && props.delete(applicationId);
|
|
};
|
|
const askForConfirmation = () => {
|
|
setIsDeleting(true);
|
|
const updatedActionItems = [...moreActionItems];
|
|
updatedActionItems.pop();
|
|
updatedActionItems.push({
|
|
onSelect: deleteApp,
|
|
children: "Are you sure?",
|
|
key: "areyousure",
|
|
startIcon: "delete-bin-line",
|
|
"data-testid": "t--delete",
|
|
});
|
|
setMoreActionItems(updatedActionItems);
|
|
};
|
|
const addDeleteOption = () => {
|
|
if (props.delete && hasDeletePermission) {
|
|
const index = moreActionItems.findIndex(
|
|
(el) => el.startIcon === "delete-bin-line",
|
|
);
|
|
if (index >= 0) {
|
|
moreActionItems.pop();
|
|
}
|
|
moreActionItems.push({
|
|
onSelect: askForConfirmation,
|
|
children: "Delete",
|
|
key: "delete",
|
|
startIcon: "delete-bin-line",
|
|
"data-testid": "t--delete-confirm",
|
|
});
|
|
setMoreActionItems(moreActionItems);
|
|
}
|
|
};
|
|
|
|
if (initials.length < 2 && props.application.name.length > 1) {
|
|
initials += props.application.name[1].toUpperCase() || "";
|
|
}
|
|
|
|
// should show correct branch of application when edit mode
|
|
const params: any = {};
|
|
if (showGitBadge) {
|
|
params.branch = showGitBadge;
|
|
}
|
|
|
|
const handleMenuOnClose = (open: boolean) => {
|
|
if (!open && !isDeleting) {
|
|
setIsMenuOpen(false);
|
|
setShowOverlay(false);
|
|
addDeleteOption();
|
|
if (lastUpdatedValue && props.application.name !== lastUpdatedValue) {
|
|
props.update &&
|
|
props.update(applicationId, {
|
|
name: lastUpdatedValue,
|
|
});
|
|
}
|
|
} else {
|
|
setIsMenuOpen(true);
|
|
setIsDeleting(false);
|
|
}
|
|
};
|
|
|
|
const contextMenu = (
|
|
<>
|
|
<Menu className="more" onOpenChange={handleMenuOnClose} open={isMenuOpen}>
|
|
<MenuTrigger>
|
|
<ContextMenuTrigger
|
|
className="m-0.5"
|
|
data-testid="t--application-card-context-menu"
|
|
isIconButton
|
|
kind="tertiary"
|
|
size="sm"
|
|
startIcon="context-menu"
|
|
/>
|
|
</MenuTrigger>
|
|
<MenuContent side="right" style={{ maxHeight: "unset" }}>
|
|
{hasEditPermission && (
|
|
<div
|
|
onKeyDown={(e) => {
|
|
// This is to prevent the Menu component to take focus away from the input
|
|
// https://github.com/radix-ui/primitives/issues/1175
|
|
e.stopPropagation();
|
|
}}
|
|
>
|
|
<EditableText
|
|
className="px-3 pt-2 pb-2 t--application-name"
|
|
defaultValue={props.application.name}
|
|
editInteractionKind={EditInteractionKind.SINGLE}
|
|
fill
|
|
hideEditIcon={false}
|
|
isError={isErroredSavingName}
|
|
isInvalid={(value: string) => {
|
|
if (!value) {
|
|
return "Name cannot be empty";
|
|
} else {
|
|
return false;
|
|
}
|
|
}}
|
|
onBlur={(value: string) => {
|
|
props.update &&
|
|
props.update(applicationId, {
|
|
name: value,
|
|
});
|
|
}}
|
|
onTextChanged={(value: string) => {
|
|
setLastUpdatedValue(value);
|
|
}}
|
|
placeholder={"Edit text input"}
|
|
savingState={
|
|
isSavingName ? SavingState.STARTED : SavingState.NOT_STARTED
|
|
}
|
|
underline
|
|
/>
|
|
</div>
|
|
)}
|
|
{hasEditPermission && (
|
|
<>
|
|
<ColorSelector
|
|
colorPalette={theme.colors.appCardColors}
|
|
defaultValue={selectedColor}
|
|
fill
|
|
onSelect={updateColor}
|
|
/>
|
|
<Divider />
|
|
</>
|
|
)}
|
|
{hasEditPermission && (
|
|
<IconScrollWrapper>
|
|
<IconSelector
|
|
className="icon-selector"
|
|
fill
|
|
onSelect={updateIcon}
|
|
selectedColor={theme.colors.applications.cardMenuIcon}
|
|
selectedIcon={appIcon}
|
|
/>
|
|
<Divider />
|
|
</IconScrollWrapper>
|
|
)}
|
|
<div className="menu-items-wrapper">
|
|
{moreActionItems.map((item: MenuItemProps) => {
|
|
const { children, key, ...restMenuItem } = item;
|
|
return (
|
|
<MenuItem
|
|
{...restMenuItem}
|
|
className={
|
|
item.startIcon === "delete-bin-line" ? "error-menuitem" : ""
|
|
}
|
|
key={key}
|
|
>
|
|
{children}
|
|
</MenuItem>
|
|
);
|
|
})}
|
|
</div>
|
|
</MenuContent>
|
|
</Menu>
|
|
<ForkApplicationModal
|
|
applicationId={applicationId}
|
|
handleClose={() => {
|
|
setForkApplicationModalOpen(false);
|
|
}}
|
|
isModalOpen={isForkApplicationModalopen}
|
|
/>
|
|
</>
|
|
);
|
|
|
|
const editedByText = generateEditedByText({
|
|
modifiedAt: props.application.modifiedAt,
|
|
modifiedBy: props.application.modifiedBy,
|
|
});
|
|
|
|
function setURLParams() {
|
|
const page: ApplicationPagePayload | undefined =
|
|
props.application.pages.find(
|
|
(page) => page.id === props.application.defaultPageId,
|
|
);
|
|
if (!page) return;
|
|
urlBuilder.updateURLParams(
|
|
{
|
|
applicationSlug: props.application.slug,
|
|
applicationVersion: props.application.applicationVersion,
|
|
applicationId: props.application.id,
|
|
},
|
|
props.application.pages.map((page) => ({
|
|
pageSlug: page.slug,
|
|
customSlug: page.customSlug,
|
|
pageId: page.id,
|
|
})),
|
|
);
|
|
}
|
|
|
|
const editModeURL = useMemo(() => {
|
|
if (!props.application.defaultPageId) return "";
|
|
return builderURL({
|
|
pageId: props.application.defaultPageId,
|
|
params,
|
|
});
|
|
}, [props.application.defaultPageId, params]);
|
|
|
|
const viewModeURL = useMemo(() => {
|
|
if (!props.application.defaultPageId) return "";
|
|
return viewerURL({
|
|
pageId: props.application.defaultPageId,
|
|
params,
|
|
});
|
|
}, [props.application.defaultPageId, params]);
|
|
|
|
const launchApp = useCallback(() => {
|
|
setURLParams();
|
|
history.push(
|
|
viewerURL({
|
|
pageId: props.application.defaultPageId,
|
|
params,
|
|
}),
|
|
);
|
|
dispatch(getCurrentUser());
|
|
}, [props.application.defaultPageId]);
|
|
|
|
const editApp = useCallback(() => {
|
|
setURLParams();
|
|
history.push(
|
|
builderURL({
|
|
pageId: props.application.defaultPageId,
|
|
params,
|
|
}),
|
|
);
|
|
dispatch(getCurrentUser());
|
|
}, [props.application.defaultPageId]);
|
|
|
|
return (
|
|
<Card
|
|
backgroundColor={selectedColor}
|
|
contextMenu={contextMenu}
|
|
editedByText={editedByText}
|
|
hasEditPermission={hasEditPermission}
|
|
hasReadPermission={hasReadPermission}
|
|
icon={appIcon}
|
|
isContextMenuOpen={isMenuOpen}
|
|
isFetching={isFetchingApplications}
|
|
isMobile={props.isMobile}
|
|
moreActionItems={moreActionItems}
|
|
primaryAction={props.isMobile ? launchApp : noop}
|
|
setShowOverlay={setShowOverlay}
|
|
showGitBadge={Boolean(showGitBadge)}
|
|
showOverlay={showOverlay}
|
|
testId={`t--application-card ${props.application.name}`}
|
|
title={props.application.name}
|
|
titleTestId="t--app-card-name"
|
|
>
|
|
{hasEditPermission && !isMenuOpen && (
|
|
<Button
|
|
className="t--application-edit-link"
|
|
href={editModeURL}
|
|
onClick={editApp}
|
|
size="md"
|
|
startIcon={"pencil-line"}
|
|
>
|
|
Edit
|
|
</Button>
|
|
)}
|
|
{!isMenuOpen && (
|
|
<Button
|
|
className="t--application-view-link"
|
|
href={viewModeURL}
|
|
kind="secondary"
|
|
onClick={launchApp}
|
|
size="md"
|
|
startIcon={"rocket"}
|
|
>
|
|
Launch
|
|
</Button>
|
|
)}
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
export default ApplicationCard;
|