-
Notifications
You must be signed in to change notification settings - Fork 16
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
Instant Launch badges (WIP) #596
Merged
ianmcorvidae
merged 6 commits into
cyverse-de:main
from
ianmcorvidae:instant-launch-badges
Oct 10, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0a19058
Add a stub instant launch launcher page
ianmcorvidae 68418a6
flesh out a rudimentary instant launching launch page
ianmcorvidae 2133426
Add an autolaunch feature to InstantLaunchButtonWrapper
ianmcorvidae b49036a
Use a dedicated string for instant launch standalone page, remove dev…
ianmcorvidae 2726412
Use vice loading animation on instant launch page while loading (not …
ianmcorvidae 8e8af37
Use ErrorTypography/DEErrorDialog for errors, for now anyway
ianmcorvidae 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 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,93 @@ | ||
/** | ||
* @author mian | ||
* | ||
* The component that launches a provided instant launch, immediately. | ||
*/ | ||
import React, { useState } from "react"; | ||
|
||
import { useQuery } from "react-query"; | ||
|
||
import { | ||
GET_INSTANT_LAUNCH_FULL_KEY, | ||
getFullInstantLaunch, | ||
} from "serviceFacades/instantlaunches"; | ||
import { | ||
getResourceUsageSummary, | ||
RESOURCE_USAGE_QUERY_KEY, | ||
} from "serviceFacades/dashboard"; | ||
import { getUserQuota } from "common/resourceUsage"; | ||
import { useConfig } from "contexts/config"; | ||
import { useUserProfile } from "contexts/userProfile"; | ||
import globalConstants from "../../../constants"; | ||
import { useTranslation } from "i18n"; | ||
import isQueryLoading from "components/utils/isQueryLoading"; | ||
import InstantLaunchButtonWrapper from "components/instantlaunches/InstantLaunchButtonWrapper"; | ||
import withErrorAnnouncer from "components/error/withErrorAnnouncer"; | ||
import LoadingAnimation from "components/vice/loading/LoadingAnimation"; | ||
|
||
import ErrorTypography from "components/error/ErrorTypography"; | ||
import DEErrorDialog from "components/error/DEErrorDialog"; | ||
|
||
const InstantLaunchStandalone = (props) => { | ||
const { id: instant_launch_id, showErrorAnnouncer } = props; | ||
const [config] = useConfig(); | ||
const [userProfile] = useUserProfile(); | ||
const [computeLimitExceeded, setComputeLimitExceeded] = useState( | ||
!!config?.subscriptions?.enforce | ||
); | ||
const [errorDialogOpen, setErrorDialogOpen] = useState(false); | ||
const { t } = useTranslation(["instantlaunches", "common"]); | ||
|
||
const { data, status, error } = useQuery( | ||
[GET_INSTANT_LAUNCH_FULL_KEY, instant_launch_id], | ||
() => getFullInstantLaunch(instant_launch_id) | ||
); | ||
|
||
const { isFetching: isFetchingUsageSummary } = useQuery({ | ||
queryKey: [RESOURCE_USAGE_QUERY_KEY], | ||
queryFn: getResourceUsageSummary, | ||
enabled: !!config?.subscriptions?.enforce && !!userProfile?.id, | ||
onSuccess: (respData) => { | ||
const computeUsage = respData?.cpu_usage?.total || 0; | ||
const subscription = respData?.subscription; | ||
const computeQuota = getUserQuota( | ||
globalConstants.CPU_HOURS_RESOURCE_NAME, | ||
subscription | ||
); | ||
setComputeLimitExceeded(computeUsage >= computeQuota); | ||
}, | ||
onError: (e) => { | ||
showErrorAnnouncer(t("common:usageSummaryError"), e); | ||
}, | ||
}); | ||
|
||
const isLoading = isQueryLoading([status, isFetchingUsageSummary]); | ||
|
||
if (isLoading) { | ||
return <LoadingAnimation />; | ||
} else if (error) { | ||
return ( | ||
<> | ||
<ErrorTypography | ||
errorMessage={error.message} | ||
onDetailsClick={() => setErrorDialogOpen(true)} | ||
/> | ||
<DEErrorDialog | ||
open={errorDialogOpen} | ||
errorObject={error} | ||
handleClose={() => setErrorDialogOpen(false)} | ||
/> | ||
</> | ||
); | ||
} else { | ||
return ( | ||
<InstantLaunchButtonWrapper | ||
instantLaunch={data} | ||
computeLimitExceeded={computeLimitExceeded} | ||
autolaunch={true} | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
export default withErrorAnnouncer(InstantLaunchStandalone); |
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,33 @@ | ||
/** | ||
* @author mian | ||
* | ||
* Instant launch launch page | ||
*/ | ||
import React from "react"; | ||
|
||
import { serverSideTranslations } from "next-i18next/serverSideTranslations"; | ||
|
||
import { i18n, RequiredNamespaces } from "i18n"; | ||
|
||
import { useRouter } from "next/router"; | ||
|
||
import InstantLaunchStandalone from "components/instantlaunches/launch"; | ||
|
||
export default function InstantLaunch() { | ||
const router = useRouter(); | ||
const { id } = router.query; | ||
|
||
return <InstantLaunchStandalone id={id} />; | ||
} | ||
|
||
export async function getServerSideProps({ locale }) { | ||
const title = i18n.t("instantLaunch"); | ||
|
||
return { | ||
props: { | ||
title, | ||
// "instantlaunches" already included by RequiredNamespaces | ||
...(await serverSideTranslations(locale, RequiredNamespaces)), | ||
}, | ||
}; | ||
} |
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.
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.
This looks basic enough that this could be replaced with an
ErrorTypographyWithDialog
.See
components/apps/savedLaunch/SavedLaunchListing
for an example (I guessAppInfo
wasn't the best example forErrorTypography
, which seems like it could also use anErrorTypographyWithDialog
instead).