-
Notifications
You must be signed in to change notification settings - Fork 66
feat(rtk): position saving and reloading #104
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
Open
zarcell
wants to merge
74
commits into
skybrush-io:dev
Choose a base branch
from
zarcell:rtk-savepos
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
ab7a235
feat(rtk): add saved coord restoration, initial commit, review required
zarcell 2981b3c
chore: prettier and xo fixes
zarcell 89c7528
fix: remove unused function
zarcell cfb4612
fix: format dialog text
zarcell acdb11d
fix: align slice dialog state with types
zarcell d65737e
fix(rtk): cleaner dialog, update accuracy, delete rtk from balcklist …
zarcell 4cb8f3c
feat(rtk): improve saved coordinate management and restoration flow
zarcell e70b142
fix(rtk): remove temporary delete button
zarcell a84a034
fix(rtk): xo complaints
zarcell 4d4f601
Merge branch 'dev' into rtk-savepos
zarcell 3080a5e
chore(rtk): migrate RTK dialog to MUI v5 and add types
zarcell 7acf399
fix(rtk): improve saved coordinate dialog appearance and title
zarcell 840e3c5
feat(rtk): move coordinate restoration button to antenna position ind…
zarcell 753944b
Merge branch 'dev' into rtk-savepos
zarcell d112af3
fix(rtk): hide restore button tooltip on focus
zarcell 029ede3
feat(rtk): show preset title in save coordinate toast
zarcell 80d9b3b
fix(rtk): fix coordinate check logic and cleanup fake data
zarcell fe8d3d0
fix(rtk): xo problems
zarcell 0bb9b26
fix: accidental change
zarcell a0b953f
fix: cleaner placement instead of hacky margin
zarcell 8f16dc0
fix: make SavedCoordinateItem a presentational component
zarcell fef235a
fix: use formatDistance from utils
zarcell 60641a6
fix: sort alphabetically
zarcell 868ad9f
fix: removed the redundant early return check
zarcell 9b3b351
fix: use BackgroundHint
zarcell b9724dd
add: comment to explain why we dont need focus there
zarcell 3a3d9e7
add: void operator to explicitly ignore promise in handleUseSaved
zarcell 8807df2
fix: use general.action.cancel translation key
zarcell 98e0b88
fix: sort
zarcell 8ea1489
fix: prefer nullish coalescing
zarcell 5efe0ae
refactor: keep the original logic
zarcell 8335d86
fix: sort
zarcell 627058c
fix: sort
zarcell aa7867b
fix: sorted
zarcell c77cc4b
fix: sorted
zarcell 7a7e92c
fix: added optional chaining
zarcell 9654fb3
fix: replaced the ternary with logical expression
zarcell 75f852a
fix: simplified the prop assignment
zarcell 744be83
fix: sort imports
zarcell 4621a02
fix: use selector
zarcell a5cf8c1
refactor: flag check in hasValidFix
zarcell 936770d
fix: remove undifined (never happens)
zarcell aa83d15
fix: sort
zarcell 90d393e
fix: sort
zarcell 92e5588
refactor: show RTK preset notifications even after dialog closes
zarcell db7f4d7
fix: nullish coalescing
zarcell 935f4df
Update src/features/rtk/selectors.ts
zarcell c5edddf
fix: remove leftover function
zarcell 622444d
refactor: rtk saved coordinate selector to return formatter
zarcell 9e51aaa
add: icon to visualize clickability
zarcell 1f58834
refactor: ECEF coordinate formatting into shared helper
zarcell 570f2e7
chore: rename function
zarcell 206f11c
chore: sort
zarcell 99b0d5a
fix: optional property
zarcell 0a7f820
fix: optional property
zarcell a35fbf7
fix: use nullish coalescing assignment
zarcell 1929000
refactor: use isEqual from lodash
zarcell e4cf2e0
refactor: use isEqual here too
zarcell 556dc18
fix: just let it be
zarcell d624797
fix: remove leftover function
zarcell 5969c03
chore: sort
zarcell 02f85e6
refactor: change to conjunction
zarcell 29f847a
refactor: replaced the ternary with a logical expression
zarcell dbc8de0
refactor: use Coordinate3D
zarcell 4deb7c9
chore: sort
zarcell 4c4c2e8
chore: longer is better than larger :)
zarcell 641b089
fix: update title
zarcell be2dd26
chore: remove a11y attributes as discussed earlier
isti115 db9da5d
refactor: nullish coalescing operator
zarcell 91796cc
Merge branch 'rtk-savepos' of github.com:zarcell/live into rtk-savepos
zarcell 0792630
chore: add changelog entry
isti115 f848288
chore: apply automatic formatting fixes
isti115 be774b8
fixup! chore: prettier and xo fixes
isti115 1e0db03
Merge branch 'dev' into rtk-savepos
zarcell 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,132 @@ | ||
| import formatDate from 'date-fns/format'; | ||
| import PropTypes from 'prop-types'; | ||
| import React from 'react'; | ||
| import { withTranslation } from 'react-i18next'; | ||
| import { connect } from 'react-redux'; | ||
|
|
||
| import Box from '@mui/material/Box'; | ||
| import Button from '@mui/material/Button'; | ||
| import Dialog from '@mui/material/Dialog'; | ||
| import DialogActions from '@mui/material/DialogActions'; | ||
| import DialogContent from '@mui/material/DialogContent'; | ||
| import DialogTitle from '@mui/material/DialogTitle'; | ||
| import List from '@mui/material/List'; | ||
| import ListItem from '@mui/material/ListItem'; | ||
| import ListItemButton from '@mui/material/ListItemButton'; | ||
| import ListItemText from '@mui/material/ListItemText'; | ||
|
|
||
| import { BackgroundHint } from '@skybrush/mui-components'; | ||
|
|
||
| import { closeCoordinateRestorationDialog } from '~/features/rtk/slice'; | ||
| import { | ||
| getCoordinateRestorationDialogState, | ||
| getPreferredSavedRTKPositionFormatter, | ||
| getSavedCoordinatesForPreset, | ||
| } from '~/features/rtk/selectors'; | ||
| import { useSavedCoordinateForPreset } from '~/features/rtk/actions'; | ||
| import Download from '~/icons/Download'; | ||
| import { formatDistance } from '~/utils/formatting'; | ||
|
|
||
| const SavedCoordinateItem = ({ coordinate, coordinateFormatter, onClick }) => { | ||
| const { accuracy, savedAt } = coordinate; | ||
| const savedDateTime = formatDate(new Date(savedAt), 'yyyy-MM-dd HH:mm:ss'); | ||
|
|
||
| const formattedPosition = coordinateFormatter(coordinate); | ||
|
|
||
| return ( | ||
| <ListItem disablePadding> | ||
| <ListItemButton onClick={() => onClick(coordinate)}> | ||
zarcell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Box | ||
| sx={{ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'space-between', | ||
| width: '100%', | ||
| }} | ||
| > | ||
| <ListItemText | ||
| primary={formattedPosition} | ||
| secondary={`Accuracy: ${formatDistance(accuracy, 3)} • ${savedDateTime}`} | ||
| /> | ||
| <Download sx={{ marginLeft: 2 }} /> | ||
| </Box> | ||
| </ListItemButton> | ||
| </ListItem> | ||
| ); | ||
| }; | ||
|
|
||
| const RTKCoordinateRestorationDialog = ({ | ||
| coordinateFormatter, | ||
| dialog, | ||
| onClose, | ||
| onUseSaved, | ||
| savedCoordinates, | ||
| t, | ||
| }) => { | ||
| const { presetId } = dialog; | ||
|
|
||
| const handleUseSaved = (coordinate) => { | ||
| onClose(); // Close dialog first | ||
| void onUseSaved(presetId, coordinate); // Then start async operation | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog fullWidth open={dialog.open} maxWidth='sm' onClose={onClose}> | ||
| <DialogTitle>{t('RTKCoordinateRestorationDialog.title')}</DialogTitle> | ||
| <DialogContent> | ||
| <Box> | ||
| {savedCoordinates.length === 0 ? ( | ||
| <BackgroundHint | ||
| text={t('RTKCoordinateRestorationDialog.noSavedCoordinates')} | ||
| /> | ||
| ) : ( | ||
| <List> | ||
| {savedCoordinates.map((coordinate) => ( | ||
| <SavedCoordinateItem | ||
| key={coordinate.savedAt} | ||
| coordinate={coordinate} | ||
| coordinateFormatter={coordinateFormatter} | ||
| onClick={handleUseSaved} | ||
| /> | ||
| ))} | ||
| </List> | ||
| )} | ||
| </Box> | ||
| </DialogContent> | ||
| <DialogActions> | ||
| <Button color='primary' onClick={onClose}> | ||
| {t('general.action.cancel')} | ||
| </Button> | ||
| </DialogActions> | ||
| </Dialog> | ||
| ); | ||
| }; | ||
|
|
||
| RTKCoordinateRestorationDialog.propTypes = { | ||
| coordinateFormatter: PropTypes.func, | ||
| dialog: PropTypes.object, | ||
| onClose: PropTypes.func, | ||
| onUseSaved: PropTypes.func, | ||
| savedCoordinates: PropTypes.array, | ||
| t: PropTypes.func, | ||
| }; | ||
|
|
||
| export default connect( | ||
| (state) => { | ||
| const dialog = getCoordinateRestorationDialogState(state); | ||
|
|
||
| const coordinateFormatter = getPreferredSavedRTKPositionFormatter(state); | ||
|
|
||
| return { | ||
| dialog, | ||
| savedCoordinates: dialog.presetId | ||
| ? getSavedCoordinatesForPreset(state, dialog.presetId) | ||
| : [], | ||
| coordinateFormatter, | ||
| }; | ||
| }, | ||
| { | ||
| onClose: closeCoordinateRestorationDialog, | ||
| onUseSaved: useSavedCoordinateForPreset, | ||
| } | ||
| )(withTranslation()(RTKCoordinateRestorationDialog)); | ||
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.