2022-09-01 03:58:04 +00:00
|
|
|
import React, { useEffect, useRef } from "react";
|
2022-03-03 10:56:53 +00:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { Classes } from "@blueprintjs/core";
|
|
|
|
|
import { useParams } from "react-router";
|
|
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
|
import EntityNotFoundPane from "pages/Editor/EntityNotFoundPane";
|
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 { Template as TemplateInterface } from "api/TemplatesApi";
|
2022-03-03 10:56:53 +00:00
|
|
|
import {
|
2022-03-31 05:16:04 +00:00
|
|
|
getActiveTemplateSelector,
|
2023-02-10 06:11:35 +00:00
|
|
|
getForkableWorkspaces,
|
2022-03-31 05:16:04 +00:00
|
|
|
isFetchingTemplateSelector,
|
2022-03-03 10:56:53 +00:00
|
|
|
} from "selectors/templatesSelectors";
|
2022-03-31 05:16:04 +00:00
|
|
|
import {
|
|
|
|
|
getSimilarTemplatesInit,
|
|
|
|
|
getTemplateInformation,
|
|
|
|
|
} from "actions/templateActions";
|
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 { AppState } from "@appsmith/reducers";
|
2022-03-03 10:56:53 +00:00
|
|
|
import history from "utils/history";
|
2022-03-25 10:43:26 +00:00
|
|
|
import { TEMPLATES_PATH } from "constants/routes";
|
2022-03-03 10:56:53 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
2022-04-29 10:09:16 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
2022-08-04 04:20:54 +00:00
|
|
|
import ReconnectDatasourceModal from "pages/Editor/gitSync/ReconnectDatasourceModal";
|
2022-09-30 13:41:04 +00:00
|
|
|
import TemplateDescription from "./Template/TemplateDescription";
|
|
|
|
|
import SimilarTemplates from "./Template/SimilarTemplates";
|
2022-09-01 03:58:04 +00:00
|
|
|
import { templateIdUrl } from "RouteBuilder";
|
2023-06-15 05:26:42 +00:00
|
|
|
import TemplateViewHeader from "./TemplateViewHeader";
|
2022-03-03 10:56:53 +00:00
|
|
|
|
2022-03-31 05:16:04 +00:00
|
|
|
const breakpointColumnsObject = {
|
|
|
|
|
default: 4,
|
2023-05-19 18:37:06 +00:00
|
|
|
3000: 3,
|
|
|
|
|
1500: 3,
|
|
|
|
|
1024: 2,
|
|
|
|
|
800: 1,
|
2022-03-31 05:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
2022-03-03 10:56:53 +00:00
|
|
|
const Wrapper = styled.div`
|
|
|
|
|
overflow: auto;
|
2022-03-31 05:16:04 +00:00
|
|
|
position: relative;
|
2022-03-03 10:56:53 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const TemplateViewWrapper = styled.div`
|
2022-03-31 05:16:04 +00:00
|
|
|
padding-right: 132px;
|
|
|
|
|
padding-left: 132px;
|
2023-05-19 18:37:06 +00:00
|
|
|
padding-top: var(--ads-v2-spaces-7);
|
2022-03-10 14:39:05 +00:00
|
|
|
padding-bottom: 80px;
|
2023-05-19 18:37:06 +00:00
|
|
|
background-color: var(--ads-v2-color-bg);
|
2022-03-31 05:16:04 +00:00
|
|
|
`;
|
|
|
|
|
|
2022-09-30 13:41:04 +00:00
|
|
|
export const IframeWrapper = styled.div`
|
2022-03-03 10:56:53 +00:00
|
|
|
border-radius: 16px;
|
|
|
|
|
margin-top: ${(props) => props.theme.spaces[12]}px;
|
|
|
|
|
|
|
|
|
|
iframe {
|
|
|
|
|
border-radius: 0px 0px 16px 16px;
|
2023-10-11 07:14:38 +00:00
|
|
|
box-shadow:
|
|
|
|
|
0px 20px 24px -4px rgba(16, 24, 40, 0.1),
|
2022-03-03 10:56:53 +00:00
|
|
|
0px 8px 8px -4px rgba(16, 24, 40, 0.04);
|
2022-09-30 13:41:04 +00:00
|
|
|
width: 100%;
|
|
|
|
|
height: 734px;
|
2022-09-26 08:14:39 +00:00
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2022-09-30 13:41:04 +00:00
|
|
|
export const IframeTopBar = styled.div`
|
2022-03-03 10:56:53 +00:00
|
|
|
width: 100%;
|
2023-05-19 18:37:06 +00:00
|
|
|
background-color: var(--ads-v2-color-bg-muted);
|
2022-03-03 10:56:53 +00:00
|
|
|
border-radius: 8px 8px 0px 0px;
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: ${(props) => props.theme.spaces[3]}px;
|
|
|
|
|
height: 41px;
|
|
|
|
|
align-items: center;
|
|
|
|
|
padding-left: ${(props) => props.theme.spaces[5]}px;
|
|
|
|
|
|
|
|
|
|
.round {
|
|
|
|
|
height: 12px;
|
|
|
|
|
width: 12px;
|
2023-05-19 18:37:06 +00:00
|
|
|
border-radius: var(--ads-v2-border-radius-circle);
|
2022-03-03 10:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.red {
|
|
|
|
|
background-color: ${Colors.PERSIMMON};
|
|
|
|
|
}
|
|
|
|
|
.yellow {
|
|
|
|
|
background-color: ${Colors.SUNGLOW_2};
|
|
|
|
|
}
|
|
|
|
|
.green {
|
|
|
|
|
background-color: ${Colors.MOUNTAIN_MEADOW};
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const PageWrapper = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
margin-top: ${(props) => props.theme.homePage.header}px;
|
|
|
|
|
height: calc(100vh - ${(props) => props.theme.homePage.header}px);
|
|
|
|
|
`;
|
|
|
|
|
|
2022-03-31 05:16:04 +00:00
|
|
|
const LoadingWrapper = styled.div`
|
|
|
|
|
width: calc(100vw);
|
|
|
|
|
.title-placeholder {
|
|
|
|
|
margin-top: ${(props) => props.theme.spaces[11]}px;
|
|
|
|
|
height: 28px;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
.iframe-placeholder {
|
|
|
|
|
margin-top: ${(props) => props.theme.spaces[12]}px;
|
|
|
|
|
height: 500px;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2022-03-03 10:56:53 +00:00
|
|
|
function TemplateViewLoader() {
|
|
|
|
|
return (
|
2022-03-31 05:16:04 +00:00
|
|
|
<LoadingWrapper>
|
2022-03-03 10:56:53 +00:00
|
|
|
<TemplateViewWrapper>
|
|
|
|
|
<div className={`title-placeholder ${Classes.SKELETON}`} />
|
|
|
|
|
<div className={`iframe-placeholder ${Classes.SKELETON}`} />
|
|
|
|
|
</TemplateViewWrapper>
|
2022-03-31 05:16:04 +00:00
|
|
|
</LoadingWrapper>
|
2022-03-03 10:56:53 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function TemplateNotFound() {
|
2022-03-31 05:16:04 +00:00
|
|
|
return <EntityNotFoundPane />;
|
2022-03-03 10:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function TemplateView() {
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const similarTemplates = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.templates.similarTemplates,
|
|
|
|
|
);
|
2022-03-31 05:16:04 +00:00
|
|
|
const isFetchingTemplate = useSelector(isFetchingTemplateSelector);
|
2023-02-10 06:11:35 +00:00
|
|
|
const workspaceList = useSelector(getForkableWorkspaces);
|
2022-03-03 10:56:53 +00:00
|
|
|
const params = useParams<{ templateId: string }>();
|
2022-03-31 05:16:04 +00:00
|
|
|
const currentTemplate = useSelector(getActiveTemplateSelector);
|
2022-03-03 10:56:53 +00:00
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
const goToTemplateListView = () => {
|
2022-03-25 10:43:26 +00:00
|
|
|
history.push(TEMPLATES_PATH);
|
2022-03-03 10:56:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-03-31 05:16:04 +00:00
|
|
|
dispatch(getTemplateInformation(params.templateId));
|
|
|
|
|
dispatch(getSimilarTemplatesInit(params.templateId));
|
2022-03-03 10:56:53 +00:00
|
|
|
if (containerRef.current) {
|
2022-03-31 05:16:04 +00:00
|
|
|
containerRef.current.scrollTo({ top: 0 });
|
2022-03-03 10:56:53 +00:00
|
|
|
}
|
|
|
|
|
}, [params.templateId]);
|
|
|
|
|
|
2022-04-29 10:09:16 +00:00
|
|
|
const onSimilarTemplateClick = (template: TemplateInterface) => {
|
|
|
|
|
AnalyticsUtil.logEvent("SIMILAR_TEMPLATE_CLICK", {
|
|
|
|
|
from: {
|
|
|
|
|
id: currentTemplate?.id,
|
|
|
|
|
name: currentTemplate?.title,
|
|
|
|
|
},
|
|
|
|
|
to: {
|
|
|
|
|
id: template.id,
|
|
|
|
|
name: template.title,
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-09-30 13:41:04 +00:00
|
|
|
history.push(templateIdUrl({ id: template.id }));
|
2022-04-29 10:09:16 +00:00
|
|
|
};
|
|
|
|
|
|
2022-03-03 10:56:53 +00:00
|
|
|
return (
|
|
|
|
|
<PageWrapper>
|
2022-03-31 05:16:04 +00:00
|
|
|
{isFetchingTemplate ? (
|
2022-03-03 10:56:53 +00:00
|
|
|
<TemplateViewLoader />
|
|
|
|
|
) : !currentTemplate ? (
|
|
|
|
|
<TemplateNotFound />
|
|
|
|
|
) : (
|
|
|
|
|
<Wrapper ref={containerRef}>
|
2022-08-04 04:20:54 +00:00
|
|
|
<ReconnectDatasourceModal />
|
2022-03-03 10:56:53 +00:00
|
|
|
<TemplateViewWrapper>
|
2023-06-15 05:26:42 +00:00
|
|
|
<TemplateViewHeader templateId={params.templateId} />
|
2022-03-03 10:56:53 +00:00
|
|
|
<IframeWrapper>
|
|
|
|
|
<IframeTopBar>
|
|
|
|
|
<div className="round red" />
|
|
|
|
|
<div className="round yellow" />
|
|
|
|
|
<div className="round green" />
|
|
|
|
|
</IframeTopBar>
|
2023-06-05 14:07:39 +00:00
|
|
|
<iframe src={currentTemplate.appUrl} width={"100%"} />
|
2022-03-03 10:56:53 +00:00
|
|
|
</IframeWrapper>
|
2022-09-30 13:41:04 +00:00
|
|
|
<TemplateDescription template={currentTemplate} />
|
2022-03-03 10:56:53 +00:00
|
|
|
</TemplateViewWrapper>
|
2022-09-30 13:41:04 +00:00
|
|
|
<SimilarTemplates
|
|
|
|
|
breakpointCols={breakpointColumnsObject}
|
2023-02-10 06:11:35 +00:00
|
|
|
isForkingEnabled={!!workspaceList.length}
|
2022-09-30 13:41:04 +00:00
|
|
|
onBackPress={goToTemplateListView}
|
|
|
|
|
onClick={onSimilarTemplateClick}
|
|
|
|
|
similarTemplates={similarTemplates}
|
|
|
|
|
/>
|
2022-03-03 10:56:53 +00:00
|
|
|
</Wrapper>
|
|
|
|
|
)}
|
|
|
|
|
</PageWrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default TemplateView;
|