From 6eb20a652af1ae2705a3c8bee0257167624de0fe Mon Sep 17 00:00:00 2001
From: "Will C aka \"Big Bercin" <97210222+Vercin-G@users.noreply.github.com>
Date: Tue, 26 Sep 2023 02:00:16 -0600
Subject: [PATCH] Refactor 2 electric boogaloo (#54)
* move stuff to billetbank
* new modules
* refactor 2 electric boogaloo
* why do you do this to me, prettier?
---
client/src/App.js | 30 +--
client/src/modules/Generic/ArrayMap.js | 41 ++++
client/src/modules/Generic/BilletBank.js | 8 +
.../src/modules/Generic/CombinedFunction.js | 185 +-----------------
client/src/modules/Generic/MilpacParse.js | 140 +++++++++++++
5 files changed, 214 insertions(+), 190 deletions(-)
create mode 100644 client/src/modules/Generic/ArrayMap.js
create mode 100644 client/src/modules/Generic/MilpacParse.js
diff --git a/client/src/App.js b/client/src/App.js
index 15c6e0f..241f642 100644
--- a/client/src/App.js
+++ b/client/src/App.js
@@ -97,7 +97,7 @@ function MilpacRequest() {
alt="ADR Logo"
title="Return to the main website"
width="17em"
- height=""
+ height="3em"
/>
@@ -143,46 +143,50 @@ function MilpacRequest() {
@@ -190,7 +194,9 @@ function MilpacRequest() {
billetBankObject={
lists.billetBankObject.supportDepartments.positionIds
}
- collapsibleTitle="Support Departments"
+ collapsibleTitle={
+ lists.billetBankObject.supportDepartments.collapsibleTitle
+ }
headerTitles={
lists.billetBankObject.supportDepartments.positionTitles
}
diff --git a/client/src/modules/Generic/ArrayMap.js b/client/src/modules/Generic/ArrayMap.js
new file mode 100644
index 0000000..4fa3ece
--- /dev/null
+++ b/client/src/modules/Generic/ArrayMap.js
@@ -0,0 +1,41 @@
+import React from "react";
+
+/*This function is probably the most complicated code in the ADR. Essentially, it takes inputArray and headerTitles, and iterates through the first layer of inputArray's arrays
+which in this case is the battalion level. At the battalion level, it creates a table row for each company, adding the company title (defined in BilletBank.js) and unit strength counter.
+After the title and counter are created for the company level, the lists themselves for each company are created, which are the second layer of arrays. The lists themselves contain
+milpac link, name and rank, and position title.*/
+
+function ArrayMap(props) {
+ let inputArray = props.inputArray;
+
+ return (
+
+
+ {inputArray.map((subArray, index) => (
+
+
+
+ {props.headerTitles[index]}
+ |
+
+ Unit Strength: {inputArray[index].length}
+ |
+
+ {subArray.map((item, subIndex) => (
+
+
+
+ {item.fullName}
+
+ |
+ {item.position.positionTitle} |
+
+ ))}
+
+ ))}
+
+
+ );
+}
+
+export default ArrayMap;
diff --git a/client/src/modules/Generic/BilletBank.js b/client/src/modules/Generic/BilletBank.js
index c0c4b37..d85982e 100644
--- a/client/src/modules/Generic/BilletBank.js
+++ b/client/src/modules/Generic/BilletBank.js
@@ -18,6 +18,7 @@ const regiCommand = [
const regi = {
positionIds: [regiCommand],
positionTitles: ["Command Staff"],
+ collapsibleTitle: "Regimental Command",
};
//1-7
@@ -187,6 +188,7 @@ const oneSeven = {
"Bravo Troop",
"Charlie Company",
],
+ collapsibleTitle: "First Battalion",
};
//2-7
@@ -348,6 +350,7 @@ const twoSeven = {
"Bravo Company",
"Charlie Company",
],
+ collapsibleTitle: "Second Battalion",
};
//ACD
@@ -524,6 +527,7 @@ const acd = {
"Star Citizen Starter Platoon",
"Future Concepts Center",
],
+ collapsibleTitle: "First Battalion",
};
//IMO
@@ -565,6 +569,7 @@ const imo = {
"S6 - Information Management",
"Wiki Administration Group",
],
+ collapsibleTitle: "Information Management Office",
};
//ROO
@@ -611,6 +616,7 @@ const roo = {
"Recruit Training Command",
"S5 - Public Relations",
],
+ collapsibleTitle: "Recruitment Oversight Office",
};
//SecOps
@@ -628,6 +634,7 @@ const secOps = {
"Military Police",
"S2 - Intelligence and Security",
],
+ collapsibleTitle: "Security Operations",
};
//Support
@@ -738,6 +745,7 @@ const supportDepartments = {
"S7 - Training",
"Leadership Development",
],
+ collapsibleTitle: "Support Departments",
};
// Overall export Object
diff --git a/client/src/modules/Generic/CombinedFunction.js b/client/src/modules/Generic/CombinedFunction.js
index 294c6d9..4f608f3 100644
--- a/client/src/modules/Generic/CombinedFunction.js
+++ b/client/src/modules/Generic/CombinedFunction.js
@@ -1,193 +1,22 @@
import React from "react";
import Collapsible from "react-collapsible";
+import MilpacParse from "./MilpacParse.js";
function CombinedFunction(props) {
- const billetBankObject = props.billetBankObject;
- const uniqueNamesSet = new Set();
-
- let collapsibleTitle = props.collapsibleTitle;
- let headerTitles = props.headerTitles;
- let milpacArray = props.milpacArray;
-
- let array = Array(billetBankObject.length)
- .fill()
- .map(() => []);
-
- if (props.usePrimaryOnly === true) {
- for (let milpacIdCombat in milpacArray[0].combat.profiles) {
- let name = milpacArray[0].combat.profiles[milpacIdCombat].realName;
- let rank = milpacArray[0].combat.profiles[milpacIdCombat].rank.rankFull;
- let primary = milpacArray[0].combat.profiles[milpacIdCombat].primary;
- let fullName = rank + " " + name;
- let primarySortKey =
- milpacArray[0].combat.profiles[milpacIdCombat].primary.positionId;
-
- for (let index in billetBankObject) {
- if (billetBankObject[index].includes(primary.positionId)) {
- array[index].push({
- fullName: fullName,
- position: primary,
- isPrimary: "true",
- sortKey: primarySortKey,
- itemKey: milpacIdCombat,
- listKey: primarySortKey + milpacIdCombat,
- });
- uniqueNamesSet.add(fullName);
-
- // Sorting the array based on the order of positionIds in the billetBankObject array
- array[index].sort((a, b) => {
- const aIndex = billetBankObject[index].indexOf(a.sortKey);
- const bIndex = billetBankObject[index].indexOf(b.sortKey);
- return aIndex - bIndex;
- });
- }
- }
- }
- } else if (props.usePrimaryOnly !== true) {
- for (let milpacIdCombat in milpacArray[0].combat.profiles) {
- let name = milpacArray[0].combat.profiles[milpacIdCombat].realName;
- let rank = milpacArray[0].combat.profiles[milpacIdCombat].rank.rankFull;
- let primary = milpacArray[0].combat.profiles[milpacIdCombat].primary;
- let fullName = rank + " " + name;
- let primarySortKey =
- milpacArray[0].combat.profiles[milpacIdCombat].primary.positionId;
-
- for (let index in billetBankObject) {
- if (billetBankObject[index].includes(primary.positionId)) {
- array[index].push({
- fullName: fullName,
- position: primary,
- isPrimary: "true",
- sortKey: primarySortKey,
- itemKey: milpacIdCombat,
- listKey: primarySortKey + milpacIdCombat,
- });
- uniqueNamesSet.add(fullName);
- }
-
- for (let index2 in milpacArray[0].combat.profiles[milpacIdCombat]
- .secondaries) {
- let secondary =
- milpacArray[0].combat.profiles[milpacIdCombat].secondaries[index2];
- let secondarySortKey =
- milpacArray[0].combat.profiles[milpacIdCombat].secondaries[index2]
- .positionId;
-
- if (!billetBankObject[index].includes(secondary.positionId)) {
- continue;
- }
-
- array[index].push({
- fullName: fullName,
- position: secondary,
- isPrimary: "false",
- sortKey: secondarySortKey,
- itemKey: milpacIdCombat,
- listKey: secondarySortKey + milpacIdCombat,
- });
- uniqueNamesSet.add(fullName);
- }
- }
- }
-
- for (let milpacIdReserve in milpacArray[0].reserve.profiles) {
- let rName = milpacArray[0].reserve.profiles[milpacIdReserve].realName;
- let rRank =
- milpacArray[0].reserve.profiles[milpacIdReserve].rank.rankFull;
- let rPrimary = milpacArray[0].reserve.profiles[milpacIdReserve].primary;
- let rFullName = rRank + " " + rName;
- let rPrimarySortKey =
- milpacArray[0].reserve.profiles[milpacIdReserve].primary.positionId;
-
- for (let index in billetBankObject) {
- if (billetBankObject[index].includes(rPrimary.positionId)) {
- array[index].push({
- fullName: rFullName,
- position: rPrimary,
- isPrimary: "true",
- sortKey: rPrimarySortKey,
- itemKey: milpacIdReserve,
- listKey: rPrimarySortKey + milpacIdReserve,
- });
- uniqueNamesSet.add(rFullName);
- }
-
- for (let rIndex in milpacArray[0].reserve.profiles[milpacIdReserve]
- .secondaries) {
- let rSecondary =
- milpacArray[0].reserve.profiles[milpacIdReserve].secondaries[
- rIndex
- ];
- let rSecondarySortKey =
- milpacArray[0].reserve.profiles[milpacIdReserve].secondaries[rIndex]
- .positionId;
-
- if (!billetBankObject[index].includes(rSecondary.positionId)) {
- continue;
- }
-
- array[index].push({
- fullName: rFullName,
- position: rSecondary,
- isPrimary: "false",
- sortKey: rSecondarySortKey,
- itemKey: milpacIdReserve,
- listKey: rSecondarySortKey + milpacIdReserve,
- });
- uniqueNamesSet.add(rFullName);
- }
-
- // Sorting the array based on the order of positionIds in the billetBankObject array
- array[index].sort((a, b) => {
- const aIndex = billetBankObject[index].indexOf(a.sortKey);
- const bIndex = billetBankObject[index].indexOf(b.sortKey);
- return aIndex - bIndex;
- });
- }
- }
- }
-
return (
-
-
-
- {array.map((subArray, index) => (
-
-
-
- {headerTitles[index]}
- |
-
- Unit Strength: {array[index].length}
- |
-
- {subArray.map((item, subIndex) => (
-
-
-
- {item.fullName}
-
- |
- {item.position.positionTitle} |
-
- ))}
-
- ))}
-
-
-
+
diff --git a/client/src/modules/Generic/MilpacParse.js b/client/src/modules/Generic/MilpacParse.js
new file mode 100644
index 0000000..1140e1c
--- /dev/null
+++ b/client/src/modules/Generic/MilpacParse.js
@@ -0,0 +1,140 @@
+import React from "react";
+import ArrayMap from "./ArrayMap.js";
+
+/*Milpac Parse is used to compare the API response (milpacArray) against desired position ID's (billetBankObject). If for example, a person is a Milpacs Clerk and billetBankObject
+is set to check for Milpacs Clerks, Milpac Parse will search for matching entries within the API resonse. If there is someone that matches, they are pushed to an output array. (returnArray)
+This particular instance of milpacArray is designed to parse an entire object for matching entries, i.e. It will parse all of First Battalion, and push out an array
+for each company within first battalion if asked to do so.*/
+
+function MilpacParse(props) {
+ const billetBankObject = props.billetBankObject;
+ let milpacArray = props.milpacArray;
+
+ /*Currently broken. Sypolt, pls fix.
+ const uniqueNamesSet = new Set();
+ */
+
+ let returnArray = Array(billetBankObject.length)
+ .fill()
+ .map(() => []);
+
+ //First, check the combat roster primaries for matching billet id's, then push them to the return array if match is found.
+
+ for (let milpacIdCombat in milpacArray[0].combat.profiles) {
+ let name = milpacArray[0].combat.profiles[milpacIdCombat].realName;
+ let rank = milpacArray[0].combat.profiles[milpacIdCombat].rank.rankFull;
+ let primary = milpacArray[0].combat.profiles[milpacIdCombat].primary;
+ let fullName = rank + " " + name;
+ let primarySortKey =
+ milpacArray[0].combat.profiles[milpacIdCombat].primary.positionId;
+
+ for (let index in billetBankObject) {
+ if (billetBankObject[index].includes(primary.positionId)) {
+ returnArray[index].push({
+ fullName: fullName,
+ position: primary,
+ isPrimary: "true",
+ sortKey: primarySortKey,
+ itemKey: milpacIdCombat,
+ listKey: primarySortKey + milpacIdCombat,
+ });
+ //uniqueNamesSet.add(fullName);
+ }
+
+ //Next, check the combat roster secondaries for matching billet id's, then push to return array if match is found.
+
+ for (let index2 in milpacArray[0].combat.profiles[milpacIdCombat]
+ .secondaries) {
+ let secondary =
+ milpacArray[0].combat.profiles[milpacIdCombat].secondaries[index2];
+ let secondarySortKey =
+ milpacArray[0].combat.profiles[milpacIdCombat].secondaries[index2]
+ .positionId;
+
+ if (!billetBankObject[index].includes(secondary.positionId)) {
+ continue;
+ }
+
+ returnArray[index].push({
+ fullName: fullName,
+ position: secondary,
+ isPrimary: "false",
+ sortKey: secondarySortKey,
+ itemKey: milpacIdCombat,
+ listKey: secondarySortKey + milpacIdCombat,
+ });
+ //uniqueNamesSet.add(fullName);
+ }
+ }
+ }
+
+ //After the Combat Roster, check the Reserves.
+
+ for (let milpacIdReserve in milpacArray[0].reserve.profiles) {
+ let rName = milpacArray[0].reserve.profiles[milpacIdReserve].realName;
+ let rRank = milpacArray[0].reserve.profiles[milpacIdReserve].rank.rankFull;
+ let rPrimary = milpacArray[0].reserve.profiles[milpacIdReserve].primary;
+ let rFullName = rRank + " " + rName;
+ let rPrimarySortKey =
+ milpacArray[0].reserve.profiles[milpacIdReserve].primary.positionId;
+
+ //Check the Reserve primaries, then push to return array if match is found.
+
+ for (let index in billetBankObject) {
+ if (billetBankObject[index].includes(rPrimary.positionId)) {
+ returnArray[index].push({
+ fullName: rFullName,
+ position: rPrimary,
+ isPrimary: "true",
+ sortKey: rPrimarySortKey,
+ itemKey: milpacIdReserve,
+ listKey: rPrimarySortKey + milpacIdReserve,
+ });
+ //uniqueNamesSet.add(rFullName);
+ }
+
+ //Check the Reserve secondaries, then push to return array if match is found.
+
+ for (let rIndex in milpacArray[0].reserve.profiles[milpacIdReserve]
+ .secondaries) {
+ let rSecondary =
+ milpacArray[0].reserve.profiles[milpacIdReserve].secondaries[rIndex];
+ let rSecondarySortKey =
+ milpacArray[0].reserve.profiles[milpacIdReserve].secondaries[rIndex]
+ .positionId;
+
+ if (!billetBankObject[index].includes(rSecondary.positionId)) {
+ continue;
+ }
+
+ returnArray[index].push({
+ fullName: rFullName,
+ position: rSecondary,
+ isPrimary: "false",
+ sortKey: rSecondarySortKey,
+ itemKey: milpacIdReserve,
+ listKey: rSecondarySortKey + milpacIdReserve,
+ });
+ //uniqueNamesSet.add(rFullName);
+ }
+
+ // Sort the array based on the order of positionIds in the billetBankObject array. This is mostly accurate, however ranks are not taken into account in the final display
+
+ returnArray[index].sort((a, b) => {
+ const aIndex = billetBankObject[index].indexOf(a.sortKey);
+ const bIndex = billetBankObject[index].indexOf(b.sortKey);
+ return aIndex - bIndex;
+ });
+ }
+ }
+
+ console.log(returnArray);
+
+ return (
+
+ );
+}
+
+export default MilpacParse;