2022-03-10 02:22:07 +00:00
|
|
|
import React, {
|
|
|
|
|
useEffect,
|
|
|
|
|
useState,
|
|
|
|
|
useContext,
|
|
|
|
|
useCallback,
|
2022-07-14 07:04:19 +00:00
|
|
|
useMemo,
|
2022-03-10 02:22:07 +00:00
|
|
|
} from "react";
|
2021-02-11 12:54:00 +00:00
|
|
|
import styled, { ThemeContext } from "styled-components";
|
2024-08-06 14:52:22 +00:00
|
|
|
import type { ApplicationPayload } from "ee/constants/ReduxActionConstants";
|
2020-05-27 13:36:06 +00:00
|
|
|
import {
|
2022-12-01 06:30:50 +00:00
|
|
|
hasDeleteApplicationPermission,
|
2020-05-27 13:36:06 +00:00
|
|
|
isPermitted,
|
|
|
|
|
PERMISSION_TYPE,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/utils/permissionHelpers";
|
2020-09-16 11:50:47 +00:00
|
|
|
import {
|
|
|
|
|
getInitialsAndColorCode,
|
|
|
|
|
getApplicationIcon,
|
2020-12-07 06:51:13 +00:00
|
|
|
getRandomPaletteColor,
|
2020-09-16 11:50:47 +00:00
|
|
|
} from "utils/AppsmithUtils";
|
2024-08-08 12:55:00 +00:00
|
|
|
import type { AppIconName } from "@appsmith/ads-old";
|
2022-08-22 05:09:39 +00:00
|
|
|
import {
|
feat: import changes batch 2 (#15722)
* Remove treedropdown from ads
* Change Treedropdown imports
* Remove Notification Banner, change imports
* Remove Toggle from ads
* Change toggle imports
* explicitly declare function argument types
* Remove Menu from ads
* Change menu imports
* Remove Spinner from ads
* Change spinner imports
* Remove Radio, import changes
* test: updated flaky test under default meta (#15707)
* updated flaky test
* Updated tests
* updated tests
* updated the tests
* updated tests
* Update constants.ts
* add more typecasting
* Remove ListSegmentHeader, import changes
* Remove TagInputComponent, import changes
* Remove Switch, import changes
* Remove SearchInput, change imports
* Rename TagInputComponent to TagInput
* Remove ProgressiveImage, import changes
* import changes for SearchVariant
* Remove menu divider, import changes
* Remove TableDropdown, import changes
* Remove Switcher
* Remove StatusBar, import changes
* Remove showcase carousel
* Remove RectangularSwitcher, import change
* Add types to TableDropdown's args
* Remove MultiSwitch, import change
* Remove GifPlayerComponent, import change
* Remove DraggableList, import change
* Remove DisplayImageUpload, import change
* Remove DatePickerComponent, import change
* Remove CopyToClipBoard, import change
* Remove ColorSelector, import change
* Remove TabItemBackgroundFill, NumberedStep, ColorPickerComponent
* GifPlayerComponent -> GifPlayer
* change named import
* Remove FormFieldError, change imports
* Update to new version of Tree Dropdown
* Fix issue with ads/index.ts
* Test file fix
* Fix issue with merge?!?!??
* update design system to 1.0.18
* Bump ds version
* bump ds version
* bump ds version
Co-authored-by: NandanAnantharamu <67676905+NandanAnantharamu@users.noreply.github.com>
Co-authored-by: Albin <albin@appsmith.com>
2022-09-02 08:38:17 +00:00
|
|
|
ColorSelector,
|
2022-10-13 20:13:44 +00:00
|
|
|
EditableText,
|
|
|
|
|
EditInteractionKind,
|
2022-08-22 05:09:39 +00:00
|
|
|
IconSelector,
|
2022-10-13 20:13:44 +00:00
|
|
|
SavingState,
|
2024-08-08 12:55:00 +00:00
|
|
|
} from "@appsmith/ads-old";
|
2024-08-09 14:20:29 +00:00
|
|
|
import type { MenuItemProps } from "@appsmith/ads";
|
2023-05-19 18:37:06 +00:00
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
Menu,
|
|
|
|
|
Divider,
|
|
|
|
|
MenuContent,
|
|
|
|
|
MenuItem,
|
|
|
|
|
MenuTrigger,
|
2024-08-09 14:20:29 +00:00
|
|
|
} from "@appsmith/ads";
|
2023-06-02 11:06:41 +00:00
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### 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
- [x] 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
- [x] 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:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type {
|
2022-07-11 04:06:29 +00:00
|
|
|
ApplicationPagePayload,
|
|
|
|
|
UpdateApplicationPayload,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/api/ApplicationApi";
|
2020-10-14 10:35:19 +00:00
|
|
|
import {
|
|
|
|
|
getIsSavingAppName,
|
2021-06-24 06:32:09 +00:00
|
|
|
getIsErroredSavingAppName,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/selectors/applicationSelectors";
|
2021-05-04 06:04:23 +00:00
|
|
|
import ForkApplicationModal from "./ForkApplicationModal";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { getExportAppAPIRoute } from "ee/constants/ApiConstants";
|
|
|
|
|
import { builderURL, viewerURL } from "ee/RouteBuilder";
|
2024-03-27 10:34:41 +00:00
|
|
|
import history from "utils/history";
|
2024-08-06 14:52:22 +00:00
|
|
|
import urlBuilder from "ee/entities/URLRedirect/URLAssembly";
|
2024-08-09 14:20:29 +00:00
|
|
|
import { toast } from "@appsmith/ads";
|
2023-06-02 11:06:41 +00:00
|
|
|
import { getCurrentUser } from "actions/authActions";
|
2024-01-22 11:52:01 +00:00
|
|
|
import Card, { ContextMenuTrigger } from "components/common/Card";
|
2023-08-31 08:21:04 +00:00
|
|
|
import { generateEditedByText } from "./helpers";
|
2024-01-22 11:52:01 +00:00
|
|
|
import { noop } from "lodash";
|
2023-03-29 17:07:06 +00:00
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
interface ApplicationCardProps {
|
2019-11-21 10:52:49 +00:00
|
|
|
application: ApplicationPayload;
|
2020-01-27 08:24:58 +00:00
|
|
|
share?: (applicationId: string) => void;
|
2020-11-25 12:24:14 +00:00
|
|
|
delete?: (applicationId: string) => void;
|
2020-09-16 11:50:47 +00:00
|
|
|
update?: (id: string, data: UpdateApplicationPayload) => void;
|
2021-06-03 06:18:08 +00:00
|
|
|
enableImportExport?: boolean;
|
2022-02-17 16:38:36 +00:00
|
|
|
isMobile?: boolean;
|
2023-08-31 08:21:04 +00:00
|
|
|
isFetchingApplications: boolean;
|
2023-03-29 17:07:06 +00:00
|
|
|
permissions?: {
|
|
|
|
|
hasCreateNewApplicationPermission?: boolean;
|
|
|
|
|
hasManageWorkspacePermissions?: boolean;
|
|
|
|
|
canInviteToWorkspace?: boolean;
|
|
|
|
|
};
|
|
|
|
|
workspaceId: string;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2019-11-21 10:52:49 +00:00
|
|
|
|
2021-10-04 15:34:37 +00:00
|
|
|
const IconScrollWrapper = styled.div`
|
|
|
|
|
position: relative;
|
|
|
|
|
.t--icon-selected {
|
2023-05-19 18:37:06 +00:00
|
|
|
background-color: var(--ads-v2-color-bg-muted);
|
|
|
|
|
border: var(--ads-v2-border-color);
|
2021-10-04 15:34:37 +00:00
|
|
|
svg {
|
|
|
|
|
path {
|
2023-05-19 18:37:06 +00:00
|
|
|
fill: var(--ads-v2-color-fg);
|
2020-09-23 14:06:50 +00:00
|
|
|
}
|
2020-09-16 11:50:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-05-19 18:37:06 +00:00
|
|
|
svg {
|
|
|
|
|
path {
|
|
|
|
|
fill: var(--ads-v2-color-fg);
|
2021-10-04 15:34:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-16 11:50:47 +00:00
|
|
|
`;
|
|
|
|
|
|
2023-10-16 09:07:39 +00:00
|
|
|
export interface ModifiedMenuItemProps extends MenuItemProps {
|
2023-05-19 18:37:06 +00:00
|
|
|
key?: string;
|
|
|
|
|
"data-testid"?: string;
|
2023-10-16 09:07:39 +00:00
|
|
|
}
|
2023-05-19 18:37:06 +00:00
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
export function ApplicationCard(props: ApplicationCardProps) {
|
2023-08-31 08:21:04 +00:00
|
|
|
const { isFetchingApplications } = props;
|
2021-02-11 12:54:00 +00:00
|
|
|
const theme = useContext(ThemeContext);
|
2020-10-14 10:35:19 +00:00
|
|
|
const isSavingName = useSelector(getIsSavingAppName);
|
2021-06-24 06:32:09 +00:00
|
|
|
const isErroredSavingName = useSelector(getIsErroredSavingAppName);
|
2020-09-16 11:50:47 +00:00
|
|
|
const initialsAndColorCode = getInitialsAndColorCode(
|
|
|
|
|
props.application.name,
|
2021-02-11 12:54:00 +00:00
|
|
|
theme.colors.appCardColors,
|
2020-09-16 11:50:47 +00:00
|
|
|
);
|
|
|
|
|
let initials = initialsAndColorCode[0];
|
2020-10-14 10:35:19 +00:00
|
|
|
const [showOverlay, setShowOverlay] = useState(false);
|
2020-12-07 06:51:13 +00:00
|
|
|
const [selectedColor, setSelectedColor] = useState<string>("");
|
2023-05-19 18:37:06 +00:00
|
|
|
const [moreActionItems, setMoreActionItems] = useState<
|
|
|
|
|
ModifiedMenuItemProps[]
|
|
|
|
|
>([]);
|
2020-10-14 10:35:19 +00:00
|
|
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
2023-05-19 18:37:06 +00:00
|
|
|
const [isDeleting, setIsDeleting] = useState(false);
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### 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
- [x] 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
- [x] 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:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
const [isForkApplicationModalopen, setForkApplicationModalOpen] =
|
|
|
|
|
useState(false);
|
2020-10-14 10:35:19 +00:00
|
|
|
const [lastUpdatedValue, setLastUpdatedValue] = useState("");
|
2023-06-02 11:06:41 +00:00
|
|
|
const dispatch = useDispatch();
|
2020-10-14 10:35:19 +00:00
|
|
|
|
2021-10-18 14:03:44 +00:00
|
|
|
const applicationId = props.application?.id;
|
2022-02-08 16:16:16 +00:00
|
|
|
const showGitBadge = props.application?.gitApplicationMetadata?.branchName;
|
2021-10-18 14:03:44 +00:00
|
|
|
|
2020-10-14 10:35:19 +00:00
|
|
|
useEffect(() => {
|
2020-12-07 06:51:13 +00:00
|
|
|
let colorCode;
|
|
|
|
|
if (props.application.color) {
|
|
|
|
|
colorCode = props.application.color;
|
|
|
|
|
} else {
|
2021-02-11 12:54:00 +00:00
|
|
|
colorCode = getRandomPaletteColor(theme.colors.appCardColors);
|
2020-12-07 06:51:13 +00:00
|
|
|
}
|
2020-10-14 10:35:19 +00:00
|
|
|
setSelectedColor(colorCode);
|
2020-12-09 07:06:02 +00:00
|
|
|
}, [props.application.color]);
|
2021-10-04 15:34:37 +00:00
|
|
|
|
2020-10-14 10:35:19 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (props.share) {
|
|
|
|
|
moreActionItems.push({
|
|
|
|
|
onSelect: shareApp,
|
2023-05-19 18:37:06 +00:00
|
|
|
children: "Share",
|
|
|
|
|
key: "share",
|
|
|
|
|
startIcon: "share",
|
|
|
|
|
"data-testid": "t--share",
|
2020-10-14 10:35:19 +00:00
|
|
|
});
|
|
|
|
|
}
|
2021-05-04 06:04:23 +00:00
|
|
|
// add fork app option to menu
|
|
|
|
|
if (hasEditPermission) {
|
|
|
|
|
moreActionItems.push({
|
|
|
|
|
onSelect: forkApplicationInitiate,
|
2023-05-19 18:37:06 +00:00
|
|
|
children: "Fork",
|
|
|
|
|
key: "fork",
|
|
|
|
|
startIcon: "fork-2",
|
|
|
|
|
"data-testid": "t--fork-app",
|
2021-05-04 06:04:23 +00:00
|
|
|
});
|
|
|
|
|
}
|
2021-06-15 12:48:21 +00:00
|
|
|
if (!!props.enableImportExport && hasExportPermission) {
|
2021-06-03 06:18:08 +00:00
|
|
|
moreActionItems.push({
|
|
|
|
|
onSelect: exportApplicationAsJSONFile,
|
2023-05-19 18:37:06 +00:00
|
|
|
children: "Export",
|
|
|
|
|
key: "export",
|
|
|
|
|
startIcon: "download",
|
|
|
|
|
"data-testid": "t--export-app",
|
2021-06-03 06:18:08 +00:00
|
|
|
});
|
|
|
|
|
}
|
2024-02-07 09:21:25 +00:00
|
|
|
setMoreActionItems(moreActionItems);
|
2020-10-14 10:35:19 +00:00
|
|
|
addDeleteOption();
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, []);
|
2020-08-18 06:40:11 +00:00
|
|
|
|
2020-10-14 10:35:19 +00:00
|
|
|
const appIcon = (props.application?.icon ||
|
2021-10-18 14:03:44 +00:00
|
|
|
getApplicationIcon(applicationId)) as AppIconName;
|
2020-05-27 13:36:06 +00:00
|
|
|
const hasEditPermission = isPermitted(
|
|
|
|
|
props.application?.userPermissions ?? [],
|
|
|
|
|
PERMISSION_TYPE.MANAGE_APPLICATION,
|
2020-05-14 10:47:13 +00:00
|
|
|
);
|
2020-05-27 13:36:06 +00:00
|
|
|
const hasReadPermission = isPermitted(
|
|
|
|
|
props.application?.userPermissions ?? [],
|
|
|
|
|
PERMISSION_TYPE.READ_APPLICATION,
|
2020-05-14 10:47:13 +00:00
|
|
|
);
|
2021-06-15 12:48:21 +00:00
|
|
|
const hasExportPermission = isPermitted(
|
|
|
|
|
props.application?.userPermissions ?? [],
|
|
|
|
|
PERMISSION_TYPE.EXPORT_APPLICATION,
|
|
|
|
|
);
|
2022-12-01 06:30:50 +00:00
|
|
|
const hasDeletePermission = hasDeleteApplicationPermission(
|
|
|
|
|
props.application?.userPermissions,
|
|
|
|
|
);
|
2022-12-01 21:26:21 +00:00
|
|
|
|
2020-09-16 11:50:47 +00:00
|
|
|
const updateColor = (color: string) => {
|
|
|
|
|
props.update &&
|
2021-10-18 14:03:44 +00:00
|
|
|
props.update(applicationId, {
|
2020-09-16 11:50:47 +00:00
|
|
|
color: color,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
const updateIcon = (icon: AppIconName) => {
|
|
|
|
|
props.update &&
|
2021-10-18 14:03:44 +00:00
|
|
|
props.update(applicationId, {
|
2020-09-16 11:50:47 +00:00
|
|
|
icon: icon,
|
|
|
|
|
});
|
|
|
|
|
};
|
2019-11-21 10:52:49 +00:00
|
|
|
const shareApp = () => {
|
2021-10-18 14:03:44 +00:00
|
|
|
props.share && props.share(applicationId);
|
2019-11-21 10:52:49 +00:00
|
|
|
};
|
2021-06-03 06:18:08 +00:00
|
|
|
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");
|
2021-08-27 07:19:21 +00:00
|
|
|
|
2023-08-17 10:48:04 +00:00
|
|
|
const branchName = props.application.gitApplicationMetadata?.branchName;
|
|
|
|
|
link.href = getExportAppAPIRoute(applicationId, branchName);
|
2021-06-03 06:18:08 +00:00
|
|
|
link.id = id;
|
|
|
|
|
document.body.appendChild(link);
|
2022-06-21 13:57:34 +00:00
|
|
|
// @ts-expect-error: Types are not available
|
2021-08-23 09:16:25 +00:00
|
|
|
if (!window.Cypress) {
|
|
|
|
|
link.click();
|
|
|
|
|
}
|
2021-06-03 06:18:08 +00:00
|
|
|
setIsMenuOpen(false);
|
2023-05-19 18:37:06 +00:00
|
|
|
toast.show(`Successfully exported ${props.application.name}`, {
|
|
|
|
|
kind: "success",
|
2021-06-03 06:18:08 +00:00
|
|
|
});
|
|
|
|
|
};
|
2021-05-04 06:04:23 +00:00
|
|
|
const forkApplicationInitiate = () => {
|
|
|
|
|
// open fork application modal
|
2022-06-15 15:37:41 +00:00
|
|
|
// on click on an workspace, create app and take to app
|
2021-05-04 06:04:23 +00:00
|
|
|
setForkApplicationModalOpen(true);
|
|
|
|
|
};
|
2019-11-21 10:52:49 +00:00
|
|
|
const deleteApp = () => {
|
2020-10-14 10:35:19 +00:00
|
|
|
setShowOverlay(false);
|
2021-10-18 14:03:44 +00:00
|
|
|
props.delete && props.delete(applicationId);
|
2019-11-21 10:52:49 +00:00
|
|
|
};
|
2020-10-14 10:35:19 +00:00
|
|
|
const askForConfirmation = () => {
|
2023-05-19 18:37:06 +00:00
|
|
|
setIsDeleting(true);
|
2020-10-14 10:35:19 +00:00
|
|
|
const updatedActionItems = [...moreActionItems];
|
|
|
|
|
updatedActionItems.pop();
|
|
|
|
|
updatedActionItems.push({
|
2019-11-21 10:52:49 +00:00
|
|
|
onSelect: deleteApp,
|
2023-05-19 18:37:06 +00:00
|
|
|
children: "Are you sure?",
|
|
|
|
|
key: "areyousure",
|
|
|
|
|
startIcon: "delete-bin-line",
|
|
|
|
|
"data-testid": "t--delete",
|
2020-01-27 08:24:58 +00:00
|
|
|
});
|
2020-10-14 10:35:19 +00:00
|
|
|
setMoreActionItems(updatedActionItems);
|
|
|
|
|
};
|
|
|
|
|
const addDeleteOption = () => {
|
2022-12-01 06:30:50 +00:00
|
|
|
if (props.delete && hasDeletePermission) {
|
2021-10-04 15:34:37 +00:00
|
|
|
const index = moreActionItems.findIndex(
|
2023-05-19 18:37:06 +00:00
|
|
|
(el) => el.startIcon === "delete-bin-line",
|
2021-10-04 15:34:37 +00:00
|
|
|
);
|
2020-10-14 10:35:19 +00:00
|
|
|
if (index >= 0) {
|
|
|
|
|
moreActionItems.pop();
|
|
|
|
|
}
|
|
|
|
|
moreActionItems.push({
|
|
|
|
|
onSelect: askForConfirmation,
|
2023-05-19 18:37:06 +00:00
|
|
|
children: "Delete",
|
|
|
|
|
key: "delete",
|
|
|
|
|
startIcon: "delete-bin-line",
|
|
|
|
|
"data-testid": "t--delete-confirm",
|
2020-10-14 10:35:19 +00:00
|
|
|
});
|
|
|
|
|
setMoreActionItems(moreActionItems);
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-05-19 18:37:06 +00:00
|
|
|
|
2020-10-14 10:35:19 +00:00
|
|
|
if (initials.length < 2 && props.application.name.length > 1) {
|
|
|
|
|
initials += props.application.name[1].toUpperCase() || "";
|
2020-01-27 08:24:58 +00:00
|
|
|
}
|
2021-10-18 14:03:44 +00:00
|
|
|
|
2022-04-22 06:36:49 +00:00
|
|
|
// should show correct branch of application when edit mode
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2022-04-22 06:36:49 +00:00
|
|
|
const params: any = {};
|
|
|
|
|
if (showGitBadge) {
|
|
|
|
|
params.branch = showGitBadge;
|
|
|
|
|
}
|
2021-10-18 14:03:44 +00:00
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-31 08:21:04 +00:00
|
|
|
const contextMenu = (
|
2023-05-19 18:37:06 +00:00
|
|
|
<>
|
|
|
|
|
<Menu className="more" onOpenChange={handleMenuOnClose} open={isMenuOpen}>
|
|
|
|
|
<MenuTrigger>
|
2023-09-13 10:09:34 +00:00
|
|
|
<ContextMenuTrigger
|
2023-05-19 18:37:06 +00:00
|
|
|
className="m-0.5"
|
2023-05-20 00:49:33 +00:00
|
|
|
data-testid="t--application-card-context-menu"
|
2023-05-19 18:37:06 +00:00
|
|
|
isIconButton
|
|
|
|
|
kind="tertiary"
|
|
|
|
|
size="sm"
|
|
|
|
|
startIcon="context-menu"
|
2020-09-16 11:50:47 +00:00
|
|
|
/>
|
2023-05-19 18:37:06 +00:00
|
|
|
</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>
|
2020-09-16 11:50:47 +00:00
|
|
|
</Menu>
|
2023-05-19 18:37:06 +00:00
|
|
|
<ForkApplicationModal
|
|
|
|
|
applicationId={applicationId}
|
2023-09-26 02:08:05 +00:00
|
|
|
handleClose={() => {
|
|
|
|
|
setForkApplicationModalOpen(false);
|
|
|
|
|
}}
|
2023-05-19 18:37:06 +00:00
|
|
|
isModalOpen={isForkApplicationModalopen}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2020-09-16 11:50:47 +00:00
|
|
|
);
|
2020-08-18 06:40:11 +00:00
|
|
|
|
2023-08-31 08:21:04 +00:00
|
|
|
const editedByText = generateEditedByText({
|
|
|
|
|
modifiedAt: props.application.modifiedAt,
|
|
|
|
|
modifiedBy: props.application.modifiedBy,
|
|
|
|
|
});
|
2021-10-04 15:34:37 +00:00
|
|
|
|
2022-07-11 04:06:29 +00:00
|
|
|
function setURLParams() {
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### 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
- [x] 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
- [x] 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:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
const page: ApplicationPagePayload | undefined =
|
|
|
|
|
props.application.pages.find(
|
|
|
|
|
(page) => page.id === props.application.defaultPageId,
|
|
|
|
|
);
|
2022-07-11 04:06:29 +00:00
|
|
|
if (!page) return;
|
|
|
|
|
urlBuilder.updateURLParams(
|
|
|
|
|
{
|
|
|
|
|
applicationSlug: props.application.slug,
|
|
|
|
|
applicationVersion: props.application.applicationVersion,
|
2024-07-31 02:54:51 +00:00
|
|
|
baseApplicationId: props.application.baseId,
|
2022-07-11 04:06:29 +00:00
|
|
|
},
|
|
|
|
|
props.application.pages.map((page) => ({
|
|
|
|
|
pageSlug: page.slug,
|
|
|
|
|
customSlug: page.customSlug,
|
2024-07-31 02:54:51 +00:00
|
|
|
basePageId: page.baseId,
|
2022-07-11 04:06:29 +00:00
|
|
|
})),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 07:04:19 +00:00
|
|
|
const editModeURL = useMemo(() => {
|
2024-07-31 02:54:51 +00:00
|
|
|
const basePageId = props.application.defaultBasePageId;
|
|
|
|
|
if (!basePageId) return "";
|
|
|
|
|
return builderURL({ basePageId, params });
|
|
|
|
|
}, [props.application.defaultBasePageId, params]);
|
2022-07-14 07:04:19 +00:00
|
|
|
|
|
|
|
|
const viewModeURL = useMemo(() => {
|
2024-07-31 02:54:51 +00:00
|
|
|
const basePageId = props.application.defaultBasePageId;
|
|
|
|
|
if (!basePageId) return "";
|
|
|
|
|
return viewerURL({ basePageId, params });
|
|
|
|
|
}, [props.application.defaultBasePageId, params]);
|
2022-07-14 07:04:19 +00:00
|
|
|
|
2023-09-14 10:44:23 +00:00
|
|
|
const launchApp = useCallback(() => {
|
|
|
|
|
setURLParams();
|
|
|
|
|
dispatch(getCurrentUser());
|
2024-03-21 10:07:13 +00:00
|
|
|
}, []);
|
2022-07-11 04:06:29 +00:00
|
|
|
|
2023-09-14 10:44:23 +00:00
|
|
|
const editApp = useCallback(() => {
|
|
|
|
|
setURLParams();
|
|
|
|
|
dispatch(getCurrentUser());
|
2024-03-21 10:07:13 +00:00
|
|
|
}, []);
|
2022-02-17 16:38:36 +00:00
|
|
|
|
2024-03-27 10:34:41 +00:00
|
|
|
const launchMobileApp = useCallback(() => {
|
|
|
|
|
setURLParams();
|
|
|
|
|
history.push(
|
|
|
|
|
viewerURL({
|
2024-07-31 02:54:51 +00:00
|
|
|
basePageId: props.application.defaultBasePageId,
|
2024-03-27 10:34:41 +00:00
|
|
|
params,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
dispatch(getCurrentUser());
|
|
|
|
|
}, [props.application.defaultPageId]);
|
|
|
|
|
|
2019-11-21 10:52:49 +00:00
|
|
|
return (
|
2023-08-31 08:21:04 +00:00
|
|
|
<Card
|
|
|
|
|
backgroundColor={selectedColor}
|
|
|
|
|
contextMenu={contextMenu}
|
|
|
|
|
editedByText={editedByText}
|
2024-01-25 13:41:48 +00:00
|
|
|
hasEditPermission={hasEditPermission}
|
2023-08-31 08:21:04 +00:00
|
|
|
hasReadPermission={hasReadPermission}
|
|
|
|
|
icon={appIcon}
|
|
|
|
|
isContextMenuOpen={isMenuOpen}
|
|
|
|
|
isFetching={isFetchingApplications}
|
2022-02-17 16:38:36 +00:00
|
|
|
isMobile={props.isMobile}
|
2023-08-31 08:21:04 +00:00
|
|
|
moreActionItems={moreActionItems}
|
2024-03-27 10:34:41 +00:00
|
|
|
primaryAction={props.isMobile ? launchMobileApp : noop}
|
2023-08-31 08:21:04 +00:00
|
|
|
setShowOverlay={setShowOverlay}
|
|
|
|
|
showGitBadge={Boolean(showGitBadge)}
|
2024-01-29 14:21:01 +00:00
|
|
|
showOverlay={showOverlay}
|
2024-01-25 13:41:48 +00:00
|
|
|
testId={`t--application-card ${props.application.name}`}
|
2023-08-31 08:21:04 +00:00
|
|
|
title={props.application.name}
|
|
|
|
|
titleTestId="t--app-card-name"
|
2022-02-17 16:38:36 +00:00
|
|
|
>
|
2023-08-31 08:21:04 +00:00
|
|
|
{hasEditPermission && !isMenuOpen && (
|
|
|
|
|
<Button
|
|
|
|
|
className="t--application-edit-link"
|
|
|
|
|
href={editModeURL}
|
|
|
|
|
onClick={editApp}
|
2024-03-21 10:07:13 +00:00
|
|
|
renderAs="a"
|
2023-08-31 08:21:04 +00:00
|
|
|
size="md"
|
|
|
|
|
startIcon={"pencil-line"}
|
2020-10-14 10:35:19 +00:00
|
|
|
>
|
2023-08-31 08:21:04 +00:00
|
|
|
Edit
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
{!isMenuOpen && (
|
|
|
|
|
<Button
|
|
|
|
|
className="t--application-view-link"
|
|
|
|
|
href={viewModeURL}
|
|
|
|
|
kind="secondary"
|
|
|
|
|
onClick={launchApp}
|
2024-03-21 10:07:13 +00:00
|
|
|
renderAs="a"
|
2023-08-31 08:21:04 +00:00
|
|
|
size="md"
|
|
|
|
|
startIcon={"rocket"}
|
|
|
|
|
>
|
|
|
|
|
Launch
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</Card>
|
2019-11-21 10:52:49 +00:00
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-11-21 10:52:49 +00:00
|
|
|
|
|
|
|
|
export default ApplicationCard;
|