Skip to content
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

fix: disable edit button based on endpoint status #2695

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions react/src/pages/EndpointDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '../hooks';
import { useCurrentUserInfo } from '../hooks/backendai';
import { useTanMutation } from '../hooks/reactQueryAlias';
import { isDestroyingStatus } from './EndpointListPage';
import {
EndpointDetailPageQuery,
EndpointDetailPageQuery$data,
Expand Down Expand Up @@ -300,7 +301,7 @@ const EndpointDetailPage: React.FC<EndpointDetailPageProps> = () => {
children: endpoint?.url ? (
<>
<Typography.Text copyable>{endpoint?.url}</Typography.Text>
<Tooltip title={'LLM Playground'}>
<Tooltip title={'LLM Chat Test'}>
<Button
type="link"
icon={<BotMessageSquareIcon />}
Expand Down Expand Up @@ -472,6 +473,10 @@ const EndpointDetailPage: React.FC<EndpointDetailPageProps> = () => {
<Button
loading={isPendingRefetch}
icon={<ReloadOutlined />}
disabled={isDestroyingStatus(
endpoint?.desired_session_count,
endpoint?.status,
)}
onClick={() => {
startRefetchTransition(() => {
updateFetchKey();
Expand All @@ -489,8 +494,10 @@ const EndpointDetailPage: React.FC<EndpointDetailPageProps> = () => {
type="primary"
icon={<SettingOutlined />}
disabled={
(endpoint?.desired_session_count || 0) < 0 ||
endpoint?.status === 'DESTROYING' ||
isDestroyingStatus(
endpoint?.desired_session_count,
endpoint?.status,
) ||
(!!endpoint?.created_user_email &&
endpoint?.created_user_email !== currentUser.email)
}
Expand All @@ -517,7 +524,10 @@ const EndpointDetailPage: React.FC<EndpointDetailPageProps> = () => {
<Button
type="primary"
icon={<PlusOutlined />}
disabled={endpoint?.status === 'DESTROYING'}
disabled={isDestroyingStatus(
endpoint?.desired_session_count,
endpoint?.status,
)}
onClick={() => {
setIsOpenTokenGenerationModal(true);
}}
Expand Down Expand Up @@ -600,6 +610,10 @@ const EndpointDetailPage: React.FC<EndpointDetailPageProps> = () => {
<Button
icon={<SyncOutlined />}
loading={mutationToSyncRoutes.isPending}
disabled={isDestroyingStatus(
endpoint?.desired_session_count,
endpoint?.status,
)}
onClick={() => {
endpoint?.endpoint_id &&
mutationToSyncRoutes.mutateAsync(endpoint?.endpoint_id, {
Expand Down
27 changes: 17 additions & 10 deletions react/src/pages/EndpointListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ export type Endpoint = NonNullable<
>[0]
>;

export const isDestroyingStatus = (
desiredSessionCount: number | null | undefined,
status: string | null | undefined,
) => {
return (
(desiredSessionCount ?? 0) < 0 ||
_.includes(['DESTROYED', 'DESTROYING'], status ?? '')
);
};

type LifecycleStage = 'created&destroying' | 'destroyed';

const EndpointListPage: React.FC<PropsWithChildren> = ({ children }) => {
Expand Down Expand Up @@ -137,8 +147,7 @@ const EndpointListPage: React.FC<PropsWithChildren> = ({ children }) => {
type="text"
icon={<SettingOutlined />}
style={
row.desired_session_count < 0 ||
row.status?.toLowerCase() === 'destroying' ||
isDestroyingStatus(row?.desired_session_count, row?.status) ||
(!!row.created_user_email &&
row.created_user_email !== currentUser.email)
? {
Expand All @@ -149,8 +158,7 @@ const EndpointListPage: React.FC<PropsWithChildren> = ({ children }) => {
}
}
disabled={
row.desired_session_count < 0 ||
row.status?.toLowerCase() === 'destroying' ||
isDestroyingStatus(row?.desired_session_count, row?.status) ||
(!!row.created_user_email &&
row.created_user_email !== currentUser.email)
}
Expand All @@ -163,8 +171,7 @@ const EndpointListPage: React.FC<PropsWithChildren> = ({ children }) => {
icon={
<DeleteOutlined
style={
row.desired_session_count < 0 ||
row.status?.toLowerCase() === 'destroying'
isDestroyingStatus(row?.desired_session_count, row?.status)
? undefined
: {
color: token.colorError,
Expand All @@ -176,10 +183,10 @@ const EndpointListPage: React.FC<PropsWithChildren> = ({ children }) => {
terminateModelServiceMutation.isPending &&
optimisticDeletingId === row.endpoint_id
}
disabled={
row.desired_session_count < 0 ||
row.status?.toLowerCase() === 'destroying'
}
disabled={isDestroyingStatus(
row?.desired_session_count,
row?.status,
)}
onClick={() => {
modal.confirm({
title: t('dialog.ask.DoYouWantToDeleteSomething', {
Expand Down
Loading