Skip to content

Commit

Permalink
use a redirectOnDelete flag for lighter footprint
Browse files Browse the repository at this point in the history
  • Loading branch information
mapmeld committed Dec 1, 2023
1 parent 5e7c978 commit 11dbf93
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
7 changes: 4 additions & 3 deletions webui/react/src/components/DeleteModelModal.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { Modal } from 'hew/Modal';

import { paths } from 'routes/utils';
import { deleteModel } from 'services/api';
import { ModelItem } from 'types';
import handleError, { ErrorLevel, ErrorType } from 'utils/error';
import { routeToReactUrl } from 'utils/routes';

interface Props {
listPath?: string;
model: ModelItem;
redirectOnDelete?: boolean;
}

const DeleteModelModal = ({ listPath, model }: Props): JSX.Element => {
const DeleteModelModal = ({ model, redirectOnDelete = false }: Props): JSX.Element => {
const handleOk = async () => {
try {
await deleteModel({ modelName: model.name });
if (listPath) routeToReactUrl(listPath);
if (redirectOnDelete) routeToReactUrl(paths.workspaceDetails(model.workspaceId, 'models'));
} catch (e) {
handleError(e, {
level: ErrorLevel.Error,
Expand Down
9 changes: 1 addition & 8 deletions webui/react/src/pages/ModelDetails/ModelHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import ModelMoveModal from 'components/ModelMoveModal';
import TimeAgo from 'components/TimeAgo';
import Avatar from 'components/UserAvatar';
import usePermissions from 'hooks/usePermissions';
import { paths } from 'routes/utils';
import userStore from 'stores/users';
import { ModelItem, Workspace } from 'types';
import { formatDatetime } from 'utils/datetime';
Expand Down Expand Up @@ -149,12 +148,6 @@ const ModelHeader: React.FC<Props> = ({
[deleteModelModal, modelEditModal, modelMoveModal, onSwitchArchive],
);

const listPath = useMemo(
() =>
model.workspaceId ? paths.workspaceDetails(model.workspaceId, 'models') : paths.modelList(),
[model.workspaceId],
);

return (
<header className={css.base}>
{model.archived && (
Expand All @@ -180,7 +173,7 @@ const ModelHeader: React.FC<Props> = ({
</div>
<Glossary content={infoRows} />
</div>
<deleteModelModal.Component listPath={listPath} model={model} />
<deleteModelModal.Component model={model} redirectOnDelete />
<modelMoveModal.Component model={model} />
<modelEditModal.Component fetchModel={fetchModel} model={model} />
</header>
Expand Down

0 comments on commit 11dbf93

Please sign in to comment.