Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Unstract Subscription Plugin Fixes #1113

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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