|
1 | | -import { Button, Col, Flex, Layout, Row, Table } from "antd"; |
| 1 | +import { Button, Col, Flex, Layout, Modal, notification, Row, Table, Tooltip, Tooltip } from "antd"; |
2 | 2 | import { Content } from "antd/es/layout/layout"; |
3 | 3 | import styled from "styled-components"; |
4 | | -import { useModelProviders } from "./hooks"; |
| 4 | +import { deleteModelProvider, useModelProviders } from "./hooks"; |
5 | 5 | import get from "lodash/get"; |
6 | 6 | import { sortItemsByKey } from "../../utils/sortutils"; |
7 | 7 | import Paragraph from "antd/es/typography/Paragraph"; |
8 | 8 | import StyledTitle from "../Evaluator/StyledTitle"; |
9 | 9 | import Toolbar from "./Toolbar"; |
10 | 10 | import AddModelProviderButton, { ModelProviderType } from "./AddModelProviderButton"; |
11 | 11 | import DateTime from "../../components/DateTime/DateTime"; |
| 12 | +import { |
| 13 | + EditOutlined, |
| 14 | + DeleteOutlined |
| 15 | + } from '@ant-design/icons'; |
| 16 | +import { useMutation } from "@tanstack/react-query"; |
12 | 17 |
|
13 | 18 |
|
14 | 19 |
|
@@ -65,12 +70,42 @@ const StyledParagraph = styled(Paragraph)` |
65 | 70 | color: #5a656d; |
66 | 71 | `; |
67 | 72 |
|
| 73 | +const StyledButton = styled(Button)` |
| 74 | + margin-left: 8px; |
| 75 | +`; |
| 76 | + |
68 | 77 | const SettingsPage: React.FC = () => { |
69 | 78 | const filteredModelsReq = useModelProviders(); |
70 | 79 | console.log('filteredModelsReq', filteredModelsReq); |
71 | 80 | const customModels = get(filteredModelsReq, 'data.endpoints', []); |
72 | 81 |
|
| 82 | + const mutation = useMutation({ |
| 83 | + mutationFn: deleteModelProvider |
| 84 | + }); |
73 | 85 |
|
| 86 | + const onDelete = (model: CustomModel) => { |
| 87 | + Modal.confirm({ |
| 88 | + content: ( |
| 89 | + <span>{`Are you sure you want to delete the model ${model}`}</span> |
| 90 | + ), |
| 91 | + onOk: async () => { |
| 92 | + try { |
| 93 | + mutation.mutate({ |
| 94 | + model_id: model.model_id, |
| 95 | + provider_type: model.provider_type |
| 96 | + }) |
| 97 | + } catch (error) { |
| 98 | + notification.error({ |
| 99 | + message: "Error", |
| 100 | + description: error instanceof Error ? error.message : String(error), |
| 101 | + }); |
| 102 | + } |
| 103 | + }, |
| 104 | + title: 'Confirm' |
| 105 | + }); |
| 106 | + }; |
| 107 | + |
| 108 | + const onEdit = () => {} |
74 | 109 |
|
75 | 110 | const modelProvidersColumns = [{ |
76 | 111 | key: 'display_name', |
@@ -117,6 +152,39 @@ const SettingsPage: React.FC = () => { |
117 | 152 | width: 300, |
118 | 153 | sorter: sortItemsByKey('endpoint_url'), |
119 | 154 | render: (endpoint_url: string) => <StyledParagraph style={{ width: 200, marginBottom: 0 }} ellipsis={{ rows: 1 }}>{endpoint_url}</StyledParagraph> |
| 155 | + }, { |
| 156 | + title: 'Actions', |
| 157 | + width: 100, |
| 158 | + render: (model: CustomModel) => { |
| 159 | + console.log('model', model); |
| 160 | + return ( |
| 161 | + <Flex> |
| 162 | + <Tooltip title="Edit"> |
| 163 | + <Button |
| 164 | + type="link" |
| 165 | + key={`${model.endpoint_id}-delete`} |
| 166 | + onClick={() => onDelete(model)} |
| 167 | + data-event-category="User Action" |
| 168 | + data-event="Delete" |
| 169 | + > |
| 170 | + <DeleteOutlined /> |
| 171 | + </Button> |
| 172 | + </Tooltip> |
| 173 | + <Tooltip title="Edit"> |
| 174 | + <StyledButton |
| 175 | + type="link" |
| 176 | + key={`${model.endpoint_id}-deploy`} |
| 177 | + onClick={onEdit} |
| 178 | + data-event-category="User Action" |
| 179 | + data-event="Edit" |
| 180 | + > |
| 181 | + <EditOutlined /> |
| 182 | + </StyledButton> |
| 183 | + </Tooltip> |
| 184 | + </Flex> |
| 185 | + ); |
| 186 | + |
| 187 | + } |
120 | 188 | }]; |
121 | 189 |
|
122 | 190 |
|
|
0 commit comments