Skip to content

Commit

Permalink
Merge pull request #2325 from Plant-for-the-Planet-org/feature/salesf…
Browse files Browse the repository at this point in the history
…orce-projectListcontrol-tab

feat: avoid rendering project tabs for Salesforce tenant
  • Loading branch information
mohitb35 authored Dec 10, 2024
2 parents 0110f3d + 557428a commit 95eb9c8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface ProjectListControlForMobileProps {
filteredProjects: MapProject[] | undefined;
mapOptions: MapOptions;
updateMapOption: (option: keyof MapOptions, value: boolean) => void;
shouldHideProjectTabs: boolean;
}

const ProjectListControlForMobile = ({
Expand All @@ -52,14 +53,15 @@ const ProjectListControlForMobile = ({
setIsSearching,
mapOptions,
updateMapOption,
shouldHideProjectTabs,
}: ProjectListControlForMobileProps) => {
const [isFilterOpen, setIsFilterOpen] = useState(false);
const tAllProjects = useTranslations('AllProjects');
const { isImpersonationModeOn } = useUserProps();
const hasFilterApplied = selectedClassification.length > 0;
const shouldDisplayFilterResults = hasFilterApplied && selectedMode !== 'map';
const shouldDisplayProjectListTab =
!hasFilterApplied && selectedMode !== 'map';
!hasFilterApplied && selectedMode !== 'map' && !shouldHideProjectTabs;
const shouldDisplayMapFeatureExplorer = selectedMode === 'map';
const projectListControlsMobileClasses = `${
styles.projectListControlsMobile
Expand Down
38 changes: 27 additions & 11 deletions src/features/projectsV2/ProjectListControls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { SetState } from '../../common/types/common';
import type { TreeProjectClassification } from '@planet-sdk/common';
import type { MapProject } from '../../common/types/projectv2';

import { useState } from 'react';
import { useMemo, useState } from 'react';
import { useTranslations } from 'next-intl';
import styles from './styles/ProjectListControls.module.scss';
import ActiveSearchField from './microComponents/ActiveSearchField';
Expand All @@ -22,6 +22,7 @@ export interface ProjectListControlsProps {
debouncedSearchValue: string;
setDebouncedSearchValue: SetState<string>;
filteredProjects: MapProject[] | undefined;
shouldHideProjectTabs: boolean;
}
const ProjectListControls = ({
projectCount,
Expand All @@ -33,11 +34,12 @@ const ProjectListControls = ({
debouncedSearchValue,
setDebouncedSearchValue,
filteredProjects,
shouldHideProjectTabs,
}: ProjectListControlsProps) => {
const [isFilterOpen, setIsFilterOpen] = useState(false);
const [isSearching, setIsSearching] = useState(false);
const tAllProjects = useTranslations('AllProjects');

const tCommon = useTranslations('Common');
const hasFilterApplied = selectedClassification.length > 0;

const projectListTabProps = {
Expand Down Expand Up @@ -65,21 +67,35 @@ const ProjectListControls = ({
setSelectedClassification,
};

const renderTabContent = useMemo(() => {
if (hasFilterApplied) {
return (
<div className={styles.filterResultContainer}>
{tAllProjects('filterResult', {
count: filteredProjects?.length,
})}
</div>
);
}

if (shouldHideProjectTabs) {
return (
<h2 className={styles.projectListHeaderText}>
{tCommon('stopTalkingStartPlanting')}
</h2>
);
}

return <ProjectListTabLargeScreen {...projectListTabProps} />;
}, [hasFilterApplied, shouldHideProjectTabs, filteredProjects]);

return (
<>
{isSearching ? (
<ActiveSearchField {...activeSearchFieldProps} />
) : (
<div className={styles.projectListControls}>
{hasFilterApplied ? (
<div className={styles.filterResultContainer}>
{tAllProjects('filterResult', {
count: filteredProjects?.length,
})}
</div>
) : (
<ProjectListTabLargeScreen {...projectListTabProps} />
)}
{renderTabContent}
<SearchAndFilter {...searchAndFilterProps} />
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
}
}
}

.projectListHeaderText {
font-weight: 600;
margin-left: 20px;
}
.tabsContainer,
.projectListControlsMobile {
display: flex;
Expand Down
4 changes: 4 additions & 0 deletions src/features/projectsV2/ProjectsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ProjectListControlForMobile from './ProjectListControls/ProjectListContro
import ProjectList from './ProjectList';
import { useProjectsMap } from './ProjectsMapContext';
import ProjectsListMeta from '../../utils/getMetaTags/ProjectsListMeta';
import { useTenant } from '../common/Layout/TenantContext';

interface ProjectsSectionProps {
isMobile: boolean;
Expand All @@ -31,6 +32,8 @@ const ProjectsSection = ({ isMobile }: ProjectsSectionProps) => {
} = useProjects();
const { mapOptions, updateMapOption } = useProjectsMap();
const [tabSelected, setTabSelected] = useState<ProjectTabs>('topProjects');
const { tenantConfig } = useTenant();
const shouldHideProjectTabs = tenantConfig.topProjectsOnly === true;
if ((isLoading || isError) && filteredProjects?.length === 0) {
return <Skeleton className={styles.projectSectionSkeleton} />;
}
Expand All @@ -47,6 +50,7 @@ const ProjectsSection = ({ isMobile }: ProjectsSectionProps) => {
debouncedSearchValue,
setDebouncedSearchValue,
filteredProjects,
shouldHideProjectTabs,
};
const projectListControlMobileProps = {
debouncedSearchValue,
Expand Down

0 comments on commit 95eb9c8

Please sign in to comment.