munch2024 / munch

2 stars 11 forks source link

Documentation Assistance Async Function Issue #61

Closed mitshelle closed 8 months ago

mitshelle commented 8 months ago

I have found a code snippet that exports data frames. However, the current implementation does not have any documentation describing its usuage.

This piece of code includes one large function with multiple exporting tasks inside. It may have confusing code as it also involves SQL. To improve readability, it could have better comments to help understand it better.

The code does not have proper documentation describing the function's purpose, parameters, and the return values.

Goals for Refactoring:

  1. Refactoring the code by including comments about its purpose.

Below is the attached code snippet of the issue.

const onClick = async () => {
    if (exporting) return;
    setExporting(true);
    try {
        if (props.parseDslType === "server") {
            await communicationStore.comm?.sendMsg("export_dataframe_by_payload", {
                payload: {
                    workflow: storeRef.current?.workflow,
                },
                encodings: storeRef.current?.currentVis.encodings,
            });
        } else {
            const sql = parser_dsl_with_meta(
                "pygwalker_mid_table",
                JSON.stringify({workflow: storeRef.current?.workflow}),
                JSON.stringify({"pygwalker_mid_table": props.fieldMetas})
            );
            await communicationStore.comm?.sendMsg("export_dataframe_by_sql", {
                sql: sql,
                encodings: storeRef.current?.currentVis.encodings
            });
        }
        exportSuccess();
    } catch (_) {
        setExporting(false);
    }
}

return {
    key: "export_dataframe",
    label: "export_dataframe",
    icon: (iconProps?: any) => {
        return exporting ? <LoadingIcon width={36} height={36} /> : <DocumentArrowDownIcon {...iconProps} />
    },
    onClick: onClick,
}