Skip to content

Commit

Permalink
feat: Create api abstraction layer for dataset network calls (apache#…
Browse files Browse the repository at this point in the history
…11855)

* add datasets api file

* Update dataset.ts

* Update dataset.ts

* Update dataset.ts
  • Loading branch information
hughhhh committed Nov 30, 2020
1 parent a0b8135 commit 3cd94d6
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions superset-frontend/src/api/dataset.ts
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 3cd94d6

Please sign in to comment.