MCPcopy Index your code
hub / github.com/tone-row/flowchart-fun / MappingData

Function MappingData

app/src/components/ImportDataDialog.tsx:294–581  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

292}
293
294const MappingData = () => {
295 const columnNames = useImportData((state) => state.columnNames);
296 const columnSelectionValues = useMemo(
297 () =>
298 columnNames.map((name) => ({
299 text: name,
300 value: name,
301 })),
302 [columnNames]
303 );
304 const columnSelectionValuesWithNone = useMemo(
305 () => [
306 {
307 text: "None",
308 value: "",
309 },
310 ...columnSelectionValues,
311 ],
312 [columnSelectionValues]
313 );
314 const columnValues = useImportData((state) => state.columnValues);
315 const [formState, setFormState] = useState<ImportDataFormType>({
316 idColumn: columnNames[0],
317 nodeLabelColumn: columnNames[0],
318 edgesDeclared: "none",
319 });
320
321 const handleFormChange = (name: string, value: string) => {
322 setFormState((prevState) => ({ ...prevState, [name]: value }));
323 };
324
325 const processingErrorMessage = useImportData(
326 (state) => state.processingErrorMessage
327 );
328
329 const onSubmit = useMutation(
330 "process-data",
331 async (formState: ImportDataFormType) => {
332 await fetch("/api/data/process", {
333 method: "POST",
334 headers: {
335 "Content-Type": "application/json",
336 },
337 body: JSON.stringify({
338 mapping: formState,
339 data: useImportData.getState().records,
340 }),
341 }).then((res) => {
342 if (res.ok) {
343 // move to the next step
344 (
345 res.json() as Promise<{
346 numNodes: number;
347 numEdges: number;
348 graphString: string;
349 }>
350 ).then((data) => {
351 // here we would set the final data and ask for confirmation

Callers

nothing calls this directly

Calls 1

handleFormChangeFunction · 0.85

Tested by

no test coverage detected