-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
[front] feat: display entity contexts on comparison page #1858
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f45c2d9
[front] feat: display entity contexts on comparison page
GresilleSiffle affda52
[front] feat: display the entity name in the context box
GresilleSiffle ac1c565
[front] refactor: rename `title` to `disclaimer` in EntityContext
GresilleSiffle eb0d1a0
Merge branch 'main' into front-add_context_in_comparison
GresilleSiffle b5980f9
[front] fix: remove useless initializing ref in Comparison.tsx
GresilleSiffle 22884d1
Update frontend/src/features/entity_context/EntityContextBox.tsx
GresilleSiffle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this check on
initliazing.current
is useful here 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked and it's not useful, the
isLoading
check seems to be enough.