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

chore: add proposal discussion forum feature flag #1200

Merged
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
10 changes: 10 additions & 0 deletions .github/workflows/build-and-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ run-name: Deploy by @${{ github.actor }}

on:
workflow_dispatch:
inputs:
isProposalDiscussionForumEnabled:
description: "Enable proposal discussion forum"
required: true
type: choice
default: "disabled"
options:
- "enabled"
- "disabled"

env:
ENVIRONMENT: "dev"
CARDANO_NETWORK: "sanchonet"
DOMAIN: "dev-sanchonet.govtool.byron.network"
IS_PROPOSAL_DISCUSSION_FORUM_ENABLED: ${{ inputs.isProposalDiscussionForumEnabled == 'enabled' }}

jobs:
deploy:
Expand Down
10 changes: 5 additions & 5 deletions govtool/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback, useEffect } from "react";
import { Route, Routes, useNavigate } from "react-router-dom";
import { Modal, ScrollToTop } from "@atoms";
import { PATHS, PDF_PATHS } from "@consts";
import { useCardano, useModal } from "@context";
import { useCardano, useFeatureFlag, useModal } from "@context";
import { useWalletConnectionListener } from "@hooks";
import {
DashboardCards,
Expand Down Expand Up @@ -34,12 +34,12 @@ import {
getItemFromLocalStorage,
WALLET_LS_KEY,
removeItemFromLocalStorage,
isDevEnv,
} from "@utils";

import { PDFWrapper } from "./components/organisms/PDFWrapper";

export default () => {
const { isProposalDiscussionForumEnabled } = useFeatureFlag();
const { enable, isEnabled } = useCardano();
const navigate = useNavigate();
const { modal, openModal, modals } = useModal();
Expand Down Expand Up @@ -81,7 +81,7 @@ export default () => {
}, [checkTheWalletIsActive]);

useEffect(() => {
if (!isDevEnv) return;
if (!isProposalDiscussionForumEnabled) return;
if (
window.location.pathname.includes(PDF_PATHS.proposalDiscussion) &&
!window.location.pathname.includes(PATHS.proposalPillar.replace("/*", ""))
Expand All @@ -101,7 +101,7 @@ export default () => {
<Routes>
<Route path={PATHS.home} element={<Home />} />
<Route path={PATHS.governanceActions} element={<GovernanceActions />} />
{isDevEnv && !isEnabled && (
{isProposalDiscussionForumEnabled && !isEnabled && (
<Route path={PATHS.proposalPillar} element={<PDFWrapper />} />
)}
<Route
Expand All @@ -114,7 +114,7 @@ export default () => {
/>
<Route element={<Dashboard />}>
<Route path={PATHS.dashboard} element={<DashboardCards />} />
{isDevEnv && (
{isProposalDiscussionForumEnabled && (
<Route
path={PATHS.connectedProposalPillar}
element={<PDFWrapper />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CONNECTED_NAV_ITEMS, ICONS } from "@consts";
import { DRepInfoCard, WalletInfoCard } from "@molecules";
import { useGetVoterInfo, useScreenDimension } from "@hooks";
import { openInNewTab } from "@utils";
import { useFeatureFlag } from "@context";

import { DashboardDrawerMobileProps } from "./types";

Expand All @@ -16,6 +17,7 @@ export const DashboardDrawerMobile = ({
isDrawerOpen,
setIsDrawerOpen,
}: DashboardDrawerMobileProps) => {
const { isProposalDiscussionForumEnabled } = useFeatureFlag();
const { screenWidth } = useScreenDimension();
const { voter } = useGetVoterInfo();

Expand Down Expand Up @@ -65,21 +67,30 @@ export const DashboardDrawerMobile = ({
</IconButton>
</Box>
<Grid container direction="column" rowGap={4} mt={6}>
{CONNECTED_NAV_ITEMS.map((navItem) => (
<Grid item>
<Link
{...navItem}
size="big"
onClick={() => {
// TODO: Refine if it is needed to remove this eslint-disable
// eslint-disable-next-line no-unused-expressions
navItem.newTabLink && openInNewTab(navItem.newTabLink);
setIsDrawerOpen(false);
}}
isConnectWallet
/>
</Grid>
))}
{CONNECTED_NAV_ITEMS.map((navItem) => {
if (
!isProposalDiscussionForumEnabled &&
navItem.dataTestId === "proposal-discussion-link"
) {
return null;
}

return (
<Grid item>
<Link
{...navItem}
size="big"
onClick={() => {
// TODO: Refine if it is needed to remove this eslint-disable
// eslint-disable-next-line no-unused-expressions
navItem.newTabLink && openInNewTab(navItem.newTabLink);
setIsDrawerOpen(false);
}}
isConnectWallet
/>
</Grid>
);
})}
</Grid>
</Box>
{(voter?.isRegisteredAsDRep || voter?.isRegisteredAsSoleVoter) && (
Expand Down
35 changes: 23 additions & 12 deletions govtool/frontend/src/components/organisms/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { NavLink } from "react-router-dom";

import { DrawerLink, Spacer } from "@atoms";
import { CONNECTED_NAV_ITEMS, IMAGES, PATHS } from "@consts";
import { useFeatureFlag } from "@context";
import { useGetVoterInfo } from "@hooks";
import { WalletInfoCard, DRepInfoCard } from "@molecules";
import { openInNewTab } from "@utils";

export const Drawer = () => {
const { isProposalDiscussionForumEnabled } = useFeatureFlag();
const { voter } = useGetVoterInfo();

return (
Expand Down Expand Up @@ -44,18 +46,27 @@ export const Drawer = () => {
px={3}
rowGap={2}
>
{CONNECTED_NAV_ITEMS.map((navItem) => (
<Grid item key={navItem.label}>
<DrawerLink
{...navItem}
onClick={
navItem.newTabLink
? () => openInNewTab(navItem.newTabLink)
: undefined
}
/>
</Grid>
))}
{CONNECTED_NAV_ITEMS.map((navItem) => {
if (
!isProposalDiscussionForumEnabled &&
navItem.dataTestId === "proposal-discussion-link"
) {
return null;
}

return (
<Grid item key={navItem.label}>
<DrawerLink
{...navItem}
onClick={
navItem.newTabLink
? () => openInNewTab(navItem.newTabLink)
: undefined
}
/>
</Grid>
);
})}
</Grid>
<Box p={2}>
{voter?.isRegisteredAsDRep && <DRepInfoCard />}
Expand Down
8 changes: 1 addition & 7 deletions govtool/frontend/src/consts/navItems.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IconAcademicCap } from "@intersect.mbo/intersectmbo.org-icons-set";
import { isDevEnv } from "@utils";
import i18n from "@/i18n";
import { theme } from "@/theme";

Expand Down Expand Up @@ -102,9 +101,4 @@ export const CONNECTED_NAV_ITEMS = [
icon: ICONS.faqsIcon,
newTabLink: "https://docs.sanchogov.tools/faqs",
},
].filter((item) => {
if (!isDevEnv && item.dataTestId === "proposal-discussion-link") {
return false;
}
return true;
});
];
17 changes: 10 additions & 7 deletions govtool/frontend/src/context/contextProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import { CardanoProvider, useCardano } from "./wallet";
import { ModalProvider, useModal } from "./modal";
import { SnackbarProvider, useSnackbar } from "./snackbar";
import { DataActionsBarProvider } from "./dataActionsBar";
import { FeatureFlagProvider } from "./featureFlag";

interface Props {
children: React.ReactNode;
}

const ContextProviders = ({ children }: Props) => (
<ModalProvider>
<SnackbarProvider>
<DataActionsBarProvider>
<CardanoProvider>{children}</CardanoProvider>
</DataActionsBarProvider>
</SnackbarProvider>
</ModalProvider>
<FeatureFlagProvider>
<ModalProvider>
<SnackbarProvider>
<DataActionsBarProvider>
<CardanoProvider>{children}</CardanoProvider>
</DataActionsBarProvider>
</SnackbarProvider>
</ModalProvider>
</FeatureFlagProvider>
);

export { ContextProviders, useCardano, useModal, useSnackbar };
44 changes: 44 additions & 0 deletions govtool/frontend/src/context/featureFlag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { PropsWithChildren, useMemo, createContext, useContext } from "react";

const FeatureFlagContext = createContext({
isProposalDiscussionForumEnabled: false,
});

/**
* Provides feature flag context to its children components.
*
* @param children - The child components to render.
*/
const FeatureFlagProvider = ({ children }: PropsWithChildren) => {
const value = useMemo(
() => ({
isProposalDiscussionForumEnabled:
import.meta.env.VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED === "true" ||
false,
}),
[],
);

return (
<FeatureFlagContext.Provider value={value}>
{children}
</FeatureFlagContext.Provider>
);
};

/**
* Custom hook that provides access to the feature flag context.
* Throws an error if used outside of a FeatureFlagProvider.
* @returns The feature flag context.
*/
const useFeatureFlag = () => {
const context = useContext(FeatureFlagContext);

if (!context) {
throw new Error("useFeatureFlag must be used within a FeatureFlagProvider");
}

return context;
};

export { FeatureFlagProvider, useFeatureFlag };
1 change: 1 addition & 0 deletions govtool/frontend/src/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from "./pendingTransaction";
export * from "./snackbar";
export * from "./usersnapContext";
export * from "./wallet";
export * from "./featureFlag";
1 change: 0 additions & 1 deletion govtool/frontend/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ export * from "./openInNewTab";
export * from "./removeDuplicatedProposals";
export * from "./testIdFromLabel";
export * from "./wait";
export * from "./isDevEnv";
3 changes: 0 additions & 3 deletions govtool/frontend/src/utils/isDevEnv.ts

This file was deleted.

Loading