-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[front] feat: display entity contexts on comparison page (#1858)
Co-authored-by: Adrien Matissart <amatissart@users.noreply.github.com>
- Loading branch information
1 parent
15a521b
commit b389f1c
Showing
7 changed files
with
264 additions
and
23 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
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
105 changes: 105 additions & 0 deletions
105
frontend/src/features/comparisons/ComparisonEntityContexts.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,105 @@ | ||
import React from 'react'; | ||
import { Trans, useTranslation } from 'react-i18next'; | ||
|
||
import { Grid, useTheme } from '@mui/material'; | ||
|
||
import EntityContextBox from 'src/features/entity_context/EntityContextBox'; | ||
import { SelectorValue } from 'src/features/entity_selector/EntitySelector'; | ||
import { useCurrentPoll } from 'src/hooks'; | ||
import { getEntityName } from 'src/utils/constants'; | ||
|
||
interface EntityContextBoxProps { | ||
selectorA: SelectorValue; | ||
selectorB: SelectorValue; | ||
} | ||
|
||
const ComparisonEntityContextsItem = ({ | ||
selector, | ||
altAssociationDisclaimer, | ||
}: { | ||
selector: SelectorValue; | ||
altAssociationDisclaimer?: React.ReactElement; | ||
}) => { | ||
return ( | ||
<> | ||
{selector.rating && selector.uid && selector.rating.entity_contexts && ( | ||
<EntityContextBox | ||
uid={selector.uid} | ||
contexts={selector.rating.entity_contexts} | ||
entityName={selector.rating?.entity?.metadata?.name} | ||
altAssociationDisclaimer={altAssociationDisclaimer} | ||
collapsible={true} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
const ComparisonEntityContexts = ({ | ||
selectorA, | ||
selectorB, | ||
}: EntityContextBoxProps) => { | ||
const theme = useTheme(); | ||
|
||
const { t } = useTranslation(); | ||
const { name: pollName } = useCurrentPoll(); | ||
|
||
const entityName = getEntityName(t, pollName); | ||
|
||
return ( | ||
<Grid | ||
container | ||
spacing={1} | ||
sx={{ | ||
'span.primary': { | ||
color: theme.palette.secondary.main, | ||
fontWeight: 'bold', | ||
textTransform: 'capitalize', | ||
}, | ||
}} | ||
> | ||
{selectorA.uid === selectorB.uid ? ( | ||
<Grid item xs={12}> | ||
<ComparisonEntityContextsItem selector={selectorA} /> | ||
</Grid> | ||
) : ( | ||
<> | ||
<Grid item xs={12} sm={12} md={6}> | ||
<ComparisonEntityContextsItem | ||
selector={selectorA} | ||
altAssociationDisclaimer={ | ||
<strong> | ||
<Trans | ||
t={t} | ||
i18nKey="entityContext.entityAtheAssociationWouldLikeToGiveYouContext" | ||
> | ||
<span className="primary">{{ entityName }} A</span> - The | ||
Tournesol association would like to give you some context. | ||
</Trans> | ||
</strong> | ||
} | ||
/> | ||
</Grid> | ||
<Grid item xs={12} sm={12} md={6}> | ||
<ComparisonEntityContextsItem | ||
selector={selectorB} | ||
altAssociationDisclaimer={ | ||
<strong> | ||
<Trans | ||
t={t} | ||
i18nKey="entityContext.entityBtheAssociationWouldLikeToGiveYouContext" | ||
> | ||
<span className="primary">{{ entityName }} B</span> - The | ||
Tournesol association would like to give you some context. | ||
</Trans> | ||
</strong> | ||
} | ||
/> | ||
</Grid> | ||
</> | ||
)} | ||
</Grid> | ||
); | ||
}; | ||
|
||
export default ComparisonEntityContexts; |
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
Oops, something went wrong.