2021-10-18 07:47:55 +00:00
|
|
|
import React from "react";
|
2022-10-17 13:09:09 +00:00
|
|
|
import { Link } from "react-router-dom";
|
2021-10-18 07:47:55 +00:00
|
|
|
import styled from "styled-components";
|
2022-09-28 17:27:40 +00:00
|
|
|
import AdminConfig from "@appsmith/pages/AdminSettings/config";
|
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 { Category } from "@appsmith/pages/AdminSettings/config/types";
|
2022-03-27 16:25:08 +00:00
|
|
|
import { adminSettingsCategoryUrl } from "RouteBuilder";
|
2022-10-17 13:09:09 +00:00
|
|
|
import { useParams } from "react-router";
|
2023-05-19 18:37:06 +00:00
|
|
|
import { createMessage, UPGRADE } from "@appsmith/constants/messages";
|
2022-12-10 09:26:29 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
2023-05-19 18:37:06 +00:00
|
|
|
import { Icon, Text } from "design-system";
|
2021-10-18 07:47:55 +00:00
|
|
|
|
2022-05-05 05:37:50 +00:00
|
|
|
export const Wrapper = styled.div`
|
2023-05-19 18:37:06 +00:00
|
|
|
flex-basis: ${(props) => props.theme.sidebarWidth};
|
2022-12-11 12:51:52 +00:00
|
|
|
overflow-y: auto;
|
2023-05-19 18:37:06 +00:00
|
|
|
border-right: 1px solid var(--ads-v2-color-border);
|
2022-12-14 12:07:55 +00:00
|
|
|
flex-shrink: 0;
|
2022-12-11 12:51:52 +00:00
|
|
|
|
|
|
|
|
&::-webkit-scrollbar {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
2023-05-19 18:37:06 +00:00
|
|
|
|
|
|
|
|
> div:not(:first-child) {
|
|
|
|
|
border-top: 1px solid var(--ads-v2-color-border);
|
|
|
|
|
}
|
2021-10-18 07:47:55 +00:00
|
|
|
`;
|
|
|
|
|
|
2022-12-14 12:07:55 +00:00
|
|
|
export const HeaderContainer = styled.div`
|
|
|
|
|
padding: 20px 0;
|
2023-05-19 18:37:06 +00:00
|
|
|
margin: 0 16px;
|
2022-12-14 12:07:55 +00:00
|
|
|
`;
|
2021-10-18 07:47:55 +00:00
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
export const StyledHeader = styled(Text)`
|
2022-02-11 18:08:46 +00:00
|
|
|
height: 20px;
|
2022-12-14 12:07:55 +00:00
|
|
|
margin: 8px 16px 8px;
|
2023-05-19 18:37:06 +00:00
|
|
|
color: var(--ads-v2-color-fg-emphasis);
|
2021-10-18 07:47:55 +00:00
|
|
|
`;
|
|
|
|
|
|
2022-05-05 05:37:50 +00:00
|
|
|
export const CategoryList = styled.ul`
|
2021-10-18 07:47:55 +00:00
|
|
|
margin: 0;
|
|
|
|
|
list-style-type: none;
|
|
|
|
|
`;
|
|
|
|
|
|
2022-10-20 16:49:30 +00:00
|
|
|
export const CategoryItem = styled.li`
|
2023-05-19 18:37:06 +00:00
|
|
|
/* width: 90%; */
|
2022-10-20 16:49:30 +00:00
|
|
|
`;
|
2021-10-18 07:47:55 +00:00
|
|
|
|
2022-05-05 05:37:50 +00:00
|
|
|
export const StyledLink = styled(Link)<{ $active: boolean }>`
|
2021-10-18 07:47:55 +00:00
|
|
|
height: 38px;
|
2022-05-05 05:37:50 +00:00
|
|
|
padding: 8px 16px;
|
2023-05-19 18:37:06 +00:00
|
|
|
border-radius: var(--ads-v2-border-radius);
|
2021-10-18 07:47:55 +00:00
|
|
|
background-color: ${(props) =>
|
2023-05-19 18:37:06 +00:00
|
|
|
props.$active ? `var(--ads-v2-color-bg-muted)` : ""};
|
2022-10-17 13:09:09 +00:00
|
|
|
display: flex;
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
2021-10-18 07:47:55 +00:00
|
|
|
&& {
|
2023-05-19 18:37:06 +00:00
|
|
|
color: var(--ads-v2-color-fg);
|
2021-10-18 07:47:55 +00:00
|
|
|
}
|
2023-05-19 18:37:06 +00:00
|
|
|
|
2021-10-18 07:47:55 +00:00
|
|
|
&:hover {
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
}
|
2022-10-17 13:09:09 +00:00
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
&:hover:not(.active) {
|
|
|
|
|
background-color: var(--ads-v2-color-bg-subtle);
|
2022-10-17 13:09:09 +00:00
|
|
|
}
|
2021-10-18 07:47:55 +00:00
|
|
|
`;
|
|
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
export const SettingName = styled(Text)<{ active?: boolean }>`
|
|
|
|
|
color: ${(props) =>
|
|
|
|
|
props.active
|
|
|
|
|
? "var(--ads-v2-color-fg-emphasis-plus)"
|
|
|
|
|
: "var(--ads-v2-color-fg)"};
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
`;
|
|
|
|
|
|
2022-05-18 04:53:08 +00:00
|
|
|
export function getSettingsCategory() {
|
2022-02-11 18:08:46 +00:00
|
|
|
return Array.from(AdminConfig.categories);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-05 05:37:50 +00:00
|
|
|
export function Categories({
|
2022-02-11 18:08:46 +00:00
|
|
|
categories,
|
|
|
|
|
currentCategory,
|
|
|
|
|
currentSubCategory,
|
|
|
|
|
parentCategory,
|
|
|
|
|
showSubCategory,
|
|
|
|
|
}: {
|
|
|
|
|
categories?: Category[];
|
|
|
|
|
parentCategory?: Category;
|
|
|
|
|
currentCategory: string;
|
|
|
|
|
currentSubCategory?: string;
|
|
|
|
|
showSubCategory?: boolean;
|
|
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<CategoryList className="t--settings-category-list">
|
2023-05-19 18:37:06 +00:00
|
|
|
{categories?.map((config) => {
|
|
|
|
|
const active =
|
|
|
|
|
!!currentSubCategory && showSubCategory
|
|
|
|
|
? currentSubCategory == config.slug
|
|
|
|
|
: currentCategory == config.slug;
|
|
|
|
|
return (
|
|
|
|
|
<CategoryItem key={config.slug}>
|
|
|
|
|
<StyledLink
|
|
|
|
|
$active={active}
|
|
|
|
|
className={`t--settings-category-${config.slug} ${
|
|
|
|
|
active ? "active" : ""
|
|
|
|
|
}`}
|
|
|
|
|
to={
|
|
|
|
|
!parentCategory
|
|
|
|
|
? adminSettingsCategoryUrl({ category: config.slug })
|
|
|
|
|
: adminSettingsCategoryUrl({
|
|
|
|
|
category: parentCategory.slug,
|
|
|
|
|
selected: config.slug,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{config?.icon && <Icon name={config?.icon} size="md" />}
|
|
|
|
|
<SettingName active={active}>{config.title}</SettingName>
|
|
|
|
|
</StyledLink>
|
|
|
|
|
{showSubCategory && (
|
|
|
|
|
<Categories
|
|
|
|
|
categories={config.children}
|
|
|
|
|
currentCategory={currentCategory}
|
|
|
|
|
currentSubCategory={currentSubCategory}
|
|
|
|
|
parentCategory={config}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</CategoryItem>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2022-02-11 18:08:46 +00:00
|
|
|
</CategoryList>
|
|
|
|
|
);
|
2021-10-18 07:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function LeftPane() {
|
2022-05-18 04:53:08 +00:00
|
|
|
const categories = getSettingsCategory();
|
2022-06-08 13:18:15 +00:00
|
|
|
const { category, selected: subCategory } = useParams() as any;
|
2022-12-01 06:30:50 +00:00
|
|
|
|
2022-12-10 09:26:29 +00:00
|
|
|
function triggerAnalytics(source: string) {
|
|
|
|
|
AnalyticsUtil.logEvent("ADMIN_SETTINGS_CLICK", {
|
|
|
|
|
source,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 07:47:55 +00:00
|
|
|
return (
|
|
|
|
|
<Wrapper>
|
2022-12-14 12:07:55 +00:00
|
|
|
<HeaderContainer>
|
2023-05-19 18:37:06 +00:00
|
|
|
<StyledHeader kind="heading-s" renderAs="p">
|
|
|
|
|
Admin settings
|
|
|
|
|
</StyledHeader>
|
2022-12-01 06:30:50 +00:00
|
|
|
<Categories
|
|
|
|
|
categories={categories}
|
|
|
|
|
currentCategory={category}
|
|
|
|
|
currentSubCategory={subCategory}
|
|
|
|
|
/>
|
2022-12-14 12:07:55 +00:00
|
|
|
</HeaderContainer>
|
|
|
|
|
<HeaderContainer>
|
2023-05-19 18:37:06 +00:00
|
|
|
<StyledHeader kind="heading-s" renderAs="p">
|
|
|
|
|
Business
|
|
|
|
|
</StyledHeader>
|
2022-10-17 13:09:09 +00:00
|
|
|
<CategoryList data-testid="t--enterprise-settings-category-list">
|
2022-12-23 08:09:36 +00:00
|
|
|
<CategoryItem>
|
|
|
|
|
<StyledLink
|
|
|
|
|
$active={category === "access-control"}
|
2023-05-19 18:37:06 +00:00
|
|
|
className={`${category === "access-control" ? "active" : ""}`}
|
2022-12-23 08:09:36 +00:00
|
|
|
data-testid="t--enterprise-settings-category-item-access-control"
|
|
|
|
|
to="/settings/access-control"
|
|
|
|
|
>
|
2023-05-19 18:37:06 +00:00
|
|
|
<Icon name="lock-2-line" size="md" />
|
|
|
|
|
<SettingName active={category === "access-control"}>
|
|
|
|
|
Access control
|
|
|
|
|
</SettingName>
|
2022-12-23 08:09:36 +00:00
|
|
|
</StyledLink>
|
|
|
|
|
</CategoryItem>
|
2022-10-17 13:09:09 +00:00
|
|
|
<CategoryItem>
|
|
|
|
|
<StyledLink
|
|
|
|
|
$active={category === "audit-logs"}
|
2023-05-19 18:37:06 +00:00
|
|
|
className={`${category === "audit-logs" ? "active" : ""}`}
|
2022-10-17 13:09:09 +00:00
|
|
|
data-testid="t--enterprise-settings-category-item-audit-logs"
|
2022-12-10 09:26:29 +00:00
|
|
|
onClick={() => triggerAnalytics("AuditLogs")}
|
2022-10-17 13:09:09 +00:00
|
|
|
to="/settings/audit-logs"
|
|
|
|
|
>
|
2023-05-19 18:37:06 +00:00
|
|
|
<Icon name="lock-2-line" size="md" />
|
|
|
|
|
<SettingName active={category === "audit-logs"}>
|
|
|
|
|
Audit logs
|
|
|
|
|
</SettingName>
|
2022-10-17 13:09:09 +00:00
|
|
|
</StyledLink>
|
|
|
|
|
</CategoryItem>
|
2023-02-20 16:59:06 +00:00
|
|
|
<CategoryItem>
|
|
|
|
|
<StyledLink
|
|
|
|
|
$active={category === "business-edition"}
|
2023-05-19 18:37:06 +00:00
|
|
|
className={`${category === "business-edition" ? "active" : ""}`}
|
2023-02-20 16:59:06 +00:00
|
|
|
data-testid="t--enterprise-settings-category-item-be"
|
|
|
|
|
onClick={() => triggerAnalytics("BusinessEdition")}
|
|
|
|
|
to="/settings/business-edition"
|
|
|
|
|
>
|
2023-05-19 18:37:06 +00:00
|
|
|
<Icon name="arrow-up-line" size="md" />
|
|
|
|
|
<SettingName active={category === "business-edition"}>
|
|
|
|
|
{createMessage(UPGRADE)}
|
|
|
|
|
</SettingName>
|
2023-02-20 16:59:06 +00:00
|
|
|
</StyledLink>
|
|
|
|
|
</CategoryItem>
|
2022-10-17 13:09:09 +00:00
|
|
|
</CategoryList>
|
2022-12-14 12:07:55 +00:00
|
|
|
</HeaderContainer>
|
2021-10-18 07:47:55 +00:00
|
|
|
</Wrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|