2021-10-18 07:47:55 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import styled from "styled-components";
|
2022-09-28 17:27:40 +00:00
|
|
|
import AdminConfig from "@appsmith/pages/AdminSettings/config";
|
2023-07-18 09:48:48 +00:00
|
|
|
import {
|
|
|
|
|
CategoryType,
|
|
|
|
|
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";
|
2022-12-10 09:26:29 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
2023-09-14 10:44:23 +00:00
|
|
|
import { Link, Text } from "design-system";
|
2023-07-18 09:48:48 +00:00
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
2023-05-23 17:00:20 +00:00
|
|
|
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
|
2023-07-18 09:48:48 +00:00
|
|
|
import { getCurrentUser } from "selectors/usersSelectors";
|
2023-08-07 04:58:21 +00:00
|
|
|
import BusinessTag from "components/BusinessTag";
|
|
|
|
|
import EnterpriseTag from "components/EnterpriseTag";
|
2023-08-28 15:37:32 +00:00
|
|
|
import { getTenantPermissions } from "@appsmith/selectors/tenantSelectors";
|
|
|
|
|
import { hasAuditLogsReadPermission } from "@appsmith/utils/permissionHelpers";
|
|
|
|
|
import {
|
|
|
|
|
getFilteredAclCategories,
|
|
|
|
|
getFilteredGeneralCategories,
|
|
|
|
|
getFilteredOtherCategories,
|
|
|
|
|
} from "@appsmith/utils/adminSettingsHelpers";
|
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;
|
2023-07-18 09:48:48 +00:00
|
|
|
padding: 12px 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`
|
2023-07-18 09:48:48 +00:00
|
|
|
margin: 12px;
|
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;
|
2023-07-18 09:48:48 +00:00
|
|
|
margin: 16px;
|
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 }>`
|
|
|
|
|
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)` : ""};
|
2023-09-14 10:44:23 +00:00
|
|
|
text-decoration: none !important;
|
|
|
|
|
|
|
|
|
|
.ads-v2-text {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 12px;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
2022-10-17 13:09:09 +00:00
|
|
|
|
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;
|
|
|
|
|
`;
|
|
|
|
|
|
2023-08-28 15:37:32 +00:00
|
|
|
export function getSettingsCategory(type: string): Category[] {
|
2023-07-18 09:48:48 +00:00
|
|
|
return Array.from(
|
|
|
|
|
AdminConfig.categories.filter((cat: any) => cat.categoryType === type),
|
|
|
|
|
);
|
2022-02-11 18:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}) {
|
2023-05-23 17:00:20 +00:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
2023-07-18 09:48:48 +00:00
|
|
|
const triggerAnalytics = (page: string) => {
|
|
|
|
|
const source: any = {
|
|
|
|
|
"audit-logs": "AuditLogs",
|
|
|
|
|
"access-control": "AccessControl",
|
|
|
|
|
provisioning: "Provisioning",
|
|
|
|
|
};
|
|
|
|
|
AnalyticsUtil.logEvent("ADMIN_SETTINGS_CLICK", {
|
|
|
|
|
source: source[page],
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-24 12:32:51 +00:00
|
|
|
const onClickHandler = (category: string, showUpgradeTag: boolean) => {
|
2023-05-23 17:00:20 +00:00
|
|
|
if (category === "general") {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.FETCH_ADMIN_SETTINGS,
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-08-24 12:32:51 +00:00
|
|
|
if (showUpgradeTag) {
|
2023-07-18 09:48:48 +00:00
|
|
|
triggerAnalytics(category);
|
|
|
|
|
}
|
2023-05-23 17:00:20 +00:00
|
|
|
};
|
|
|
|
|
|
2022-02-11 18:08:46 +00:00
|
|
|
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;
|
2023-08-24 12:32:51 +00:00
|
|
|
const showUpgradeTag = config?.isFeatureEnabled === false;
|
2023-05-19 18:37:06 +00:00
|
|
|
return (
|
|
|
|
|
<CategoryItem key={config.slug}>
|
|
|
|
|
<StyledLink
|
|
|
|
|
$active={active}
|
|
|
|
|
className={`t--settings-category-${config.slug} ${
|
|
|
|
|
active ? "active" : ""
|
|
|
|
|
}`}
|
2023-07-18 09:48:48 +00:00
|
|
|
onClick={() =>
|
2023-08-24 12:32:51 +00:00
|
|
|
onClickHandler(config.slug, showUpgradeTag || false)
|
2023-07-18 09:48:48 +00:00
|
|
|
}
|
2023-09-14 10:44:23 +00:00
|
|
|
startIcon={showUpgradeTag ? "lock-2-line" : `${config.icon}`}
|
|
|
|
|
target="_self"
|
2023-05-19 18:37:06 +00:00
|
|
|
to={
|
|
|
|
|
!parentCategory
|
|
|
|
|
? adminSettingsCategoryUrl({ category: config.slug })
|
|
|
|
|
: adminSettingsCategoryUrl({
|
|
|
|
|
category: parentCategory.slug,
|
|
|
|
|
selected: config.slug,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<SettingName active={active}>{config.title}</SettingName>
|
2023-08-24 12:32:51 +00:00
|
|
|
{showUpgradeTag &&
|
2023-08-07 04:58:21 +00:00
|
|
|
(config?.isEnterprise ? <EnterpriseTag /> : <BusinessTag />)}
|
2023-05-19 18:37:06 +00:00
|
|
|
</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() {
|
2023-07-18 09:48:48 +00:00
|
|
|
const categories = getSettingsCategory(CategoryType.GENERAL);
|
|
|
|
|
const aclCategories = getSettingsCategory(CategoryType.ACL);
|
|
|
|
|
const othersCategories = getSettingsCategory(CategoryType.OTHER);
|
2022-06-08 13:18:15 +00:00
|
|
|
const { category, selected: subCategory } = useParams() as any;
|
2023-07-18 09:48:48 +00:00
|
|
|
const user = useSelector(getCurrentUser);
|
|
|
|
|
const isSuperUser = user?.isSuperUser;
|
2023-08-28 15:37:32 +00:00
|
|
|
const tenantPermissions = useSelector(getTenantPermissions);
|
|
|
|
|
const isAuditLogsEnabled = hasAuditLogsReadPermission(tenantPermissions);
|
|
|
|
|
|
|
|
|
|
const filteredGeneralCategories = getFilteredGeneralCategories(categories);
|
|
|
|
|
|
|
|
|
|
const filteredAclCategories = getFilteredAclCategories(
|
|
|
|
|
aclCategories,
|
|
|
|
|
isSuperUser,
|
|
|
|
|
);
|
2023-07-18 09:48:48 +00:00
|
|
|
|
2023-08-28 15:37:32 +00:00
|
|
|
const filteredOthersCategories = getFilteredOtherCategories(
|
|
|
|
|
othersCategories,
|
|
|
|
|
isSuperUser,
|
|
|
|
|
);
|
2022-12-10 09:26:29 +00:00
|
|
|
|
2021-10-18 07:47:55 +00:00
|
|
|
return (
|
|
|
|
|
<Wrapper>
|
2023-07-18 09:48:48 +00:00
|
|
|
{isSuperUser && (
|
|
|
|
|
<HeaderContainer>
|
|
|
|
|
<StyledHeader kind="heading-s" renderAs="p">
|
|
|
|
|
Admin settings
|
|
|
|
|
</StyledHeader>
|
|
|
|
|
<Categories
|
2023-08-28 15:37:32 +00:00
|
|
|
categories={filteredGeneralCategories}
|
2023-07-18 09:48:48 +00:00
|
|
|
currentCategory={category}
|
|
|
|
|
currentSubCategory={subCategory}
|
|
|
|
|
/>
|
|
|
|
|
</HeaderContainer>
|
|
|
|
|
)}
|
2022-12-14 12:07:55 +00:00
|
|
|
<HeaderContainer>
|
2023-05-19 18:37:06 +00:00
|
|
|
<StyledHeader kind="heading-s" renderAs="p">
|
2023-07-18 09:48:48 +00:00
|
|
|
Access control
|
2023-05-19 18:37:06 +00:00
|
|
|
</StyledHeader>
|
2022-12-01 06:30:50 +00:00
|
|
|
<Categories
|
2023-07-18 09:48:48 +00:00
|
|
|
categories={filteredAclCategories}
|
2022-12-01 06:30:50 +00:00
|
|
|
currentCategory={category}
|
|
|
|
|
currentSubCategory={subCategory}
|
|
|
|
|
/>
|
2022-12-14 12:07:55 +00:00
|
|
|
</HeaderContainer>
|
2023-08-28 15:37:32 +00:00
|
|
|
{isAuditLogsEnabled && (
|
|
|
|
|
<HeaderContainer>
|
|
|
|
|
<StyledHeader kind="heading-s" renderAs="p">
|
|
|
|
|
Others
|
|
|
|
|
</StyledHeader>
|
|
|
|
|
<Categories
|
|
|
|
|
categories={filteredOthersCategories}
|
|
|
|
|
currentCategory={category}
|
|
|
|
|
currentSubCategory={subCategory}
|
|
|
|
|
/>
|
|
|
|
|
</HeaderContainer>
|
|
|
|
|
)}
|
2021-10-18 07:47:55 +00:00
|
|
|
</Wrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|