MCPcopy Create free account
hub / github.com/Shazbot/WH3-Mod-Manager / executeGroupByColumnsNode

Function executeGroupByColumnsNode

src/nodeExecutor.ts:817–923  ·  view source on GitHub ↗
(
  nodeId: string,
  textValue: string,
  inputData: DBTablesNodeData,
  config?: unknown,
)

Source from the content-addressed store, hash-verified

815}
816
817async function executeGroupByColumnsNode(
818 nodeId: string,
819 textValue: string,
820 inputData: DBTablesNodeData,
821 config?: unknown,
822): Promise<NodeExecutionResult> {
823 console.log(`GroupByColumns Node ${nodeId}: Processing with textValue:`, textValue);
824 console.log(`GroupByColumns Node ${nodeId}: Input data:`, inputData);
825
826 if (!inputData || inputData.type !== "TableSelection") {
827 return { success: false, error: "Invalid input: Expected TableSelection data" };
828 }
829
830 // Parse the column selections from textValue
831 const parsed = getNodeConfig<{ column1?: string; column2?: string; onlyForMultiple?: boolean }>(config, textValue);
832 if (!parsed) {
833 return {
834 success: false,
835 error: "Invalid column configuration. Expected JSON with column1 and column2 fields.",
836 };
837 }
838 const column1 = parsed.column1 || "";
839 const column2 = parsed.column2 || "";
840 const onlyForMultiple = parsed.onlyForMultiple || false;
841
842 if (!column1 || column1.trim() === "" || !column2 || column2.trim() === "") {
843 return {
844 success: false,
845 error: `Both column1 and column2 must be selected. Received: column1="${column1}", column2="${column2}"`,
846 };
847 }
848
849 // Process each table
850 const groupedData = new Map<string, string[]>();
851
852 for (const tableData of inputData.tables) {
853 if (
854 !tableData.table.tableSchema ||
855 !tableData.table.schemaFields ||
856 tableData.table.schemaFields.length === 0
857 ) {
858 console.log(`Missing table data, skipping ${tableData.name}!`);
859 continue;
860 }
861
862 const rows = getRowsForPackedFile(tableData.table);
863
864 // Find the column indices
865 const column1Index = getColumnIndexForPackedFile(tableData.table, column1);
866 const column2Index = getColumnIndexForPackedFile(tableData.table, column2);
867
868 if (column1Index === -1 || column2Index === -1) {
869 console.warn(
870 `Columns ${column1} or ${column2} not found in table ${tableData.name}. Skipping this table.`,
871 );
872 continue;
873 }
874

Callers 1

executeNodeActionFunction · 0.85

Calls 5

getNodeConfigFunction · 0.85
clearMethod · 0.80
getRowsForPackedFileFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected