-
Notifications
You must be signed in to change notification settings - Fork 887
chore(site): Use react-query and refactor the workspaces page to use it #5838
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f591887
chore: Use react-query
BrunoQuaresma 5ef8460
chore: Use react-query and refactor workspaces page
BrunoQuaresma d9dcf07
Update depds
BrunoQuaresma ee7da80
Update providers in test
BrunoQuaresma 8cf28a6
Remove unused func
BrunoQuaresma d8db704
Handle update version error
BrunoQuaresma 5da5438
Fix empty message
BrunoQuaresma 241d360
Add i18n provider for tests
BrunoQuaresma 0a6ea09
Remoove global snackbar from providers
BrunoQuaresma 4f4638e
Fix empty states
BrunoQuaresma 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 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
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 |
---|---|---|
@@ -1,26 +1,46 @@ | ||
import CssBaseline from "@material-ui/core/CssBaseline" | ||
import ThemeProvider from "@material-ui/styles/ThemeProvider" | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query" | ||
import { AuthProvider } from "components/AuthProvider/AuthProvider" | ||
import { FC } from "react" | ||
import { FC, PropsWithChildren } from "react" | ||
import { HelmetProvider } from "react-helmet-async" | ||
import { AppRouter } from "./AppRouter" | ||
import { ErrorBoundary } from "./components/ErrorBoundary/ErrorBoundary" | ||
import { GlobalSnackbar } from "./components/GlobalSnackbar/GlobalSnackbar" | ||
import { dark } from "./theme" | ||
import "./theme/globalFonts" | ||
|
||
export const App: FC = () => { | ||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
cacheTime: 0, | ||
}, | ||
}, | ||
}) | ||
|
||
export const AppProviders: FC<PropsWithChildren> = ({ children }) => { | ||
return ( | ||
<HelmetProvider> | ||
<ThemeProvider theme={dark}> | ||
<CssBaseline /> | ||
<ErrorBoundary> | ||
<AuthProvider> | ||
<AppRouter /> | ||
<GlobalSnackbar /> | ||
</AuthProvider> | ||
<QueryClientProvider client={queryClient}> | ||
<AuthProvider> | ||
{children} | ||
<GlobalSnackbar /> | ||
</AuthProvider> | ||
</QueryClientProvider> | ||
</ErrorBoundary> | ||
</ThemeProvider> | ||
</HelmetProvider> | ||
) | ||
} | ||
|
||
export const App: FC = () => { | ||
return ( | ||
<AppProviders> | ||
<AppRouter /> | ||
</AppProviders> | ||
) | ||
} |
104 changes: 104 additions & 0 deletions
104
site/src/components/PaginationWidget/PaginationWidgetBase.tsx
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,104 @@ | ||
import Button from "@material-ui/core/Button" | ||
import { makeStyles, useTheme } from "@material-ui/core/styles" | ||
import useMediaQuery from "@material-ui/core/useMediaQuery" | ||
import KeyboardArrowLeft from "@material-ui/icons/KeyboardArrowLeft" | ||
import KeyboardArrowRight from "@material-ui/icons/KeyboardArrowRight" | ||
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne" | ||
import { PageButton } from "./PageButton" | ||
import { buildPagedList } from "./utils" | ||
|
||
export type PaginationWidgetBaseProps = { | ||
count: number | ||
page: number | ||
limit: number | ||
onChange: (page: number) => void | ||
} | ||
|
||
export const PaginationWidgetBase = ({ | ||
code-asher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
count, | ||
page, | ||
limit, | ||
onChange, | ||
}: PaginationWidgetBaseProps): JSX.Element | null => { | ||
const theme = useTheme() | ||
const isMobile = useMediaQuery(theme.breakpoints.down("sm")) | ||
const styles = useStyles() | ||
const numPages = Math.ceil(count / limit) | ||
const isFirstPage = page === 0 | ||
const isLastPage = page === numPages - 1 | ||
|
||
if (numPages < 2) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div className={styles.defaultContainerStyles}> | ||
<Button | ||
className={styles.prevLabelStyles} | ||
aria-label="Previous page" | ||
disabled={isFirstPage} | ||
onClick={() => { | ||
if (!isFirstPage) { | ||
onChange(page - 1) | ||
} | ||
}} | ||
> | ||
<KeyboardArrowLeft /> | ||
</Button> | ||
<ChooseOne> | ||
<Cond condition={isMobile}> | ||
<PageButton activePage={page} page={page} numPages={numPages} /> | ||
</Cond> | ||
<Cond> | ||
{buildPagedList(numPages, page).map((pageItem) => { | ||
if (pageItem === "left" || pageItem === "right") { | ||
return ( | ||
<PageButton | ||
key={pageItem} | ||
activePage={page} | ||
placeholder="..." | ||
disabled | ||
/> | ||
) | ||
} | ||
|
||
return ( | ||
<PageButton | ||
key={pageItem} | ||
page={pageItem} | ||
activePage={page} | ||
numPages={numPages} | ||
onPageClick={() => onChange(pageItem)} | ||
/> | ||
) | ||
})} | ||
</Cond> | ||
</ChooseOne> | ||
<Button | ||
aria-label="Next page" | ||
disabled={isLastPage} | ||
onClick={() => { | ||
if (!isLastPage) { | ||
onChange(page + 1) | ||
} | ||
}} | ||
> | ||
<KeyboardArrowRight /> | ||
</Button> | ||
</div> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
defaultContainerStyles: { | ||
justifyContent: "center", | ||
alignItems: "center", | ||
display: "flex", | ||
flexDirection: "row", | ||
padding: "20px", | ||
}, | ||
|
||
prevLabelStyles: { | ||
marginRight: `${theme.spacing(0.5)}px`, | ||
}, | ||
})) |
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
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.
Do we want to handle the error for
getTemplate
?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.
It is already handled. If it fails, it will throw an error that will be passed to the
Alert
component. But I guess, you were talking about handling errors in a more granular way. Since these operations are consecutive, one by one, the first one that fails will throw the error, so only one error will happen at a time. But even in case we could have two errors happening at the same time in this operation, I would ask: As a user are those two errors helpful? Or would be good enough to just show a single error like "Update template version failed"? IMO, as a user, usually don't need to know what is happening under the hood so I would avoid showing multiple errors which can make me confused. Makes sense?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.
Sure, totally makes sense. I just see a blank screen with a toast when that error is thrown. Maybe down the road and outside of the PR, we can have a cuter error state, like even an empty table.
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.
Ah, it should not be a toast, should be an alert banner, not VERY different tho. I agree we could have better error components when there is a main loading data error.