- Notifications
You must be signed in to change notification settings - Fork906
feat: add inline actions into workspaces table#17636
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
0ba8372
25d986e
50d9d74
a20a188
6f054b9
fcc5a27
10dcd68
766463d
c14442c
281cf1a
71c6369
3502a22
7d2b8b3
61dc162
ddcb1e9
53c4332
86337e2
821f9d0
b70e28f
b790963
0987ed1
c1d3046
f797506
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -139,13 +139,9 @@ function workspacesKey(config: WorkspacesRequest = {}) { | ||
} | ||
export function workspaces(config: WorkspacesRequest = {}) { | ||
return { | ||
queryKey: workspacesKey(config), | ||
queryFn: () => API.getWorkspaces(config), | ||
BrunoQuaresma marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} as const satisfies QueryOptions<WorkspacesResponse>; | ||
} | ||
@@ -281,7 +277,10 @@ const updateWorkspaceBuild = async ( | ||
build.workspace_owner_name, | ||
build.workspace_name, | ||
); | ||
const previousData = queryClient.getQueryData<Workspace>(workspaceKey); | ||
if (!previousData) { | ||
return; | ||
} | ||
// Check if the build returned is newer than the previous build that could be | ||
// updated from web socket | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -9,7 +9,7 @@ export const usePagination = ({ | ||
const [searchParams, setSearchParams] = searchParamsResult; | ||
const page = searchParams.get("page") ? Number(searchParams.get("page")) : 1; | ||
const limit = DEFAULT_RECORDS_PER_PAGE; | ||
const offset =calcOffset(page,limit); | ||
const goToPage = (page: number) => { | ||
searchParams.set("page", page.toString()); | ||
@@ -23,3 +23,7 @@ export const usePagination = ({ | ||
offset, | ||
}; | ||
}; | ||
export const calcOffset = (page: number, limit: number) => { | ||
return page <= 0 ? 0 : (page - 1) * limit; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This can be turned into Member
| ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { MissingBuildParameters } from "api/api"; | ||
import { updateWorkspace } from "api/queries/workspaces"; | ||
import type { | ||
TemplateVersion, | ||
Workspace, | ||
WorkspaceBuild, | ||
WorkspaceBuildParameter, | ||
} from "api/typesGenerated"; | ||
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"; | ||
import { MemoizedInlineMarkdown } from "components/Markdown/Markdown"; | ||
import { UpdateBuildParametersDialog } from "pages/WorkspacePage/UpdateBuildParametersDialog"; | ||
import { type FC, useState } from "react"; | ||
import { useMutation, useQueryClient } from "react-query"; | ||
type UseWorkspaceUpdateOptions = { | ||
workspace: Workspace; | ||
latestVersion: TemplateVersion | undefined; | ||
onSuccess?: (build: WorkspaceBuild) => void; | ||
onError?: (error: unknown) => void; | ||
}; | ||
type UseWorkspaceUpdateResult = { | ||
update: () => void; | ||
isUpdating: boolean; | ||
dialogs: { | ||
updateConfirmation: UpdateConfirmationDialogProps; | ||
missingBuildParameters: MissingBuildParametersDialogProps; | ||
}; | ||
}; | ||
export const useWorkspaceUpdate = ({ | ||
workspace, | ||
latestVersion, | ||
onSuccess, | ||
onError, | ||
}: UseWorkspaceUpdateOptions): UseWorkspaceUpdateResult => { | ||
const queryClient = useQueryClient(); | ||
const [isConfirmingUpdate, setIsConfirmingUpdate] = useState(false); | ||
const updateWorkspaceOptions = updateWorkspace(workspace, queryClient); | ||
const updateWorkspaceMutation = useMutation({ | ||
...updateWorkspaceOptions, | ||
onSuccess: (build: WorkspaceBuild) => { | ||
updateWorkspaceOptions.onSuccess(build); | ||
onSuccess?.(build); | ||
}, | ||
onError, | ||
}); | ||
const update = () => { | ||
setIsConfirmingUpdate(true); | ||
}; | ||
const confirmUpdate = (buildParameters: WorkspaceBuildParameter[] = []) => { | ||
updateWorkspaceMutation.mutate(buildParameters); | ||
setIsConfirmingUpdate(false); | ||
}; | ||
return { | ||
update, | ||
isUpdating: updateWorkspaceMutation.isLoading, | ||
dialogs: { | ||
updateConfirmation: { | ||
open: isConfirmingUpdate, | ||
onClose: () => setIsConfirmingUpdate(false), | ||
onConfirm: () => confirmUpdate(), | ||
latestVersion, | ||
}, | ||
missingBuildParameters: { | ||
error: updateWorkspaceMutation.error, | ||
onClose: () => { | ||
updateWorkspaceMutation.reset(); | ||
}, | ||
onUpdate: (buildParameters: WorkspaceBuildParameter[]) => { | ||
if (updateWorkspaceMutation.error instanceof MissingBuildParameters) { | ||
confirmUpdate(buildParameters); | ||
} | ||
}, | ||
}, | ||
}, | ||
}; | ||
}; | ||
type WorkspaceUpdateDialogsProps = { | ||
updateConfirmation: UpdateConfirmationDialogProps; | ||
missingBuildParameters: MissingBuildParametersDialogProps; | ||
}; | ||
export const WorkspaceUpdateDialogs: FC<WorkspaceUpdateDialogsProps> = ({ | ||
updateConfirmation, | ||
missingBuildParameters, | ||
}) => { | ||
return ( | ||
<> | ||
<UpdateConfirmationDialog {...updateConfirmation} /> | ||
<MissingBuildParametersDialog {...missingBuildParameters} /> | ||
</> | ||
); | ||
}; | ||
type UpdateConfirmationDialogProps = { | ||
open: boolean; | ||
onClose: () => void; | ||
onConfirm: () => void; | ||
latestVersion?: TemplateVersion; | ||
}; | ||
const UpdateConfirmationDialog: FC<UpdateConfirmationDialogProps> = ({ | ||
latestVersion, | ||
...dialogProps | ||
}) => { | ||
return ( | ||
<ConfirmDialog | ||
{...dialogProps} | ||
hideCancel={false} | ||
title="Update workspace?" | ||
confirmText="Update" | ||
description={ | ||
<div className="flex flex-col gap-2"> | ||
<p> | ||
Updating your workspace will start the workspace on the latest | ||
template version. This can{" "} | ||
<strong>delete non-persistent data</strong>. | ||
</p> | ||
{latestVersion?.message && ( | ||
<MemoizedInlineMarkdown allowedElements={["ol", "ul", "li"]}> | ||
{latestVersion.message} | ||
</MemoizedInlineMarkdown> | ||
)} | ||
</div> | ||
} | ||
/> | ||
); | ||
}; | ||
type MissingBuildParametersDialogProps = { | ||
error: unknown; | ||
onClose: () => void; | ||
onUpdate: (buildParameters: WorkspaceBuildParameter[]) => void; | ||
}; | ||
const MissingBuildParametersDialog: FC<MissingBuildParametersDialogProps> = ({ | ||
error, | ||
...dialogProps | ||
}) => { | ||
return ( | ||
<UpdateBuildParametersDialog | ||
missedParameters={ | ||
error instanceof MissingBuildParameters ? error.parameters : [] | ||
} | ||
open={error instanceof MissingBuildParameters} | ||
{...dialogProps} | ||
/> | ||
); | ||
}; |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.