-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmissionItemsTableRow.jsx
More file actions
163 lines (149 loc) · 4.24 KB
/
missionItemsTableRow.jsx
File metadata and controls
163 lines (149 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
This component displays the row for a mission item in a table.
*/
import {
ActionIcon,
NumberInput,
Select,
TableTd,
TableTr,
} from "@mantine/core"
import { IconArrowDown, IconArrowUp, IconTrash } from "@tabler/icons-react"
import { useEffect, useState } from "react"
import { coordToInt, intToCoord } from "../../helpers/dataFormatters"
import {
COPTER_MISSION_ITEM_COMMANDS_LIST,
MAV_FRAME_LIST,
PLANE_MISSION_ITEM_COMMANDS_LIST,
} from "../../helpers/mavlinkConstants"
const coordsFractionDigits = 9
export default function MissionItemsTableRow({
index,
aircraftType,
missionItem,
updateMissionItem,
deleteMissionItem,
updateMissionItemOrder,
}) {
const [missionItemData, setMissionItemData] = useState(missionItem)
useEffect(() => {
setMissionItemData(missionItem)
}, [missionItem])
useEffect(() => {
updateMissionItem(missionItemData)
}, [missionItemData])
function getDisplayCommandName(commandName) {
if (commandName.startsWith("MAV_CMD_NAV_")) {
commandName = commandName.replace("MAV_CMD_NAV_", "")
} else if (commandName.startsWith("MAV_CMD_")) {
commandName = commandName.replace("MAV_CMD_", "")
}
return commandName
}
function getAvailableCommands() {
var commandsList = COPTER_MISSION_ITEM_COMMANDS_LIST
if (aircraftType === 1) {
commandsList = PLANE_MISSION_ITEM_COMMANDS_LIST
}
return Object.entries(commandsList).map(([key, value]) => ({
value: key,
label: getDisplayCommandName(value),
}))
}
function getFrameName(frameId) {
var frameName = MAV_FRAME_LIST[frameId]
if (frameName.startsWith("MAV_FRAME_")) {
frameName = frameName.replace("MAV_FRAME_", "")
}
return frameName || "UNKNOWN"
}
function updateMissionItemData(key, newVal) {
setMissionItemData({
...missionItemData,
[key]: newVal,
})
}
return (
<TableTr>
<TableTd>{index}</TableTd>
<TableTd>
<Select
data={getAvailableCommands()}
value={missionItemData.command.toString()}
onChange={(value) =>
updateMissionItemData("command", parseInt(value))
}
allowDeselect={false}
/>
</TableTd>
<TableTd>
<NumberInput
value={missionItemData.param1}
onChange={(val) => updateMissionItemData("param1", val)}
hideControls
/>
</TableTd>
<TableTd>
<NumberInput
value={missionItemData.param2}
onChange={(val) => updateMissionItemData("param2", val)}
hideControls
/>
</TableTd>
<TableTd>
<NumberInput
value={missionItemData.param3}
onChange={(val) => updateMissionItemData("param3", val)}
hideControls
/>
</TableTd>
<TableTd>
<NumberInput
value={missionItemData.param4}
onChange={(val) => updateMissionItemData("param4", val)}
hideControls
/>
</TableTd>
<TableTd>
<NumberInput
value={intToCoord(missionItemData.x).toFixed(coordsFractionDigits)}
onChange={(val) => updateMissionItemData("x", coordToInt(val))}
hideControls
/>
</TableTd>
<TableTd>
<NumberInput
value={intToCoord(missionItemData.y).toFixed(coordsFractionDigits)}
onChange={(val) => updateMissionItemData("y", coordToInt(val))}
hideControls
/>
</TableTd>
<TableTd>
<NumberInput
value={missionItemData.z}
onChange={(val) => updateMissionItemData("z", val)}
hideControls
/>
</TableTd>
<TableTd>{getFrameName(missionItemData.frame)}</TableTd>
<TableTd className="flex flex-row gap-2">
<ActionIcon
onClick={() => updateMissionItemOrder(missionItemData.id, -1)}
>
<IconArrowUp size={20} />
</ActionIcon>
<ActionIcon
onClick={() => updateMissionItemOrder(missionItemData.id, 1)}
>
<IconArrowDown size={20} />
</ActionIcon>
<ActionIcon
onClick={() => deleteMissionItem(missionItemData.id)}
color="red"
>
<IconTrash size={20} />
</ActionIcon>
</TableTd>
</TableTr>
)
}