-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1506 from cphelefu/handling-layer-actions
Handling layer actions (#1506)
- Loading branch information
Showing
11 changed files
with
267 additions
and
43 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
9 changes: 9 additions & 0 deletions
9
packages/geoview-core/src/core/components/layers/left-panel/add-new-layer.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,9 @@ | ||
import { Paper } from '@/ui'; | ||
|
||
export function AddNewLayer(): JSX.Element { | ||
return ( | ||
<Paper sx={{ padding: '20px', display: 'flex', flexDirection: 'column' }}> | ||
<h3>This is the add new layer component</h3> | ||
</Paper> | ||
); | ||
} |
86 changes: 86 additions & 0 deletions
86
packages/geoview-core/src/core/components/layers/left-panel/delete-undo-button.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,86 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { Box, CircularProgressBase, DeleteOutlineIcon, IconButton, UndoIcon } from '@/ui'; | ||
import { TypeLegendLayer } from '../types'; | ||
import { useLayerStoreActions } from '@/core/stores/store-interface-and-intial-values/layer-state'; | ||
|
||
interface DeleteUndoButtonProps { | ||
layer: TypeLegendLayer; | ||
} | ||
|
||
interface UndoButtonProps { | ||
progressValue: number; | ||
onUndo: () => void; | ||
} | ||
|
||
function UndoButtonWithProgress(props: UndoButtonProps): JSX.Element { | ||
const { progressValue, onUndo } = props; | ||
return ( | ||
<Box sx={{ position: 'relative', display: 'inline-flex' }} onClick={onUndo}> | ||
<CircularProgressBase variant="determinate" size={40} value={progressValue} /> | ||
<Box | ||
style={{ | ||
top: 0, | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
position: 'absolute', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}} | ||
> | ||
<IconButton> | ||
<UndoIcon /> | ||
</IconButton> | ||
</Box> | ||
</Box> | ||
); | ||
} | ||
|
||
export function DeleteUndoButton(props: DeleteUndoButtonProps): JSX.Element { | ||
const { layer } = props; | ||
|
||
const [progress, setProgress] = useState(10); | ||
const [inUndoState, setInUndoState] = useState(false); | ||
|
||
// get store actions | ||
const { deleteLayer } = useLayerStoreActions(); | ||
|
||
const handleDeleteClick = () => { | ||
setInUndoState(true); | ||
}; | ||
|
||
const handleUndoClick = () => { | ||
setInUndoState(false); | ||
}; | ||
|
||
useEffect(() => { | ||
if (progress === 100) { | ||
deleteLayer(layer.layerPath); | ||
setInUndoState(false); | ||
} | ||
return undefined; | ||
}, [progress]); | ||
Check warning on line 63 in packages/geoview-core/src/core/components/layers/left-panel/delete-undo-button.tsx GitHub Actions / Build demo files / build-geoview
|
||
|
||
useEffect(() => { | ||
if (inUndoState) { | ||
const timer = setInterval(() => { | ||
setProgress((prevProgress) => (prevProgress >= 100 ? 0 : prevProgress + 5)); | ||
}, 250); | ||
return () => { | ||
clearInterval(timer); | ||
}; | ||
} | ||
setProgress(0); | ||
return undefined; | ||
}, [inUndoState]); | ||
|
||
if (!inUndoState) { | ||
return ( | ||
<IconButton onClick={handleDeleteClick}> | ||
<DeleteOutlineIcon color="error" /> | ||
</IconButton> | ||
); | ||
} | ||
return <UndoButtonWithProgress progressValue={progress} onUndo={handleUndoClick} />; | ||
} |
44 changes: 26 additions & 18 deletions
44
packages/geoview-core/src/core/components/layers/left-panel/layers-actions.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 |
---|---|---|
@@ -1,46 +1,54 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { useTheme } from '@mui/material/styles'; | ||
import { Button } from '@mui/material'; | ||
import { Box, Typography, Stack, ExpandIcon, RemoveCircleOutlineIcon, AddCircleOutlineIcon } from '@/ui'; | ||
import { Box, Typography, AddCircleOutlineIcon, ButtonGroup, DeleteOutlineIcon, HandleIcon } from '@/ui'; | ||
import { getSxClasses } from '../layers-style'; | ||
import { useLayerStoreActions, useLayersDisplayState } from '@/core/stores/store-interface-and-intial-values/layer-state'; | ||
import { TypeLayersViewDisplayState } from '../types'; | ||
|
||
export function LayersActions(): JSX.Element { | ||
const { t } = useTranslation<string>(); | ||
|
||
const theme = useTheme(); | ||
const sxClasses = getSxClasses(theme); | ||
|
||
// access store | ||
const displayState = useLayersDisplayState(); | ||
const { setDisplayState } = useLayerStoreActions(); | ||
|
||
const handleSetDisplayState = function (newState: TypeLayersViewDisplayState) { | ||
setDisplayState(newState); | ||
}; | ||
|
||
return ( | ||
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: '15px' }}> | ||
<div> | ||
<Typography sx={sxClasses.categoryTitle}>{t('general.layers')}</Typography> | ||
</div> | ||
<Stack style={{ alignItems: 'center', gap: '15px' }} direction="row"> | ||
|
||
<ButtonGroup size="small" variant="outlined" aria-label="outlined button group"> | ||
<Button | ||
variant="contained" | ||
size="small" | ||
sx={{ backgroundColor: '#F4F5FF', borderRadius: '20px' }} | ||
startIcon={<ExpandIcon fontSize="small" sx={{ color: '#515BA5' }} />} | ||
variant={displayState === 'add' ? 'contained' : 'outlined'} | ||
startIcon={<AddCircleOutlineIcon fontSize="small" />} | ||
onClick={() => handleSetDisplayState('add')} | ||
> | ||
<Typography sx={sxClasses.legendButtonText}>{t('legend.re-arrange')}</Typography> | ||
{t('general.add')} | ||
</Button> | ||
<Button | ||
variant="contained" | ||
size="small" | ||
sx={{ backgroundColor: '#F4F5FF', borderRadius: '20px' }} | ||
startIcon={<AddCircleOutlineIcon fontSize="small" sx={{ color: '#515BA5' }} />} | ||
variant={displayState === 'order' ? 'contained' : 'outlined'} | ||
startIcon={<HandleIcon fontSize="small" />} | ||
onClick={() => handleSetDisplayState('order')} | ||
> | ||
<Typography sx={sxClasses.legendButtonText}>{t('general.add')}</Typography> | ||
{t('legend.re-arrange')} | ||
</Button> | ||
<Button | ||
variant="contained" | ||
size="small" | ||
sx={{ backgroundColor: '#F4F5FF', borderRadius: '20px' }} | ||
startIcon={<RemoveCircleOutlineIcon fontSize="small" sx={{ color: '#515BA5' }} />} | ||
variant={displayState === 'remove' ? 'contained' : 'outlined'} | ||
startIcon={<DeleteOutlineIcon fontSize="small" />} | ||
onClick={() => handleSetDisplayState('remove')} | ||
> | ||
<Typography sx={sxClasses.legendButtonText}>{t('general.remove')}</Typography> | ||
{t('general.remove')} | ||
</Button> | ||
</Stack> | ||
</ButtonGroup> | ||
</Box> | ||
); | ||
} |
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.