fix typing issue
This commit is contained in:
parent
a07d1c7d39
commit
3111f56571
@ -41,6 +41,7 @@ export default function CanvasEndpoints() {
|
|||||||
const [chatLoading, setChatLoading] = useState(false);
|
const [chatLoading, setChatLoading] = useState(false);
|
||||||
const [chatError, setChatError] = useState<string | null>(null);
|
const [chatError, setChatError] = useState<string | null>(null);
|
||||||
const toast = useRef(null);
|
const toast = useRef(null);
|
||||||
|
const [editEndpointId, setEditEndpointId] = useState<number | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
initFilters();
|
initFilters();
|
||||||
@ -203,6 +204,40 @@ export default function CanvasEndpoints() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openEditModal = (endpoint: any) => {
|
||||||
|
setEditEndpointId(endpoint.id);
|
||||||
|
setNewEndpoint({
|
||||||
|
name: endpoint.name,
|
||||||
|
method: endpoint.method,
|
||||||
|
path: endpoint.path,
|
||||||
|
description: endpoint.description || '',
|
||||||
|
});
|
||||||
|
setShowCreateModal(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSaveEndpoint = async () => {
|
||||||
|
try {
|
||||||
|
const sanitizedEndpoint = { ...newEndpoint, path: sanitizeCanvasPath(newEndpoint.path) };
|
||||||
|
if (editEndpointId) {
|
||||||
|
await api('put', `/api/v1/canvas-api/endpoints/${editEndpointId}`, sanitizedEndpoint);
|
||||||
|
} else {
|
||||||
|
await api('post', '/api/v1/canvas-api/endpoints', sanitizedEndpoint);
|
||||||
|
}
|
||||||
|
setShowCreateModal(false);
|
||||||
|
setNewEndpoint({ name: '', method: '', path: '', description: '' });
|
||||||
|
setEditEndpointId(null);
|
||||||
|
fetchEndpoints();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to save endpoint:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleModalHide = () => {
|
||||||
|
setShowCreateModal(false);
|
||||||
|
setNewEndpoint({ name: '', method: '', path: '', description: '' });
|
||||||
|
setEditEndpointId(null);
|
||||||
|
};
|
||||||
|
|
||||||
const renderHeader = () => (
|
const renderHeader = () => (
|
||||||
<TableGroupHeader
|
<TableGroupHeader
|
||||||
size={size}
|
size={size}
|
||||||
@ -233,6 +268,7 @@ export default function CanvasEndpoints() {
|
|||||||
const renderCallButton = (rowData: any) => (
|
const renderCallButton = (rowData: any) => (
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Button label="Call" icon="pi pi-play" onClick={() => handleCallEndpoint(rowData)} />
|
<Button label="Call" icon="pi pi-play" onClick={() => handleCallEndpoint(rowData)} />
|
||||||
|
<Button label="Edit" icon="pi pi-pencil" className="p-button-warning" onClick={() => openEditModal(rowData)} />
|
||||||
<Button label="Delete" icon="pi pi-trash" className="p-button-danger" onClick={() => handleDeleteEndpoint(rowData)} />
|
<Button label="Delete" icon="pi pi-trash" className="p-button-danger" onClick={() => handleDeleteEndpoint(rowData)} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -274,12 +310,12 @@ export default function CanvasEndpoints() {
|
|||||||
|
|
||||||
<Dialog
|
<Dialog
|
||||||
visible={showCreateModal}
|
visible={showCreateModal}
|
||||||
onHide={() => setShowCreateModal(false)}
|
onHide={handleModalHide}
|
||||||
header="Create New Endpoint"
|
header={editEndpointId ? "Edit Endpoint" : "Create New Endpoint"}
|
||||||
footer={
|
footer={
|
||||||
<div>
|
<div>
|
||||||
<Button label="Cancel" icon="pi pi-times" onClick={() => setShowCreateModal(false)} className="p-button-text" />
|
<Button label="Cancel" icon="pi pi-times" onClick={handleModalHide} className="p-button-text" />
|
||||||
<Button label="Create" icon="pi pi-check" onClick={handleCreateEndpoint} autoFocus disabled={!(newEndpoint.name && newEndpoint.method && newEndpoint.path)} />
|
<Button label={editEndpointId ? "Save" : "Create"} icon="pi pi-check" onClick={handleSaveEndpoint} autoFocus disabled={!(newEndpoint.name && newEndpoint.method && newEndpoint.path)} />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
@ -22,12 +22,26 @@ export class CanvasApiEndpointController {
|
|||||||
return reply.send(endpoint);
|
return reply.send(endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(request: FastifyRequest, reply: FastifyReply) {
|
async delete(request: FastifyRequest<{ Params: { id: string } }>, reply: FastifyReply) {
|
||||||
const id = Number(request.params['id']);
|
const id = Number(request.params.id);
|
||||||
if (!id) return reply.status(400).send({ error: 'Missing id' });
|
if (!id) return reply.status(400).send({ error: 'Missing id' });
|
||||||
const endpoint = await request.em.findOne(CanvasApiEndpoint, { id });
|
const endpoint = await request.em.findOne(CanvasApiEndpoint, { id });
|
||||||
if (!endpoint) return reply.status(404).send({ error: 'Not found' });
|
if (!endpoint) return reply.status(404).send({ error: 'Not found' });
|
||||||
await request.em.removeAndFlush(endpoint);
|
await request.em.removeAndFlush(endpoint);
|
||||||
return reply.send({ success: true });
|
return reply.send({ success: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async update(request: FastifyRequest<{ Params: { id: string } }>, reply: FastifyReply) {
|
||||||
|
const id = Number(request.params.id);
|
||||||
|
if (!id) return reply.status(400).send({ error: 'Missing id' });
|
||||||
|
const endpoint = await request.em.findOne(CanvasApiEndpoint, { id });
|
||||||
|
if (!endpoint) return reply.status(404).send({ error: 'Not found' });
|
||||||
|
const { name, method, path, description } = request.body as any;
|
||||||
|
if (name) endpoint.name = name;
|
||||||
|
if (method) endpoint.method = method;
|
||||||
|
if (path) endpoint.path = (path as string).replace(/^\/api\/v1/, '');
|
||||||
|
if (description !== undefined) endpoint.description = description;
|
||||||
|
await request.em.persistAndFlush(endpoint);
|
||||||
|
return reply.send(endpoint);
|
||||||
|
}
|
||||||
}
|
}
|
@ -26,6 +26,10 @@ const endpointsRoutes: FastifyPluginAsync = async (app) => {
|
|||||||
return controller.delete(request, reply);
|
return controller.delete(request, reply);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.put('/endpoints/:id', async (request: FastifyRequest, reply: FastifyReply) => {
|
||||||
|
return controller.update(request, reply);
|
||||||
|
});
|
||||||
|
|
||||||
// Dynamic proxy route for external Canvas REST API
|
// Dynamic proxy route for external Canvas REST API
|
||||||
app.post('/proxy-external', async (request: FastifyRequest, reply: FastifyReply) => {
|
app.post('/proxy-external', async (request: FastifyRequest, reply: FastifyReply) => {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user