Skip to content

Commit 75853ad

Browse files
committed
OpenConceptLab/ocl_issues#2316 | moving notification/alert on top as snackbar
1 parent ee19cb2 commit 75853ad

2 files changed

Lines changed: 57 additions & 62 deletions

File tree

src/components/map-projects/Candidates.jsx

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import React from 'react'
44
import { useTranslation } from 'react-i18next';
5-
import Alert from '@mui/material/Alert';
6-
import Collapse from '@mui/material/Collapse';
75
import IconButton from '@mui/material/IconButton'
86
import ListSubheader from '@mui/material/ListSubheader';
97
import List from '@mui/material/List';
@@ -20,7 +18,6 @@ import Tooltip from '@mui/material/Tooltip'
2018

2119
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
2220
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
23-
import CloseIcon from '@mui/icons-material/Close';
2421
import FilterListIcon from '@mui/icons-material/FilterList';
2522
import RefreshIcon from '@mui/icons-material/Refresh';
2623
import SortIcon from '@mui/icons-material/Sort';
@@ -411,7 +408,7 @@ const CandidateList = ({rowViews, header, rowIndex, sortBy, order, openConceptPa
411408
// conceptCache — project-wide ConceptDefinition store, keyed by concept_key.
412409
// algosSelected — algorithm definitions (for headers/grouping).
413410
// (plans/unified-mapper-model.md "How the views map onto this model".)
414-
const Candidates = ({rowIndex, alert, setAlert, rowState, conceptCache, targetCanonical, targetRelativeUrl, openConceptPanel, showItem, isSelectedForMap, onMap, onFetchMore, isLoading, candidatesScore, repoVersion, analysis, onFetchRecommendation, appliedFacets, setAppliedFacets, filters, facets, columns, defaultFilters, locales, models, selectedModel, onModelChange, promptTemplates, promptTemplate, onPromptTemplateChange, onRefreshClick, rowStage, inAIAssistantGroup, algosSelected, isCoreUser}) => {
411+
const Candidates = ({rowIndex, rowState, conceptCache, targetCanonical, targetRelativeUrl, openConceptPanel, showItem, isSelectedForMap, onMap, onFetchMore, isLoading, candidatesScore, repoVersion, analysis, onFetchRecommendation, appliedFacets, setAppliedFacets, filters, facets, columns, defaultFilters, locales, models, selectedModel, onModelChange, promptTemplates, promptTemplate, onPromptTemplateChange, onRefreshClick, rowStage, inAIAssistantGroup, algosSelected, isCoreUser}) => {
415412
const { t } = useTranslation();
416413
const [sortBy, setSortBy] = React.useState('rerank_score')
417414
const [groupBy, setGroupBy] = React.useState('quality')
@@ -694,50 +691,32 @@ const Candidates = ({rowIndex, alert, setAlert, rowState, conceptCache, targetCa
694691

695692
return (
696693
<div className='col-xs-12 padding-0'>
697-
<Collapse in={Boolean(alert?.message)}>
698-
<Alert
699-
severity={alert?.severity || 'error'}
700-
action={
701-
<Button
702-
aria-label="close"
703-
color="inherit"
704-
size="small"
705-
onClick={() => setAlert(false)}
706-
>
707-
<CloseIcon fontSize="inherit" />
708-
</Button>
709-
}
710-
sx={{ mb: 2 }}
711-
>
712-
{alert.message}
713-
</Alert>
714-
</Collapse>
715-
<div className='col-xs-12 padding-0' style={{display: 'flex'}}>
716-
{
717-
!isEmpty(facets) &&
718-
<div className='col-xs-4 padding-0' style={openFilters ? {borderRight: '1px solid lightgray'} : {width: 0, display: 'none'}}>
719-
<SearchFilters
720-
open={openFilters}
721-
resource='concepts'
722-
filters={facets}
723-
appliedFilters={appliedFacets || {}}
724-
onChange={setAppliedFacets}
725-
repoDefaultFilters={filters}
726-
defaultFilters={defaultFilters}
727-
properties={repoVersion?.meta?.display?.concept_summary_properties}
728-
propertyFilters={repoVersion?.filters}
729-
heightToSubtract={523}
730-
columns={columns}
731-
/>
732-
</div>
733-
}
734-
<div className={openFilters ? 'col-xs-8' : 'col-xs-12'} style={{padding: 0, paddingLeft: openFilters ? '8px' : 0}}>
694+
<div className='col-xs-12 padding-0' style={{display: 'flex'}}>
735695
{
736-
noCandidatesFound &&
737-
<NoResults text='We could not find any candidates for this row.' height='300px' />
696+
!isEmpty(facets) &&
697+
<div className='col-xs-4 padding-0' style={openFilters ? {borderRight: '1px solid lightgray'} : {width: 0, display: 'none'}}>
698+
<SearchFilters
699+
open={openFilters}
700+
resource='concepts'
701+
filters={facets}
702+
appliedFilters={appliedFacets || {}}
703+
onChange={setAppliedFacets}
704+
repoDefaultFilters={filters}
705+
defaultFilters={defaultFilters}
706+
properties={repoVersion?.meta?.display?.concept_summary_properties}
707+
propertyFilters={repoVersion?.filters}
708+
heightToSubtract={523}
709+
columns={columns}
710+
/>
711+
</div>
738712
}
739-
<List
740-
sx={{
713+
<div className={openFilters ? 'col-xs-8' : 'col-xs-12'} style={{padding: 0, paddingLeft: openFilters ? '8px' : 0}}>
714+
{
715+
noCandidatesFound &&
716+
<NoResults text='We could not find any candidates for this row.' height='300px' />
717+
}
718+
<List
719+
sx={{
741720
marginTop: '4px',
742721
width: '100%',
743722
position: 'relative',
@@ -980,17 +959,17 @@ const Candidates = ({rowIndex, alert, setAlert, rowState, conceptCache, targetCa
980959
</>
981960
}
982961
</List>
983-
{
984-
onFetchMore && canFetchMore &&
985-
<div className='col-xs-12 padding-0' style={{textAlign: 'right', marginTop: '4px'}}>
986-
<Button disabled={isLoading} size='small' variant='text' sx={{textTransform: 'none'}} onClick={onFetchMore}>
987-
{isLoading ? t('map_project.fetching') : t('map_project.fetch_more')}
988-
</Button>
989-
</div>
990-
}
962+
{
963+
onFetchMore && canFetchMore &&
964+
<div className='col-xs-12 padding-0' style={{textAlign: 'right', marginTop: '4px'}}>
965+
<Button disabled={isLoading} size='small' variant='text' sx={{textTransform: 'none'}} onClick={onFetchMore}>
966+
{isLoading ? t('map_project.fetching') : t('map_project.fetch_more')}
967+
</Button>
968+
</div>
969+
}
970+
</div>
991971
</div>
992972
</div>
993-
</div>
994973

995974
)
996975
}

src/components/map-projects/MapProject.jsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import Chip from '@mui/material/Chip';
2020
import FormControl from '@mui/material/FormControl';
2121
import Tooltip from '@mui/material/Tooltip';
2222
import Alert from '@mui/material/Alert';
23-
import Collapse from '@mui/material/Collapse';
2423
import Divider from '@mui/material/Divider';
2524
import Dialog from '@mui/material/Dialog';
2625
import DialogActions from '@mui/material/DialogActions';
2726
import DialogContent from '@mui/material/DialogContent';
2827
import DialogTitle from '@mui/material/DialogTitle';
2928
import MenuItem from '@mui/material/MenuItem';
3029
import Select from '@mui/material/Select';
30+
import Snackbar from '@mui/material/Snackbar';
3131
import { DataGrid } from '@mui/x-data-grid';
3232

3333

@@ -240,6 +240,18 @@ const MapProject = () => {
240240
const [bulkConfirm, setBulkConfirm] = React.useState(false)
241241
const [bulkMapType, setBulkMapType] = React.useState('SAME-AS')
242242

243+
const alertDuration = React.useMemo(() => {
244+
if(!alert?.duration)
245+
return null
246+
return alert.duration < 100 ? alert.duration * 1000 : alert.duration
247+
}, [alert])
248+
249+
const onAlertClose = React.useCallback((_, reason) => {
250+
if(reason === 'clickaway')
251+
return
252+
setAlert(false)
253+
}, [])
254+
243255
// repo state
244256
const [repo, setRepo] = React.useState(false)
245257
const [repoVersion, setRepoVersion] = React.useState(false)
@@ -4987,9 +4999,15 @@ const MapProject = () => {
49874999
</Button>
49885000
</div>
49895001
}
4990-
<Collapse in={Boolean(alert?.message)}>
5002+
<Snackbar
5003+
open={Boolean(alert?.message)}
5004+
autoHideDuration={alertDuration}
5005+
onClose={onAlertClose}
5006+
anchorOrigin={{vertical: 'top', horizontal: 'center'}}
5007+
>
49915008
<Alert
49925009
severity={alert?.severity || 'error'}
5010+
onClose={onAlertClose}
49935011
action={
49945012
<IconButton
49955013
aria-label="close"
@@ -5000,11 +5018,11 @@ const MapProject = () => {
50005018
<CloseIcon fontSize="inherit" />
50015019
</IconButton>
50025020
}
5003-
sx={{ mb: 2 }}
5021+
sx={{ width: '100%' }}
50045022
>
5005-
{alert.message}
5023+
{alert?.message}
50065024
</Alert>
5007-
</Collapse>
5025+
</Snackbar>
50085026
<div style={{ width: '100%', height: project?.id ? 'calc(100vh - 263px)' : 'calc(100vh - 250px)' }}>
50095027
<DataGrid
50105028
onFilterModelChange={(model) => setFilterModel(model)}
@@ -5239,8 +5257,6 @@ const MapProject = () => {
52395257
candidatesScore={candidatesScore}
52405258
rowIndex={rowIndex}
52415259
rowStage={rowStageRef.current[rowIndex]}
5242-
alert={alert}
5243-
setAlert={setAlert}
52445260
rowState={rowMatchStateRef.current[rowIndex]}
52455261
conceptCache={conceptCache}
52465262
targetCanonical={buildProjectContext()?.target_repo?.canonical_url}

0 commit comments

Comments
 (0)