-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feat-add-repo-supports' into fea…
…t-add-repo-supports
- Loading branch information
Showing
22 changed files
with
538 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
client/src/components/DeviceConfiguration/diagnostic/ExistingDeviceAdvancedDiagnostic.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import { MedicalSearchDiagnosisSolid } from '@/components/Icons/CustomIcons'; | ||
import { postDeviceDiagnostic } from '@/services/rest/device'; | ||
import { socket } from '@/socket'; | ||
import { history } from '@umijs/max'; | ||
import { | ||
Avatar, | ||
Button, | ||
Card, | ||
Col, | ||
message, | ||
Row, | ||
StepProps, | ||
Steps, | ||
} from 'antd'; | ||
import React, { useEffect } from 'react'; | ||
import { API, SsmDeviceDiagnostic, SsmEvents } from 'ssm-shared-lib'; | ||
|
||
type ExistingDeviceAdvancedDiagnosticProps = { | ||
device: Partial<API.DeviceItem>; | ||
}; | ||
|
||
const items: (StepProps & any)[] = [ | ||
{ | ||
title: 'Ssh Connect', | ||
description: 'Waiting...', | ||
key: SsmDeviceDiagnostic.Checks.SSH_CONNECT, | ||
}, | ||
{ | ||
title: 'Ssh Docker Connect', | ||
description: 'Waiting...', | ||
key: SsmDeviceDiagnostic.Checks.SSH_DOCKER_CONNECT, | ||
}, | ||
{ | ||
title: 'Ssh Docker Socket Connectivity', | ||
description: 'Waiting...', | ||
key: SsmDeviceDiagnostic.Checks.DOCKER_SOCKET, | ||
}, | ||
{ | ||
title: 'Disk Space', | ||
description: 'Waiting...', | ||
key: SsmDeviceDiagnostic.Checks.DISK_SPACE, | ||
}, | ||
{ | ||
title: 'Memory & CPU', | ||
description: 'Waiting...', | ||
key: SsmDeviceDiagnostic.Checks.CPU_MEMORY_INFO, | ||
}, | ||
]; | ||
|
||
const ExistingDeviceAdvancedDiagnostic: React.FC< | ||
ExistingDeviceAdvancedDiagnosticProps | ||
> = ({ device }) => { | ||
const [diagInProgress, setDiagInProgress] = React.useState(false); | ||
const [steps, setSteps] = React.useState<any[]>(items); | ||
const onDiagnosticProgress = (payload: any) => { | ||
setSteps((prevSteps) => | ||
prevSteps.map((step) => | ||
step.key === payload?.data?.check | ||
? { | ||
...step, | ||
description: payload.message || step.description, // Update description if provided | ||
status: !payload.success ? 'error' : 'success', | ||
} | ||
: step, | ||
), | ||
); | ||
}; | ||
|
||
useEffect(() => { | ||
socket.connect(); | ||
socket.on(SsmEvents.Diagnostic.PROGRESS, onDiagnosticProgress); | ||
|
||
return () => { | ||
socket.off(SsmEvents.Diagnostic.PROGRESS, onDiagnosticProgress); | ||
socket.disconnect(); | ||
}; | ||
}, []); | ||
|
||
const onStartDiag = async () => { | ||
setDiagInProgress(true); | ||
setSteps(items); | ||
await postDeviceDiagnostic(device?.uuid as string) | ||
.then(() => { | ||
message.loading({ content: 'Diagnostic in progress...', duration: 5 }); | ||
}) | ||
.catch(() => { | ||
setDiagInProgress(false); | ||
setSteps(items); | ||
}); | ||
}; | ||
|
||
return ( | ||
<Card | ||
type="inner" | ||
title={ | ||
<Row> | ||
<Col> | ||
<Avatar | ||
style={{ backgroundColor: '#8e165e' }} | ||
shape="square" | ||
icon={<MedicalSearchDiagnosisSolid />} | ||
/> | ||
</Col> | ||
<Col | ||
style={{ | ||
marginLeft: 10, | ||
marginTop: 'auto', | ||
marginBottom: 'auto', | ||
}} | ||
> | ||
Advanced Diagnostic | ||
</Col> | ||
</Row> | ||
} | ||
style={{ marginBottom: 10 }} | ||
styles={{ | ||
header: { height: 55, minHeight: 55, paddingLeft: 15 }, | ||
body: { paddingBottom: 0 }, | ||
}} | ||
extra={ | ||
<Button | ||
onClick={() => { | ||
history.push({ | ||
pathname: '/admin/logs', | ||
// @ts-expect-error lib missing type | ||
search: `?msg=DEVICE_DIAGNOSTIC`, | ||
}); | ||
}} | ||
> | ||
Show Diagnostic Logs | ||
</Button> | ||
} | ||
> | ||
{diagInProgress && ( | ||
<Steps size="small" direction="vertical" items={steps} /> | ||
)} | ||
<Button style={{ marginBottom: 20 }} onClick={onStartDiag}> | ||
Run Advanced Diagnostic | ||
</Button> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default ExistingDeviceAdvancedDiagnostic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
client/src/pages/Admin/Inventory/components/DiagnosticTab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import ExistingDeviceAdvancedDiagnostic from '@/components/DeviceConfiguration/diagnostic/ExistingDeviceAdvancedDiagnostic'; | ||
import ExistingDeviceConnectionTest from '@/components/DeviceConfiguration/diagnostic/ExistingDeviceConnectionTest'; | ||
import React from 'react'; | ||
import { API } from 'ssm-shared-lib'; | ||
|
||
export type ConnectionTestTabProps = { | ||
device: Partial<API.DeviceItem>; | ||
}; | ||
|
||
const DiagnosticTab: React.FC<ConnectionTestTabProps> = (props) => ( | ||
<> | ||
<ExistingDeviceConnectionTest device={props.device} /> | ||
<ExistingDeviceAdvancedDiagnostic device={props.device} /> | ||
</> | ||
); | ||
|
||
export default DiagnosticTab; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.