-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Callouts preview accordion on SubspacesList default subspace temp…
…late selector (#7325) * Add Callouts preview accordion on SubspacesList default subspace template selector * usememo * memoize the Description component --------- Co-authored-by: Valentin Yanakiev <[email protected]>
- Loading branch information
1 parent
e6bc6de
commit 42b3f96
Showing
6 changed files
with
190 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/domain/collaboration/callout/CalloutsPreview/InnovationFlowCalloutsPreview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { memo, useMemo, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Accordion, AccordionDetails, AccordionSummary, Box, styled } from '@mui/material'; | ||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; | ||
import RoundedIcon from '@/core/ui/icon/RoundedIcon'; | ||
import { gutters } from '@/core/ui/grid/utils'; | ||
import { CalloutType } from '@/core/apollo/generated/graphql-schema'; | ||
import WrapperMarkdown from '@/core/ui/markdown/WrapperMarkdown'; | ||
import { Text, CaptionSmall } from '@/core/ui/typography'; | ||
import { getCalloutTypeIcon } from '@/domain/collaboration/callout/calloutCard/calloutIcons'; | ||
import WhiteboardPreview from '@/domain/collaboration/whiteboard/WhiteboardPreview/WhiteboardPreview'; | ||
|
||
type CalloutPreview = { | ||
id: string; | ||
type: CalloutType; | ||
framing: { | ||
profile: { | ||
displayName: string; | ||
description?: string; | ||
flowStateTagset?: { | ||
tags: string[]; | ||
}; | ||
}; | ||
whiteboard?: { | ||
profile: { | ||
preview?: { | ||
uri: string; | ||
}; | ||
}; | ||
}; | ||
}; | ||
sortOrder: number; | ||
}; | ||
|
||
export interface InnovationFlowCalloutsPreviewProps { | ||
selectedState: string | undefined; | ||
callouts: CalloutPreview[] | undefined; | ||
loading?: boolean; | ||
} | ||
|
||
const StyledAccordion = styled(Accordion)(({ theme }) => ({ | ||
border: `1px solid ${theme.palette.divider}`, | ||
borderRadius: theme.shape.borderRadius, | ||
marginBottom: gutters(1)(theme), | ||
boxShadow: 'none', | ||
})); | ||
|
||
const CalloutDescription = memo(({ callout }: { callout: CalloutPreview }) => { | ||
const { t } = useTranslation(); | ||
|
||
switch (callout.type) { | ||
case CalloutType.Whiteboard: | ||
case CalloutType.WhiteboardCollection: | ||
if (callout.framing.whiteboard?.profile.preview?.uri) { | ||
return ( | ||
<WhiteboardPreview | ||
whiteboard={callout.framing.whiteboard} | ||
displayName={callout.framing.profile.displayName} | ||
/> | ||
); | ||
} | ||
return null; | ||
default: | ||
return callout.framing.profile.description?.trim() ? ( | ||
<WrapperMarkdown>{callout.framing.profile.description}</WrapperMarkdown> | ||
) : ( | ||
<CaptionSmall>{t('common.noDescription')}</CaptionSmall> | ||
); | ||
} | ||
}); | ||
|
||
const InnovationFlowCalloutsPreview = ({ callouts, selectedState, loading }: InnovationFlowCalloutsPreviewProps) => { | ||
const [selectedCallout, setSelectedCallout] = useState<string | false>(false); | ||
const handleSelectedCalloutChange = (calloutId: string) => (_event, isExpanded: boolean) => | ||
setSelectedCallout(isExpanded ? calloutId : false); | ||
|
||
const visibleCallouts = useMemo(() => { | ||
return callouts | ||
?.filter( | ||
callout => | ||
selectedState && | ||
callout.framing.profile.flowStateTagset?.tags && | ||
callout.framing.profile.flowStateTagset?.tags.includes(selectedState) | ||
) | ||
.sort((a, b) => a.sortOrder - b.sortOrder); | ||
}, [callouts, selectedState]); | ||
|
||
return ( | ||
<> | ||
{!loading && visibleCallouts && ( | ||
<Box> | ||
{visibleCallouts.map(callout => { | ||
return ( | ||
<StyledAccordion | ||
key={callout.id} | ||
expanded={selectedCallout === callout.id} | ||
onChange={handleSelectedCalloutChange(callout.id)} | ||
> | ||
<AccordionSummary expandIcon={<ExpandMoreIcon />}> | ||
<RoundedIcon | ||
size="small" | ||
component={getCalloutTypeIcon({ type: callout.type, contributionPolicy: undefined })} | ||
/> | ||
<Text marginLeft={gutters()}>{callout.framing.profile.displayName}</Text> | ||
</AccordionSummary> | ||
<AccordionDetails> | ||
{selectedCallout === callout.id && <CalloutDescription callout={callout} />} | ||
</AccordionDetails> | ||
</StyledAccordion> | ||
); | ||
})} | ||
</Box> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default InnovationFlowCalloutsPreview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters