Skip to content

Commit

Permalink
FIX: Unstract Subscription Plugin Fixes (#1113)
Browse files Browse the repository at this point in the history
* Fixed issue in disabling the side menu items

* Allow access to the '/pricing' page only for admins
  • Loading branch information
tahierhussain authored Feb 4, 2025
1 parent cc56b29 commit bef823f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
31 changes: 24 additions & 7 deletions frontend/src/components/navigations/side-nav-bar/SideNavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ try {
// Plugin unavailable.
}

let selectedProductStore;
let selectedProduct;
try {
selectedProductStore = require("../../../plugins/llm-whisperer/store/select-product-store.js");
} catch {
// Ignore if hook not available
}

const SideNavBar = ({ collapsed }) => {
const navigate = useNavigate();
const { sessionDetails } = useSessionStore();
Expand All @@ -62,6 +70,12 @@ const SideNavBar = ({ collapsed }) => {
// Do nothing
}

if (selectedProductStore?.useSelectedProductStore) {
selectedProduct = selectedProductStore.useSelectedProductStore(
(state) => state?.selectedProduct
);
}

let menu;
if (sideMenu) {
menu = sideMenu.useSideMenu();
Expand Down Expand Up @@ -193,7 +207,12 @@ const SideNavBar = ({ collapsed }) => {
}

const shouldDisableAll = useMemo(() => {
if (!unstractSubscriptionPlan || !UNSTRACT_SUBSCRIPTION_PLANS) {
const isUnstract = !(selectedProduct && selectedProduct !== "unstract");
if (
!unstractSubscriptionPlan ||
!UNSTRACT_SUBSCRIPTION_PLANS ||
!isUnstract
) {
return false;
}

Expand All @@ -203,13 +222,11 @@ const SideNavBar = ({ collapsed }) => {
);
}, [unstractSubscriptionPlan]);

if (shouldDisableAll) {
data.forEach((mainMenuItem) => {
mainMenuItem.subMenu.forEach((subMenuItem) => {
subMenuItem.disable = true;
});
data.forEach((mainMenuItem) => {
mainMenuItem.subMenu.forEach((subMenuItem) => {
subMenuItem.disable = shouldDisableAll;
});
}
});

return (
<Sider
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/components/navigations/top-nav-bar/TopNavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getBaseUrl,
homePagePath,
onboardCompleted,
UNSTRACT_ADMIN,
} from "../../../helpers/GetStaticData.js";
import useLogout from "../../../hooks/useLogout.js";
import "../../../layouts/page-layout/PageLayout.css";
Expand Down Expand Up @@ -132,7 +133,7 @@ function TopNavBar({ isSimpleLayout, topNavBarOptions }) {
const { role } = sessionDetails;
const isReviewer = role === "unstract_reviewer";
const isSupervisor = role === "unstract_supervisor";
const isAdmin = role === "unstract_admin";
const isAdmin = role === UNSTRACT_ADMIN;

setShowOnboardBanner(
!onboardCompleted(sessionDetails?.adapters) &&
Expand Down Expand Up @@ -297,7 +298,11 @@ function TopNavBar({ isSimpleLayout, topNavBarOptions }) {
});
}

if (isUnstract && UnstractPricingMenuLink) {
if (
isUnstract &&
UnstractPricingMenuLink &&
sessionDetails?.role === UNSTRACT_ADMIN
) {
menuItems.push({
key: "7",
label: <UnstractPricingMenuLink orgName={orgName} />,
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/helpers/GetStaticData.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ const TRIAL_PLAN = "TRIAL";

const homePagePath = cloudHomePagePath || "tools";

const UNSTRACT_ADMIN = "unstract_admin";

export {
CONNECTOR_TYPE_MAP,
O_AUTH_PROVIDERS,
Expand Down Expand Up @@ -639,4 +641,5 @@ export {
generateCoverageKey,
TRIAL_PLAN,
homePagePath,
UNSTRACT_ADMIN,
};
8 changes: 8 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ body {
padding-left: 6px;
}

.pad-top-20 {
padding-top: 20px;
}

.pad-bottom-20 {
padding-bottom: 20px;
}

.cur-pointer {
cursor: pointer;
}
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/routes/useMainAppRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { CustomTools } from "../pages/CustomTools.jsx";
import { CustomToolsHelper } from "../components/helpers/custom-tools/CustomToolsHelper.js";
import { ToolIdePage } from "../pages/ToolIdePage.jsx";
import { OutputAnalyzerPage } from "../pages/OutputAnalyzerPage.jsx";
import { deploymentTypes } from "../helpers/GetStaticData.js";
import { deploymentTypes, UNSTRACT_ADMIN } from "../helpers/GetStaticData.js";
import { useSessionStore } from "../store/session-store.js";

let RequirePlatformAdmin;
let PlatformAdminPage;
Expand Down Expand Up @@ -94,6 +95,8 @@ try {
}

function useMainAppRoutes() {
const { role } = useSessionStore((state) => state?.sessionDetails);

const routes = (
<>
<Route path=":orgName" element={<FullPageLayout />}>
Expand All @@ -108,7 +111,7 @@ function useMainAppRoutes() {
{UnstractUsagePage && (
<Route path="dashboard" element={<UnstractUsagePage />} />
)}
{UnstractSubscriptionPage && (
{UnstractSubscriptionPage && role === UNSTRACT_ADMIN && (
<Route path="pricing" element={<UnstractSubscriptionPage />} />
)}
<Route path="profile" element={<ProfilePage />} />
Expand Down

0 comments on commit bef823f

Please sign in to comment.