Skip to content

Commit

Permalink
Support passing a resource path to the instant launch page
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmcorvidae committed Oct 10, 2024
1 parent 4878d18 commit a7dbf50
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
32 changes: 27 additions & 5 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 @@ -29,13 +30,19 @@ import ErrorTypography from "components/error/ErrorTypography";
import DEErrorDialog from "components/error/DEErrorDialog";

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(!!resource_path ? null : {});

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

const { data, status, error } = useQuery(
Expand All @@ -61,20 +68,34 @@ 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}
errorMessage={err.message}
onDetailsClick={() => setErrorDialogOpen(true)}
/>
<DEErrorDialog
open={errorDialogOpen}
errorObject={error}
errorObject={err}
handleClose={() => setErrorDialogOpen(false)}
/>
</>
Expand All @@ -83,6 +104,7 @@ const InstantLaunchStandalone = (props) => {
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 a7dbf50

Please sign in to comment.