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 21:28:05 UTC
[incubator-superset] branch master updated: feat: Create api
abstraction layer for dataset network calls (#11855)
This is an automated email from the ASF dual-hosted git repository.
hugh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new 3cd94d6 feat: Create api abstraction layer for dataset network calls (#11855)
3cd94d6 is described below
commit 3cd94d6da9b15286f82e6f6de0ecae26acb8ae54
Author: Hugh A. Miles II <hu...@gmail.com>
AuthorDate: Mon Nov 30 13:27:27 2020 -0800
feat: Create api abstraction layer for dataset network calls (#11855)
* add datasets api file
* Update dataset.ts
* Update dataset.ts
* Update dataset.ts
---
superset-frontend/src/api/dataset.ts | 61 ++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/superset-frontend/src/api/dataset.ts b/superset-frontend/src/api/dataset.ts
new file mode 100644
index 0000000..048487c
--- /dev/null
+++ b/superset-frontend/src/api/dataset.ts
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { SupersetClient, JsonResponse } from '@superset-ui/core';
+import rison from 'rison';
+
+export const getByUser = 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;
+};