You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2020/11/30 17:32:10 UTC
[incubator-superset] 01/01: add datasets api file
This is an automated email from the ASF dual-hosted git repository.
hugh pushed a commit to branch hugh/so-1117-fe-api
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit 1ddf808be430c00ee48652dffbc7e7578cc36c07
Author: hughhhh <hu...@gmail.com>
AuthorDate: Mon Nov 30 09:31:33 2020 -0800
add datasets api file
---
superset-frontend/src/api/dataset.ts | 42 ++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/superset-frontend/src/api/dataset.ts b/superset-frontend/src/api/dataset.ts
new file mode 100644
index 0000000..b587270
--- /dev/null
+++ b/superset-frontend/src/api/dataset.ts
@@ -0,0 +1,42 @@
+import { SupersetClient, JsonResponse } from '@superset-ui/core';
+import rison from 'rison';
+
+export const get = async (userId: number) => {
+ const queryParams = rison.encode({
+ filters: [
+ {
+ col: 'owners',
+ opr: 'rel_m_m',
+ value: userId,
+ },
+ ],
+ order_column: 'changed_on_delta_humanized',
+ order_direction: 'desc',
+ });
+ const endpoint = `/api/v1/dataset?q=${queryParams}`;
+ const data: JsonResponse = await SupersetClient.get({
+ endpoint,
+ });
+ return data.json.result;
+};
+
+export const put = async (
+ datasetId: number,
+ sql: string,
+ columns: Array<Record<string, any>>,
+ overrideColumns: boolean,
+) => {
+ const endpoint = `api/v1/dataset/${datasetId}?override_columns=${overrideColumns}`;
+ const headers = { 'Content-Type': 'application/json' };
+ const body = JSON.stringify({
+ sql,
+ columns,
+ });
+
+ const data: JsonResponse = await SupersetClient.put({
+ endpoint,
+ headers,
+ body,
+ });
+ return data.json.result;
+};