From d4029f2d47f21df93f1296ad26582cbb2c879b15 Mon Sep 17 00:00:00 2001 From: frimpongopoku Date: Thu, 5 Dec 2024 11:31:11 +0000 Subject: [PATCH] custom pages now hidden under featuer flag --- app/api/ui/communityAdminMenu.js | 95 ++++++++++++++++++---------- app/api/ui/superAdminMenu.js | 2 +- app/components/FeatureFlags/flags.js | 1 + app/components/Sidebar/Sidebar.js | 79 +++++++++++------------ app/config/config.json | 2 +- app/utils/helpers.js | 71 +++++++++------------ 6 files changed, 130 insertions(+), 120 deletions(-) diff --git a/app/api/ui/communityAdminMenu.js b/app/api/ui/communityAdminMenu.js index 66bf83685..888710c70 100644 --- a/app/api/ui/communityAdminMenu.js +++ b/app/api/ui/communityAdminMenu.js @@ -203,24 +203,7 @@ const CADMIN_MENU = [ } ] }, - { - key: "custom-pages", - name: "Pages(Beta)", - icon: "ios-paper", - child: [ - // { - // key: "create-custom-page", - // name: "Create Page", - // link: APP_LINKS.PAGE_BUILDER_CREATE_OR_EDIT, - // target: "_blank" - // }, - { - key: "all-custom-pages", - name: "All My Custom Pages", - link: APP_LINKS.PAGE_BUILDER_VIEW_PAGES - } - ] - }, + { key: "settings", name: "Settings", @@ -235,31 +218,73 @@ const CADMIN_MENU = [ } ]; -let menuAttachmentsObj = {}; - -menuAttachmentsObj[FLAGS.BROADCAST_MESSAGING_FF] = { - appendTo: "messages", - value: [ - { - key: "send-message", - name: "Send Message", - link: "/admin/send/message" - }, - { - key: "scheduled-messages", - name: "Scheduled Messages", - link: "/admin/scheduled/messages" - } - ], - index: 1 +let menuAttachmentsObj = { + [FLAGS.BROADCAST_MESSAGING_FF]: { + appendTo: "messages", + value: [ + { + key: "send-message", + name: "Send Message", + link: "/admin/send/message" + }, + { + key: "scheduled-messages", + name: "Scheduled Messages", + link: "/admin/scheduled/messages" + } + ], + index: 1 + }, + [FLAGS.CUSTOM_PAGES]: { + index: 10, + value: [ + { + key: "custom-pages", + name: "Pages(Beta)", + icon: "ios-paper", + child: [ + // { + // key: "create-custom-page", + // name: "Create Page", + // link: APP_LINKS.PAGE_BUILDER_CREATE_OR_EDIT, + // target: "_blank" + // }, + { + key: "all-custom-pages", + name: "All My Custom Pages", + link: APP_LINKS.PAGE_BUILDER_VIEW_PAGES + } + ] + } + ] + } }; +// menuAttachmentsObj[FLAGS.BROADCAST_MESSAGING_FF] = { +// appendTo: "messages", +// value: [ +// { +// key: "send-message", +// name: "Send Message", +// link: "/admin/send/message" +// }, +// { +// key: "scheduled-messages", +// name: "Scheduled Messages", +// link: "/admin/scheduled/messages" +// } +// ], +// index: 1 +// }; + const hasAlreadyBeenAppended = (mainArray, bigObjArray) => { const idsA = bigObjArray.map((objA) => objA.key); return idsA.every((id) => mainArray.some((objB) => objB.key === id)); }; +// TODO: Rewrite this so that it is more readable, and it also handles the case where the item to be appended to is a child item (make it recurse?) const communityAdminMenu = ({ flags }) => { + console.log("LET SEE FLAGS", flags); if (!flags || flags?.length === 0) return CADMIN_MENU; flags.forEach((flag) => { diff --git a/app/api/ui/superAdminMenu.js b/app/api/ui/superAdminMenu.js index cfca7f0e1..badd5cdbe 100644 --- a/app/api/ui/superAdminMenu.js +++ b/app/api/ui/superAdminMenu.js @@ -237,7 +237,7 @@ module.exports = [ { key: "custom-pages", name: "Pages(Beta)", - icon: "ios-people", + icon: "ios-paper", child: [ // { // key: "create-custom-page", diff --git a/app/components/FeatureFlags/flags.js b/app/components/FeatureFlags/flags.js index 53c3b760a..a6578f6f0 100644 --- a/app/components/FeatureFlags/flags.js +++ b/app/components/FeatureFlags/flags.js @@ -16,5 +16,6 @@ export const FLAGS = { EVENT_NUDGE_FEATURE_FLAG_KEY : "user-event-nudge-feature-flag", CUSTOMIZE_NAVIGATION_MENU: "customize-navigation-menu-feature-flag", CUSTOMIZE_AUTO_SHARE_SETTINGS: "shared-testimonials-nudge-feature-flag", + CUSTOM_PAGES: "custom-pages-feature-flag", ...USER_PORTAL_FLAGS }; diff --git a/app/components/Sidebar/Sidebar.js b/app/components/Sidebar/Sidebar.js index cbcbced42..ad926d781 100755 --- a/app/components/Sidebar/Sidebar.js +++ b/app/components/Sidebar/Sidebar.js @@ -1,18 +1,18 @@ -import React, { Fragment } from 'react'; -import PropTypes from 'prop-types'; +import React, { Fragment } from "react"; +import PropTypes from "prop-types"; import { withStyles } from "@mui/styles"; -import { connect } from 'react-redux'; -import classNames from 'classnames'; -import Hidden from '@mui/material/Hidden'; -import Drawer from '@mui/material/Drawer'; -import SwipeableDrawer from '@mui/material/SwipeableDrawer'; -import dummy from 'dan-api/dummy/dummyContents'; -import { bindActionCreators } from 'redux'; -import styles from './sidebar-jss'; -import SidebarContent from './SidebarContent'; -import communityAdminMenu from '../../api/ui/communityAdminMenu'; -import superAdminMenu from '../../api/ui/superAdminMenu'; - +import { connect } from "react-redux"; +import classNames from "classnames"; +import Hidden from "@mui/material/Hidden"; +import Drawer from "@mui/material/Drawer"; +import SwipeableDrawer from "@mui/material/SwipeableDrawer"; +import dummy from "dan-api/dummy/dummyContents"; +import { bindActionCreators } from "redux"; +import styles from "./sidebar-jss"; +import SidebarContent from "./SidebarContent"; +import communityAdminMenu from "../../api/ui/communityAdminMenu"; +import superAdminMenu from "../../api/ui/superAdminMenu"; +import { mergeTwoArrOfObjs } from "../../utils/helpers"; class Sidebar extends React.Component { state = { @@ -25,24 +25,24 @@ class Sidebar extends React.Component { flagDarker = false; componentDidMount = () => { - window.addEventListener('scroll', this.handleScroll); - } + window.addEventListener("scroll", this.handleScroll); + }; componentWillUnmount() { - window.removeEventListener('scroll', this.handleScroll); + window.removeEventListener("scroll", this.handleScroll); } handleScroll = () => { const doc = document.documentElement; const scroll = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); - const newFlagDarker = (scroll > 30); + const newFlagDarker = scroll > 30; if (this.flagDarker !== newFlagDarker) { this.setState({ turnDarker: newFlagDarker }); this.flagDarker = newFlagDarker; } - } + }; - handleOpen = event => { + handleOpen = (event) => { this.setState({ anchorEl: event.currentTarget }); }; @@ -50,26 +50,24 @@ class Sidebar extends React.Component { this.setState({ anchorEl: null }); }; - handleChangeStatus = status => { + handleChangeStatus = (status) => { this.setState({ status }); this.handleClose(); - } - + }; render() { - const { - classes, - open, - toggleDrawerOpen, - loadTransition, - leftSidebar, - auth, - featureFlags, - } = this.props; + const { classes, open, toggleDrawerOpen, loadTransition, leftSidebar, auth, featureFlags } = this.props; const drawerWidth = 240; const { status, anchorEl, turnDarker } = this.state; - const dataMenu = auth && auth.is_super_admin ? superAdminMenu : communityAdminMenu({flags:auth?.feature_flags}); + let flagsTogether = auth?.feature_flags || []; + + // Merge the user specific flags and the community specific flags together + flagsTogether = auth?.admin_at?.reduce( + (acc, curr) => mergeTwoArrOfObjs(acc, curr?.feature_flags, "key"), + flagsTogether + ); + const dataMenu = auth && auth.is_super_admin ? superAdminMenu : communityAdminMenu({ flags: flagsTogether }); return ( @@ -100,11 +98,7 @@ class Sidebar extends React.Component { variant="permanent" onClose={toggleDrawerOpen} classes={{ - paper: classNames( - classes.drawer, - classes.drawerPaper, - !open ? classes.drawerPaperClose : "" - ), + paper: classNames(classes.drawer, classes.drawerPaper, !open ? classes.drawerPaperClose : "") }} open={open} anchor={leftSidebar ? "left" : "right"} @@ -135,7 +129,7 @@ Sidebar.propTypes = { loadTransition: PropTypes.func.isRequired, open: PropTypes.bool.isRequired, leftSidebar: PropTypes.bool, - dataMenu: PropTypes.array.isRequired, + dataMenu: PropTypes.array.isRequired }; Sidebar.defaultProps = { @@ -145,8 +139,11 @@ Sidebar.defaultProps = { function mapStateToProps(state) { return { auth: state.getIn(["auth"]), - featureFlags: state.getIn(["featureFlags"]), + featureFlags: state.getIn(["featureFlags"]) }; } -const SidebarMapped = connect(mapStateToProps, null)(Sidebar); +const SidebarMapped = connect( + mapStateToProps, + null +)(Sidebar); export default withStyles(styles)(SidebarMapped); diff --git a/app/config/config.json b/app/config/config.json index 761a14978..1220642ac 100644 --- a/app/config/config.json +++ b/app/config/config.json @@ -2,5 +2,5 @@ "IS_LOCAL": false, "IS_PROD": false, "IS_CANARY": false, - "BUILD_VERSION": "4.16.17" + "BUILD_VERSION": "4.16.18" } diff --git a/app/utils/helpers.js b/app/utils/helpers.js index 8042c9429..f557373d5 100644 --- a/app/utils/helpers.js +++ b/app/utils/helpers.js @@ -1,10 +1,17 @@ import { IS_CANARY, IS_LOCAL, IS_PROD } from "../config/constants"; import { apiCall } from "./messenger"; -import { DEFAULT_ITEMS_PER_PAGE } from './constants'; +import { DEFAULT_ITEMS_PER_PAGE } from "./constants"; import { parseJSON } from "./common"; const TABLE_PROPERTIES = "_TABLE_PROPERTIES"; const FILTERS = "_FILTERS"; +export const mergeTwoArrOfObjs = (arr1, arr2, key) => { + let obj = {}; + arr1.forEach((item) => (obj[item[key]] = item)); + arr2.forEach((item) => (obj[item[key]] = item)); + return Object.values(obj); +}; + export const getSearchText = (key) => { var tableProp = localStorage.getItem(key + TABLE_PROPERTIES); tableProp = parseJSON(tableProp || null) || {}; @@ -24,12 +31,7 @@ export const getFilterParamsFromLocalStorage = (key) => { Object.values(tableProp).forEach((value) => { if (value.list.length) { - filters[ - value && - value.name && - value.name.toLowerCase && - value.name.toLowerCase() - ] = value.list; + filters[value && value.name && value.name.toLowerCase && value.name.toLowerCase()] = value.list; } }); return filters; @@ -42,7 +44,6 @@ export const getFilterData = (data, existing = [], field = "id") => { return unique; }; - const getSavedSortParamsFromLocalStorage = (key) => { let tableProp = localStorage.getItem(key + TABLE_PROPERTIES); tableProp = parseJSON(tableProp || null) || {}; @@ -54,21 +55,13 @@ export const prepareFilterAndSearchParamsFromLocal = (key) => { let params = JSON.stringify({ ...filterParams, search_text: getSearchText(key) || "", - sort_params: getSavedSortParamsFromLocalStorage(key) || {}, + sort_params: getSavedSortParamsFromLocalStorage(key) || {} }); return params; }; -export const makeAPICallForMoreData = ({ - apiUrl, - existing, - updateRedux, - args, - name, - updateMetaData, - meta, -}) => { +export const makeAPICallForMoreData = ({ apiUrl, existing, updateRedux, args, name, updateMetaData, meta }) => { apiCall(apiUrl, args).then((res) => { if (res.success) { let data = getFilterData(res, existing); @@ -84,22 +77,17 @@ export const generateFilterParams = (items, columns) => { .map((item, index) => { return { name: columns[index].name, - val: item, + val: item }; }) .filter((item) => item.val.length > 0) - .reduce( - (acc, curr) => ((acc[curr["name"].toLowerCase()] = curr.val), acc), - {} - ); + .reduce((acc, curr) => ((acc[curr["name"].toLowerCase()] = curr.val), acc), {}); }; export const getAdminApiEndpoint = (auth, base) => { let url = base; const isSuperAdmin = auth && auth.is_super_admin; - return isSuperAdmin - ? `${url}.listForSuperAdmin` - : `${url}.listForCommunityAdmin`; + return isSuperAdmin ? `${url}.listForSuperAdmin` : `${url}.listForCommunityAdmin`; }; const callMoreData = ( @@ -113,7 +101,7 @@ const callMoreData = ( updateMetaData, meta, otherArgs, - customLimit, + customLimit ) => { let filterParams = getFilterParamsFromLocalStorage(pageProp.key); makeAPICallForMoreData({ @@ -126,13 +114,13 @@ const callMoreData = ( params: JSON.stringify({ ...filterParams, search_text: getSearchText(pageProp.key) || "", - sort_params: sortBy, + sort_params: sortBy }), - ...(otherArgs || {}), + ...(otherArgs || {}) }, name, updateMetaData, - meta, + meta }); }; @@ -147,7 +135,7 @@ export const onTableStateChange = ({ name, updateMetaData, meta, - otherArgs, + otherArgs }) => { switch (action) { case "changePage": @@ -178,10 +166,10 @@ export const onTableStateChange = ({ name, updateMetaData, meta, - otherArgs, + otherArgs ); break; - + default: } }; @@ -193,14 +181,14 @@ const convertToLocalFormat = (filterList, columns) => { columns.forEach((column, index) => { let newColumn = { ...column, - options: { ...column.options, filterList: filterList[index] }, + options: { ...column.options, filterList: filterList[index] } }; newColumns.push(newColumn); let filter = { name: column.name, type: column.options.filterType || "", - list: filterList[index], + list: filterList[index] }; obj = { ...(obj || {}), [index]: filter }; }); @@ -219,14 +207,14 @@ export const handleFilterChange = ({ meta, name, updateMetaData, - otherArgs, + otherArgs }) => { if (type === "chip" || type === "custom") { let arr = generateFilterParams(filterList, columns); apiCall(url, { params: JSON.stringify(arr), limit: getLimit(page.key), - ...(otherArgs || {}), + ...(otherArgs || {}) }).then((res) => { if (res && res.success) { let filterData = getFilterData(res, reduxItems, "id"); @@ -247,13 +235,12 @@ export const removeDuplicates = (first, second) => { return uniqueItems; }; -export const getOrigin = ()=>{ - if(IS_PROD) return "https://api.massenergize.org" +export const getOrigin = () => { + if (IS_PROD) return "https://api.massenergize.org"; else if (IS_CANARY) return "https://api-canary.massenergize.org"; - else if(IS_LOCAL) return "http://127.0.0.1:8000"; + else if (IS_LOCAL) return "http://127.0.0.1:8000"; return "https://api.massenergize.dev"; -} - +}; export function sortByField(arr, field) { return arr.sort((a, b) => {