Skip to content

Commit

Permalink
DR-3313: Point to POST Query Data Endpoints (#1540)
Browse files Browse the repository at this point in the history
* Point to POST endpoints now

* lint

* Fix: update sort field name and empty check

* code reivew

* Update errors.spec.js
  • Loading branch information
snf2ye authored Nov 28, 2023
1 parent 68522a3 commit 53500e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions cypress/integration/errors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('test error handling', () => {
});

it('displays error toasts with error detail', () => {
cy.intercept('GET', '/api/repository/v1/datasets/**/data/**', {
cy.intercept('POST', '/api/repository/v1/datasets/**/data/**', {
statusCode: 401,
body: {
message: 'Was not able to query',
Expand All @@ -31,7 +31,7 @@ describe('test error handling', () => {
});

it('displays error toasts with empty error detail', () => {
cy.intercept('GET', '/api/repository/v1/datasets/**/data/**', {
cy.intercept('POST', '/api/repository/v1/datasets/**/data/**', {
statusCode: 401,
body: {
message: 'Was not able to query',
Expand All @@ -46,7 +46,7 @@ describe('test error handling', () => {
});

it('displays error toasts with no error detail', () => {
cy.intercept('GET', '/api/repository/v1/datasets/**/data/**', {
cy.intercept('POST', '/api/repository/v1/datasets/**/data/**', {
statusCode: 401,
body: {
message: 'Was not able to query',
Expand Down
35 changes: 18 additions & 17 deletions src/sagas/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import _ from 'lodash';
import { RouterRootState } from 'connected-react-router';

import { showNotification } from 'modules/notifications';
import { JobModelJobStatusEnum } from 'generated/tdr';
import { JobModelJobStatusEnum, SqlSortDirection } from 'generated/tdr';
import {
ActionTypes,
Status,
Expand Down Expand Up @@ -787,16 +787,18 @@ export function* watchGetDatasetByIdSuccess(): any {

export function* previewData({ payload }: any): any {
const queryState = yield select(getQuery);
const offset = queryState.page * queryState.rowsPerPage;
const limit = queryState.rowsPerPage;
const sort = queryState.orderProperty === undefined ? '' : `&sort=${queryState.orderProperty}`;
const sortDirection =
queryState.orderDirection === undefined ? '' : `&direction=${queryState.orderDirection}`;
const filter =
queryState.filterStatement === undefined ? '' : `&filter=${queryState.filterStatement}`;
const query = `/api/repository/v1/${payload.resourceType}s/${payload.resourceId}/data/${payload.table}?offset=${offset}&limit=${limit}${sort}${sortDirection}${filter}`;
const queryDataRequest = {
offset: queryState.page * queryState.rowsPerPage,
limit: queryState.rowsPerPage,
sort: _.isEmpty(queryState.orderProperty) ? DbColumns.ROW_ID : `${queryState.orderProperty}`,
direction: _.isEmpty(queryState.orderDirection)
? SqlSortDirection.Asc
: `${queryState.orderDirection}`,
filter: _.isEmpty(queryState.filterStatement) ? '' : `${queryState.filterStatement}`,
};
const query = `/api/repository/v1/${payload.resourceType}s/${payload.resourceId}/data/${payload.table}`;
try {
const response = yield call(authGet, query);
const response = yield call(authPost, query, queryDataRequest);
yield put({
type: ActionTypes.PREVIEW_DATA_SUCCESS,
payload: {
Expand Down Expand Up @@ -824,12 +826,11 @@ export function* getColumnStats({ payload }: any): any {
const baseQuery = `/api/repository/v1/${resourceType}s/${resourceId}/data/${tableName}/statistics/${columnName}`;
const queryState = yield select(getQuery);
const { filterStatement } = queryState;
const filter = filterStatement === undefined ? '' : `?filter=${filterStatement}`;
const filteredQuery = `${baseQuery}${filter}`;
const filter = _.isEmpty(filterStatement) ? '' : filterStatement;
try {
switch (columnStatsRetrievalType) {
case ColumnStatsRetrievalType.RETRIEVE_ALL_TEXT: {
const response = yield call(authGet, baseQuery);
const response = yield call(authPost, baseQuery);
yield put({
type: ActionTypes.COLUMN_STATS_TEXT_SUCCESS,
payload: {
Expand All @@ -840,7 +841,7 @@ export function* getColumnStats({ payload }: any): any {
break;
}
case ColumnStatsRetrievalType.RETRIEVE_ALL_NUMERIC: {
const numericResponse = yield call(authGet, baseQuery);
const numericResponse = yield call(authPost, baseQuery);
yield put({
type: ActionTypes.COLUMN_STATS_NUMERIC_SUCCESS,
payload: {
Expand All @@ -851,7 +852,7 @@ export function* getColumnStats({ payload }: any): any {
break;
}
case ColumnStatsRetrievalType.RETRIEVE_FILTERED_TEXT: {
const filteredResponse = yield call(authGet, filteredQuery);
const filteredResponse = yield call(authPost, baseQuery, { filter });
yield put({
type: ActionTypes.COLUMN_STATS_FILTERED_TEXT_SUCCESS,
payload: {
Expand All @@ -862,8 +863,8 @@ export function* getColumnStats({ payload }: any): any {
break;
}
case ColumnStatsRetrievalType.RETRIEVE_ALL_AND_FILTERED_TEXT: {
const queries = [baseQuery, filteredQuery];
const responses = yield all(queries.map((q) => call(authGet, q)));
const payloads = ['', filterStatement];
const responses = yield all(payloads.map((p) => call(authPost, baseQuery, { filter: p })));
yield put({
type: ActionTypes.COLUMN_STATS_ALL_AND_FILTERED_TEXT_SUCCESS,
payload: {
Expand Down

0 comments on commit 53500e4

Please sign in to comment.