The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
import { t } from "ttag";
import type { PythonTransformSourceValidationResult } from "metabase/plugins";
import type {
PythonTransformSource,
PythonTransformSourceDraft,
} from "metabase-types/api";
export function getPythonSourceValidationResult(
source: PythonTransformSourceDraft,
): PythonTransformSourceValidationResult {
if (!source["source-database"]) {
return { isValid: false, errorMessage: t`Select a source database` };
}
if (source.body.trim() === "") {
return {
isValid: false,
errorMessage: t`The Python script cannot be empty`,
};
}
if (source["source-tables"].length === 0) {
return {
isValid: false,
errorMessage: t`Select at least one table to alias`,
};
}
return { isValid: true };
}
export function isPythonTransformSource(
source: PythonTransformSourceDraft,
): source is PythonTransformSource {
return source.type === "python" && source["source-database"] !== undefined;
}
export function canRunPythonTransformSource(
source: PythonTransformSourceDraft,
): source is PythonTransformSource {
return (
isPythonTransformSource(source) &&
getPythonSourceValidationResult(source).isValid
);
}