Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DR-3313: Point to POST Query Data Endpoints #1540

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're in here, should we rename the method viewData? Or something that doesn't have preview in the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be hard to actually remove all of the references to "preview" data. I think I'd rather leave it all as preview rather than changing only some of the references to the new name, especially since this would only be a code-facing change rather than user-facing.

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