mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
* Set corejs version in .babelrc so Jest doesn't complain. * Rewrite services/routes in TypeScript. * Add TypeScript definitions for DialogComponent. * Make image paths more portable * Add current route context and hook. * Make EmptyState more flexible by being able to pass in getSteps function. * Rewrite ItemsList in TypeScript. * Introduce the possibility to add custom sorters for a column. * Rearrange props to be friendly to TypeScript. * Type definitions for NotificationApi. * Use Databricks query editor components for databricks_internal type of query runner. * URL Escape password in Alembic configuration. * Compare types in migrations.
43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
import { has, map, isObject } from "lodash";
|
|
import { axios } from "@/services/axios";
|
|
import { fetchDataFromJob } from "@/services/query-result";
|
|
|
|
export const SCHEMA_NOT_SUPPORTED = 1;
|
|
export const SCHEMA_LOAD_ERROR = 2;
|
|
export const IMG_ROOT = "static/images/db-logos";
|
|
|
|
function mapSchemaColumnsToObject(columns) {
|
|
return map(columns, column => (isObject(column) ? column : { name: column }));
|
|
}
|
|
|
|
const DataSource = {
|
|
query: () => axios.get("api/data_sources"),
|
|
get: ({ id }) => axios.get(`api/data_sources/${id}`),
|
|
types: () => axios.get("api/data_sources/types"),
|
|
create: data => axios.post(`api/data_sources`, data),
|
|
save: data => axios.post(`api/data_sources/${data.id}`, data),
|
|
test: data => axios.post(`api/data_sources/${data.id}/test`),
|
|
delete: ({ id }) => axios.delete(`api/data_sources/${id}`),
|
|
fetchSchema: (data, refresh = false) => {
|
|
const params = {};
|
|
|
|
if (refresh) {
|
|
params.refresh = true;
|
|
}
|
|
|
|
return axios
|
|
.get(`api/data_sources/${data.id}/schema`, { params })
|
|
.then(data => {
|
|
if (has(data, "job")) {
|
|
return fetchDataFromJob(data.job.id).catch(error =>
|
|
error.code === SCHEMA_NOT_SUPPORTED ? [] : Promise.reject(new Error(data.job.error))
|
|
);
|
|
}
|
|
return has(data, "schema") ? data.schema : Promise.reject();
|
|
})
|
|
.then(tables => map(tables, table => ({ ...table, columns: mapSchemaColumnsToObject(table.columns) })));
|
|
},
|
|
};
|
|
|
|
export default DataSource;
|