Skip to content

Commit

Permalink
Merge pull request #597 from ianmcorvidae/instant-launch-badges
Browse files Browse the repository at this point in the history
Support passing a resource path to the instant launch page
  • Loading branch information
ianmcorvidae authored Oct 11, 2024
2 parents 4878d18 + a304e67 commit e883236
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
47 changes: 30 additions & 17 deletions src/components/instantlaunches/launch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getResourceUsageSummary,
RESOURCE_USAGE_QUERY_KEY,
} from "serviceFacades/dashboard";
import { useDataDetails } from "serviceFacades/filesystem";
import { getUserQuota } from "common/resourceUsage";
import { useConfig } from "contexts/config";
import { useUserProfile } from "contexts/userProfile";
Expand All @@ -25,17 +26,21 @@ import InstantLaunchButtonWrapper from "components/instantlaunches/InstantLaunch
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";
import ErrorTypographyWithDialog from "components/error/ErrorTypographyWithDialog";

const InstantLaunchStandalone = (props) => {
const { id: instant_launch_id, showErrorAnnouncer } = props;
const {
id: instant_launch_id,
resource: resource_path,
showErrorAnnouncer,
} = props;
const [config] = useConfig();
const [userProfile] = useUserProfile();
const [computeLimitExceeded, setComputeLimitExceeded] = useState(
!!config?.subscriptions?.enforce
);
const [errorDialogOpen, setErrorDialogOpen] = useState(false);
const [resource, setResource] = useState(null);

const { t } = useTranslation(["instantlaunches", "common"]);

const { data, status, error } = useQuery(
Expand All @@ -61,28 +66,36 @@ const InstantLaunchStandalone = (props) => {
},
});

const isLoading = isQueryLoading([status, isFetchingUsageSummary]);
const { isFetching: isLoadingResource, error: resourceError } =
useDataDetails({
paths: [resource_path],
enabled: !!resource_path,
onSuccess: (resp) => {
setResource(resp?.paths[resource_path]);
},
});

const isLoading = isQueryLoading([
status,
isLoadingResource,
isFetchingUsageSummary,
]);

if (isLoading) {
return <LoadingAnimation />;
} else if (error) {
} else if (error || resourceError) {
const err = error || resourceError;
return (
<>
<ErrorTypography
errorMessage={error.message}
onDetailsClick={() => setErrorDialogOpen(true)}
/>
<DEErrorDialog
open={errorDialogOpen}
errorObject={error}
handleClose={() => setErrorDialogOpen(false)}
/>
</>
<ErrorTypographyWithDialog
errorMessage={t("instantLaunchError")}
errorObject={err}
/>
);
} else {
return (
<InstantLaunchButtonWrapper
instantLaunch={data}
resource={resource}
computeLimitExceeded={computeLimitExceeded}
autolaunch={true}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/instantlaunch/[id]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import InstantLaunchStandalone from "components/instantlaunches/launch";

export default function InstantLaunch() {
const router = useRouter();
const { id } = router.query;
const { id, resource } = router.query;

return <InstantLaunchStandalone id={id} />;
return <InstantLaunchStandalone id={id} resource={resource} />;
}

export async function getServerSideProps({ locale }) {
Expand Down

0 comments on commit e883236

Please sign in to comment.