-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Separate Upload components for maintainablity; fixed tabs height * Implemented loading state for file uploading * Implemented UploadFiles state management * Added component state * Normalized asset locations * Disabled controls while busy * Recovered folder uploading * Merged local files button * Recovered remote file * Rebased on progress * Removed unused create actions * Fixed loading message * Return file size from the server * Added large file size message * Removed unused dialog * Removed unused AdjustFile dialog * Removed unused IndexFiles dialog * Removed unused file actions * Validating -> Checking Errors * Fixed merging * Removed unused toPath prop from table/patch * Maked table/patch atomic action * Add SaveChanges process indication * Added TODO * Extracted updated_cells * Reconstruct previous errors * Fixed table saving shortcut
- Loading branch information
Showing
13 changed files
with
264 additions
and
115 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
63 changes: 63 additions & 0 deletions
63
client/components/Application/Dialogs/SaveChanges/SaveChanges.store.ts
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,63 @@ | ||
import { client } from '@client/client' | ||
import * as helpers from '@client/helpers' | ||
import * as appStore from '@client/store' | ||
|
||
// We use component level state because dialog state | ||
// needs to be shared between multiple components | ||
// but it is not needed in the global state | ||
class State { | ||
progress?: IProgress | ||
} | ||
|
||
type IProgress = { | ||
type: 'loading' | 'error' | ||
title?: string | ||
message?: string | ||
blocking?: boolean | ||
} | ||
|
||
export const { state, useState } = helpers.createState('SaveChangesDialog', new State()) | ||
|
||
export async function saveChanges() { | ||
const { grid } = appStore.getRefs() | ||
const { path, resource, table } = appStore.getState() | ||
if (!path || !grid || !table) return | ||
|
||
appStore.openDialog('saveChanges') | ||
state.progress = { | ||
type: 'loading', | ||
title: 'Saving the updated table', | ||
message: 'If the file is large, this may take some time...', | ||
blocking: true, | ||
} | ||
|
||
const appState = appStore.getState() | ||
const isTableUpdated = appStore.getIsTableUpdated(appState) | ||
const isResourceUpdated = appState.isResourceUpdated | ||
|
||
const result = await client.tablePatch({ | ||
path, | ||
history: isTableUpdated ? table.history : undefined, | ||
resource: isResourceUpdated ? resource : undefined, | ||
}) | ||
|
||
if (result instanceof client.Error) { | ||
state.progress = { | ||
type: 'error', | ||
title: 'Error saving changes', | ||
message: result.detail, | ||
} | ||
} | ||
|
||
await appStore.onFileUpdated([path]) | ||
grid.reload() | ||
|
||
state.progress = undefined | ||
closeDialog() | ||
} | ||
|
||
export function closeDialog() { | ||
if (!state.progress?.blocking) { | ||
appStore.closeDialog() | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
client/components/Application/Dialogs/SaveChanges/SaveChanges.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,47 @@ | ||
import NoButtonDialog from '@client/components/Parts/Dialogs/NoButton' | ||
import Box from '@mui/material/Box' | ||
import LinearProgress from '@mui/material/LinearProgress' | ||
import Stack from '@mui/material/Stack' | ||
import { startCase } from 'lodash' | ||
import * as store from './SaveChanges.store' | ||
|
||
export function SaveChangesDialog() { | ||
return ( | ||
<NoButtonDialog | ||
open={true} | ||
maxWidth="md" | ||
title="Saving Changes" | ||
onClose={store.closeDialog} | ||
> | ||
<ProgressIndicator /> | ||
</NoButtonDialog> | ||
) | ||
} | ||
|
||
// TODO: move to common components | ||
function ProgressIndicator() { | ||
const { progress } = store.useState() | ||
|
||
if (!progress) { | ||
return null | ||
} | ||
|
||
if (progress.type === 'error') { | ||
return <Box sx={{ color: 'red' }}>{progress.message}</Box> | ||
} | ||
|
||
return ( | ||
<Stack spacing={1}> | ||
<Box>{progress.title || startCase(progress.type)}...</Box> | ||
<LinearProgress | ||
sx={{ | ||
'& .MuiLinearProgress-bar': { | ||
backgroundColor: '#00D1FF', | ||
}, | ||
padding: '10px', | ||
}} | ||
/> | ||
<Box sx={{ color: 'gray' }}>{progress.message}</Box> | ||
</Stack> | ||
) | ||
} |
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,2 @@ | ||
export { SaveChangesDialog } from './SaveChanges' | ||
export * as saveChangesDialog from './SaveChanges.store' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import CloseIcon from '@mui/icons-material/Close' | ||
import Dialog, { DialogProps } from '@mui/material/Dialog' | ||
import DialogContent from '@mui/material/DialogContent' | ||
import DialogTitle from '@mui/material/DialogTitle' | ||
import IconButton from '@mui/material/IconButton' | ||
|
||
export default function NoButtonDialog( | ||
props: DialogProps & { title: string; onClose: () => void } | ||
) { | ||
const handleClose = () => { | ||
props.onClose() | ||
} | ||
|
||
return ( | ||
<Dialog | ||
fullWidth | ||
maxWidth={props.maxWidth} | ||
open={!!props.open} | ||
onClose={props.onClose} | ||
aria-labelledby={props.title} | ||
> | ||
<IconButton | ||
aria-label="close" | ||
onClick={handleClose} | ||
sx={{ | ||
position: 'absolute', | ||
right: 8, | ||
top: 8, | ||
color: (theme) => theme.palette.grey[500], | ||
}} | ||
> | ||
<CloseIcon /> | ||
</IconButton> | ||
<DialogTitle | ||
id="dialog-title" | ||
sx={{ | ||
paddingBottom: 1, | ||
marginBottom: 2, | ||
borderBottom: 'solid 1px #ddd', | ||
backgroundColor: (theme) => theme.palette.OKFNGray100.main, | ||
}} | ||
> | ||
{props.title} | ||
</DialogTitle> | ||
<DialogContent>{props.children}</DialogContent> | ||
</Dialog> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './actions' | ||
export { getRefs } from './actions/refs' | ||
export * from './state' | ||
export { getState, useStore } from './store' |
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.