Skip to content

Commit

Permalink
Fix SNYK suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Christdej committed Jan 28, 2025
1 parent 0de6f7c commit ca0d60b
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 601 deletions.
510 changes: 0 additions & 510 deletions .editorconfig

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MissionSchedulingControllerTests : IAsyncLifetime

public async Task InitializeAsync()
{
(Container, string connectionString, var connection) =
(Container, string connectionString, var _) =
await TestSetupHelpers.ConfigurePostgreSqlDatabase();
var factory = TestSetupHelpers.ConfigureWebApplicationFactory(
postgreSqlConnectionString: connectionString
Expand Down
9 changes: 6 additions & 3 deletions backend/api/Controllers/MissionSchedulingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ [FromBody] ScheduledMissionQuery scheduledMissionQuery
[.. missionInspectionAreaNames]
);
logger.LogWarning(
$"Mission {missionDefinition.Name} has tags on more than one inspection area. The inspection areas are: {joinedMissionInspectionAreaNames}."
"Mission {missionDefinition} has tags on more than one inspection area. The inspection areas are: {joinedMissionInspectionAreaNames}.",
missionDefinition.Name,
joinedMissionInspectionAreaNames
);
}

Expand All @@ -346,7 +348,8 @@ [.. missionInspectionAreaNames]
if (area == null && sortedAreas.Count() > 1)
{
logger.LogWarning(
$"Most common area in mission {missionDefinition.Name} is null. Will use second most common area."
"Most common area in mission {missionDefinition} is null. Will use second most common area.",
missionDefinition.Name
);
area = sortedAreas.Skip(1).First();
}
Expand Down Expand Up @@ -564,7 +567,7 @@ [FromBody] CustomMissionQuery customMissionQuery
};

customMissionDefinition.Map ??= await mapService.ChooseMapFromPositions(
missionTasks.Select(t => t.RobotPose.Position).ToList(),
[.. missionTasks.Select(t => t.RobotPose.Position)],
customMissionQuery.InstallationCode
);

Expand Down
4 changes: 3 additions & 1 deletion backend/api/EventHandlers/InspectionFindingEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
string errorBody = await response.Content.ReadAsStringAsync(stoppingToken);
logger.LogWarning(
$"Webhook request failed with status code {response.StatusCode}. Response body: {errorBody}"
"Webhook request failed with status code {statusCode}. Response body: {errorBody}",
response.StatusCode,
errorBody
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion backend/api/EventHandlers/MqttEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ Installation installation
}
catch (DbUpdateException)
{
_logger.LogError($"Failed to add robot {robotQuery.Name} with to the database");
_logger.LogError(
"Failed to add robot {robotQueryName} with to the database",
robotQuery.Name
);
return;
}
}
Expand Down
40 changes: 25 additions & 15 deletions backend/api/Services/EchoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ await sourceService.CheckForExistingSource(echoMission.Id)
?? await sourceService.Create(new Source { SourceId = $"{echoMission.Id}" });
var missionTasks = echoMission.Tags;
List<Area?> missionAreas;
missionAreas = missionTasks
.Where(t => t.TagId != null)
.Select(t => stidService.GetTagArea(t.TagId, echoMission.InstallationCode).Result)
.ToList();
missionAreas =
[
.. missionTasks
.Where(t => t.TagId != null)
.Select(t =>
stidService.GetTagArea(t.TagId, echoMission.InstallationCode).Result
),
];

var missionInspectionAreaNames = missionAreas
.Where(a => a != null)
Expand All @@ -145,7 +149,9 @@ await sourceService.CheckForExistingSource(echoMission.Id)
[.. missionInspectionAreaNames]
);
logger.LogWarning(
$"Mission {echoMission.Name} has tags on more than one inspection area. The inspection areas are: {joinedMissionInspectionAreaNames}."
"Mission {echoMissionName} has tags on more than one inspection area. The inspection areas are: {joinedMissionInspectionAreaNames}.",
echoMission.Name,
joinedMissionInspectionAreaNames
);
}

Expand All @@ -158,14 +164,16 @@ [.. missionInspectionAreaNames]
if (area == null && sortedAreas.Count() > 1)
{
logger.LogWarning(
$"Most common area in mission {echoMission.Name} is null. Will use second most common area."
"Most common area in mission {echoMissionName} is null. Will use second most common area.",
echoMission.Name
);
area = sortedAreas.Skip(1).First();
}
if (area == null)
{
logger.LogError(
$"Mission {echoMission.Name} doesn't have any tags with valid area."
"Mission {echoMissionName} doesn't have any tags with valid area.",
echoMission.Name
);
return null;
}
Expand Down Expand Up @@ -242,14 +250,16 @@ string installationCode
URL = new Uri(
$"https://stid.equinor.com/{installationCode}/tag?tagNo={planItem.Tag}"
),
Inspections = planItem
.SensorTypes.Select(sensor => new EchoInspection(
sensor,
planItem.InspectionPoint.EnuPosition.ToPosition(),
planItem.InspectionPoint.Name
))
.Distinct(new EchoInspectionComparer())
.ToList(),
Inspections =
[
.. planItem
.SensorTypes.Select(sensor => new EchoInspection(
sensor,
planItem.InspectionPoint.EnuPosition.ToPosition(),
planItem.InspectionPoint.Name
))
.Distinct(new EchoInspectionComparer()),
],
};

if (tag.Inspections.Count < 1)
Expand Down
3 changes: 2 additions & 1 deletion backend/api/Services/MissionSchedulingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ await missionRunService.Create(
catch (UnsupportedRobotCapabilityException)
{
logger.LogError(
$"Unsupported robot capability detected when restarting interrupted missions for robot {missionRun.Robot.Name}. This should not happen."
"Unsupported robot capability detected when restarting interrupted missions for robot {robotName}. This should not happen.",
missionRun.Robot.Name
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/api/Services/Models/IsarMission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public class IsarMission(IsarStartMissionResponse missionResponse)
public string IsarMissionId { get; } = missionResponse.MissionId;

public List<IsarTask> Tasks { get; } =
missionResponse.Tasks.Select(task => new IsarTask(task)).ToList();
[.. missionResponse.Tasks.Select(task => new IsarTask(task))];
}
}
3 changes: 2 additions & 1 deletion backend/api/Services/ReturnToHomeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ robot.RobotCapabilities is not null
if (activeReturnToHomeMissions.Count > 1)
{
logger.LogError(
$"Two Return home missions should not be queued or ongoing simoultaneously for robot with Id {robotId}."
"Two Return home missions should not be queued or ongoing simoultaneously for robot with Id {robotId}.",
robotId
);
}

Expand Down
Empty file removed backend/d1.py
Empty file.
18 changes: 9 additions & 9 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/src/api/ApiCaller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export class BackendAPICaller {
}

static async reRunMission(missionId: string, failedTasksOnly: boolean = false): Promise<Mission> {
const mission = await this.getMissionRunById(missionId)
const mission = await BackendAPICaller.getMissionRunById(missionId)

if (failedTasksOnly) {
const path = `missions/rerun/${mission.id}`
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/components/Contexts/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ export const AuthProvider = (props: Props) => {
const [accessToken, setAccessToken] = useState('')

const VerifyToken = useCallback(() => {
fetchAccessToken(msalContext).then((accessToken) => {
setAccessToken(accessToken)
})
fetchAccessToken(msalContext)
.then((accessToken) => {
setAccessToken(accessToken)
})
.catch((error) => {
console.error('Failed to fetch access token:', error)
})
}, [msalContext])

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export const BatteryStatusDisplay = ({
switch (true) {
case batteryState === BatteryStatus.Charging:
return Icons.BatteryCharging
case batteryLevel === null || batteryLevel === undefined:
return Icons.BatteryUnknown
case !batteryWarningLimit || batteryLevel! > batteryWarningLimit:
case !batteryWarningLimit:
case batteryWarningLimit !== undefined && batteryLevel! > batteryWarningLimit:
return Icons.Battery
case batteryWarningLimit && batteryLevel! <= batteryWarningLimit:
return Icons.BatteryAlert
case batteryLevel == null:
default:
return Icons.BatteryUnknown
}
Expand All @@ -52,7 +52,7 @@ export const BatteryStatusDisplay = ({

return (
<BatteryAlignment style={{ alignItems: textAlignedBottom ? 'end' : 'center' }}>
<Icon name={batteryIcon} color={iconColor} size={itemSize} />
{batteryIcon && <Icon name={batteryIcon} color={iconColor} size={itemSize} />}
<StyledTypography $fontSize={itemSize}>{batteryValue}</StyledTypography>
</BatteryAlignment>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ export const RobotStatusChip = ({ status, flotillaStatus, isarConnected, itemSiz
iconColor = tokens.colors.text.static_icons__default.hex
break
}
case RobotStatus.Blocked: {
statusIcon = Icons.Blocked
iconColor = tokens.colors.interactive.danger__resting.hex
break
}
case RobotStatus.Blocked:
case RobotStatus.BlockedProtectiveStop: {
statusIcon = Icons.Blocked
iconColor = tokens.colors.interactive.danger__resting.hex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const StopMissionDialog = ({
<Dialog.Title>
<Typography variant="h5">
{missionName ? TranslateText('Stop mission:') : TranslateText('No mission running')}{' '}
{missionName && missionName}
{missionName}
</Typography>
</Dialog.Title>
</Dialog.Header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ export const getDeadlineInspection = (deadline: Date): InspectionAreaCardColors
const deadlineDays = getDeadlineInDays(deadline)
switch (true) {
case deadlineDays <= 1:
case 1 < deadlineDays && deadlineDays <= 7:
return InspectionAreaCardColors.Red
case deadlineDays > 1 && deadlineDays <= 7:
return InspectionAreaCardColors.Red
case deadlineDays > 7 && deadlineDays <= 14:
case 7 < deadlineDays && deadlineDays <= 14:
return InspectionAreaCardColors.Orange
case deadlineDays > 7 && deadlineDays <= 30:
case 7 < deadlineDays && deadlineDays <= 30:
return InspectionAreaCardColors.Green
}
return InspectionAreaCardColors.Green
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const MissionDefinitionEditDialog = ({
unit={TranslateText('days')}
value={inspectionFrequencyDays}
onChange={(changes: ChangeEvent<HTMLInputElement>) => {
if (!isNaN(+changes.target.value))
if (!Number.isNaN(+changes.target.value))
updateInspectionFrequencyFormDays(changes.target.value)
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,27 @@ export const MissionMapView = ({ mission }: MissionProps) => {
imageObjectURL.current = NoMap
})
.then(() => {
getMeta(imageObjectURL.current).then((img) => {
const mapCanvas = document.getElementById('mapCanvas') as HTMLCanvasElement
if (mapCanvas) {
mapCanvas.width = img.width
mapCanvas.height = img.height
const context = mapCanvas?.getContext('2d')
if (context) {
setMapContext(context)
context.drawImage(img, 0, 0)
getMeta(imageObjectURL.current)
.then((img) => {
const mapCanvas = document.getElementById('mapCanvas') as HTMLCanvasElement
if (mapCanvas) {
mapCanvas.width = img.width
mapCanvas.height = img.height
const context = mapCanvas?.getContext('2d')
if (context) {
setMapContext(context)
context.drawImage(img, 0, 0)
}
setMapCanvas(mapCanvas)
}
setMapCanvas(mapCanvas)
}
setMapImage(img)
})
setMapImage(img)
})
.catch((error) => {
console.error('Failed to get image metadata:', error)
})
})
.catch((error) => {
console.error('Failed to process map image:', error)
})
} else {
imageObjectURL.current = NoMap
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/components/Pages/MissionPage/StatusReason.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ export const StatusReason = ({ statusReason, status }: MissionProps) => {
let warningLevel: 'default' | 'info' | 'warning' | 'danger' = 'info'
switch (status) {
case MissionStatus.Failed:
warningLevel = 'danger'
break
case MissionStatus.Aborted:
warningLevel = 'danger'
break
case MissionStatus.Cancelled:
warningLevel = 'warning'
break
case MissionStatus.PartiallySuccessful:
warningLevel = 'warning'
break
Expand Down
Loading

0 comments on commit ca0d60b

Please sign in to comment.