|
1 | 1 | import { createComponent, Shade } from '@furystack/shades' |
2 | | -import { Button, Icon, icons, PageContainer, PageHeader, Paper } from '@furystack/shades-common-components' |
| 2 | +import { Button, Icon, icons, NotyService, PageContainer, PageHeader, Paper } from '@furystack/shades-common-components' |
3 | 3 |
|
4 | 4 | import { LogViewer } from '../../components/log-viewer.js' |
| 5 | +import { ServicesApiClient } from '../../services/api-clients/services-api-client.js' |
5 | 6 |
|
6 | 7 | type ServiceLogsProps = { |
7 | 8 | serviceId: string |
8 | 9 | } |
9 | 10 |
|
10 | 11 | export const ServiceLogs = Shade<ServiceLogsProps>({ |
11 | 12 | shadowDomName: 'shade-service-logs', |
12 | | - render: ({ props }) => { |
| 13 | + render: ({ props, injector }) => { |
| 14 | + const api = injector.getInstance(ServicesApiClient) |
| 15 | + const notyService = injector.getInstance(NotyService) |
| 16 | + |
| 17 | + const handleClearLogs = async () => { |
| 18 | + try { |
| 19 | + await api.call({ |
| 20 | + method: 'DELETE', |
| 21 | + action: '/services/:id/logs', |
| 22 | + url: { id: props.serviceId }, |
| 23 | + }) |
| 24 | + notyService.emit('onNotyAdded', { |
| 25 | + title: 'Logs cleared', |
| 26 | + body: 'Service logs have been cleared.', |
| 27 | + type: 'success', |
| 28 | + }) |
| 29 | + } catch (error) { |
| 30 | + notyService.emit('onNotyAdded', { |
| 31 | + title: 'Error', |
| 32 | + body: error instanceof Error ? error.message : 'Failed to clear logs', |
| 33 | + type: 'error', |
| 34 | + }) |
| 35 | + } |
| 36 | + } |
| 37 | + |
13 | 38 | return ( |
14 | 39 | <PageContainer> |
15 | 40 | <PageHeader |
16 | 41 | icon="📋" |
17 | 42 | title="Service Logs" |
18 | 43 | actions={ |
19 | | - <Button |
20 | | - variant="outlined" |
21 | | - onclick={() => history.back()} |
22 | | - startIcon={<Icon icon={icons.chevronLeft} size="small" />} |
23 | | - > |
24 | | - Back |
25 | | - </Button> |
| 44 | + <div style={{ display: 'flex', gap: '8px' }}> |
| 45 | + <Button |
| 46 | + variant="outlined" |
| 47 | + color="error" |
| 48 | + onclick={() => void handleClearLogs()} |
| 49 | + startIcon={<Icon icon={icons.trash} size="small" />} |
| 50 | + > |
| 51 | + Clear Logs |
| 52 | + </Button> |
| 53 | + <Button |
| 54 | + variant="outlined" |
| 55 | + onclick={() => history.back()} |
| 56 | + startIcon={<Icon icon={icons.chevronLeft} size="small" />} |
| 57 | + > |
| 58 | + Back |
| 59 | + </Button> |
| 60 | + </div> |
26 | 61 | } |
27 | 62 | /> |
28 | 63 | <Paper style={{ flex: '1', overflow: 'hidden' }}> |
|
0 commit comments