Unverified Commit d3a0cda9 authored by Tamika Tannis's avatar Tamika Tannis Committed by GitHub

Cleanup ducks folder: Address a few more inconsistencies. (#197)

* Address a few more inconsistencies

* Fix Resources.ts

* Some tweaks
parent 63306c91
......@@ -2,7 +2,7 @@ import axios, { AxiosResponse } from 'axios';
import { Tag } from 'interfaces';
import { metadataAllTags, AllTagsResponseAPI } from '../v0';
import { metadataAllTags, AllTagsAPI } from '../v0';
describe('metadataAllTags', () => {
it('resolves with array of sorted result of response.data.tags on success', async () => {
......@@ -14,7 +14,7 @@ describe('metadataAllTags', () => {
{tag_count: 1, tag_name: 'atest'},
{tag_count: 2, tag_name: 'test'}
];
const mockResponse: AxiosResponse<AllTagsResponseAPI> = {
const mockResponse: AxiosResponse<AllTagsAPI> = {
data: {
tags: rawTags,
msg: 'Success'
......
......@@ -3,13 +3,13 @@ import axios, { AxiosResponse } from 'axios';
import { sortTagsAlphabetical } from 'ducks/utilMethods';
import { Tag } from 'interfaces';
export type AllTagsResponseAPI = {
export type AllTagsAPI = {
msg: string;
tags: Tag[];
};
export function metadataAllTags() {
return axios.get('/api/metadata/v0/tags').then((response: AxiosResponse<AllTagsResponseAPI>) => {
return axios.get('/api/metadata/v0/tags').then((response: AxiosResponse<AllTagsAPI>) => {
return response.data.tags.sort(sortTagsAlphabetical);
})
};
......@@ -2,13 +2,13 @@ import axios, { AxiosResponse } from 'axios';
import { AnnouncementPost } from 'interfaces';
import { announcementsGet, AnnouncementsResponseAPI } from '../v0';
import { announcementsGet, AnnouncementsAPI } from '../v0';
jest.mock('axios');
describe('announcementsGet', () => {
let expectedPosts: AnnouncementPost[];
let mockResponse: AxiosResponse<AnnouncementsResponseAPI>;
let mockResponse: AxiosResponse<AnnouncementsAPI>;
beforeAll(() => {
expectedPosts = [{ date: '12/31/1999', title: 'Test', html_content: '<div>Test content</div>' }];
mockResponse = {
......
......@@ -2,7 +2,7 @@ import axios, { AxiosResponse } from 'axios';
import { AnnouncementPost } from 'interfaces';
export type AnnouncementsResponseAPI = {
export type AnnouncementsAPI = {
msg: string;
posts: AnnouncementPost[];
};
......@@ -12,7 +12,7 @@ export function announcementsGet() {
method: 'get',
url: '/api/announcements/v0/',
})
.then((response: AxiosResponse<AnnouncementsResponseAPI>) => {
.then((response: AxiosResponse<AnnouncementsAPI>) => {
return response.data.posts;
})
};
......@@ -17,15 +17,19 @@ import {
/* ACTIONS */
export function addBookmark(resourceKey: string, resourceType: string): AddBookmarkRequest {
return {
resourceKey,
resourceType,
payload: {
resourceKey,
resourceType,
},
type: AddBookmark.REQUEST,
}
}
export function removeBookmark(resourceKey: string, resourceType: string): RemoveBookmarkRequest {
return {
resourceKey,
resourceType,
payload: {
resourceKey,
resourceType,
},
type: RemoveBookmark.REQUEST,
}
}
......@@ -36,7 +40,9 @@ export function getBookmarks(): GetBookmarksRequest {
}
export function getBookmarksForUser(userId: string): GetBookmarksForUserRequest {
return {
userId,
payload: {
userId,
},
type: GetBookmarksForUser.REQUEST,
}
}
......
......@@ -20,7 +20,7 @@ import {
export function* addBookmarkWorker(action: AddBookmarkRequest): SagaIterator {
let response;
const { resourceKey, resourceType } = action;
const { resourceKey, resourceType } = action.payload;
try {
yield call(addBookmark, resourceKey, resourceType);
......@@ -39,7 +39,7 @@ export function* addBookmarkWatcher(): SagaIterator {
export function* removeBookmarkWorker(action: RemoveBookmarkRequest): SagaIterator {
let response;
const { resourceKey, resourceType } = action;
const { resourceKey, resourceType } = action.payload;
try {
response = yield call(removeBookmark, resourceKey, resourceType);
yield put({ type: RemoveBookmark.SUCCESS, payload: { resourceKey, resourceType }});
......@@ -68,7 +68,7 @@ export function* getBookmarksWatcher(): SagaIterator {
export function* getBookmarkForUserWorker(action: GetBookmarksForUserRequest): SagaIterator {
let response;
const { userId } = action;
const { userId } = action.payload;
try {
response = yield call(getBookmarks, userId);
yield put({ type: GetBookmarksForUser.SUCCESS, payload: { userId, bookmarks: response.bookmarks } });
......
......@@ -31,7 +31,13 @@ describe('bookmark ducks', () => {
describe('actions', () => {
describe('addBookmark', () => {
it('should return action of type AddBookmarkRequest', () => {
expect(addBookmark(testResourceKey, testResourceType)).toEqual({ type: AddBookmark.REQUEST, resourceKey: testResourceKey, resourceType: testResourceType });
expect(addBookmark(testResourceKey, testResourceType)).toEqual({
type: AddBookmark.REQUEST,
payload: {
resourceKey: testResourceKey,
resourceType: testResourceType,
},
});
});
});
......@@ -43,13 +49,24 @@ describe('bookmark ducks', () => {
describe('getBookmarksForUser', () => {
it('should return action of type GetBookmarksForUserRequest', () => {
expect(getBookmarksForUser(testUserId)).toEqual({ type: GetBookmarksForUser.REQUEST, userId: testUserId });
expect(getBookmarksForUser(testUserId)).toEqual({
type: GetBookmarksForUser.REQUEST,
payload: {
userId: testUserId,
},
});
});
});
describe('removeBookmark', () => {
it('should return action of type RemoveBookmarkRequest', () => {
expect(removeBookmark(testResourceKey, testResourceType)).toEqual({ type: RemoveBookmark.REQUEST, resourceKey: testResourceKey, resourceType: testResourceType });
expect(removeBookmark(testResourceKey, testResourceType)).toEqual({
type: RemoveBookmark.REQUEST,
payload: {
resourceKey: testResourceKey,
resourceType: testResourceType,
},
});
});
});
});
......@@ -238,11 +255,11 @@ describe('sagas', () => {
];
return expectSaga(getBookmarkForUserWorker, action)
.provide([
[matchers.call.fn(getBkmrks), { bookmarks, userId: action.userId }],
[matchers.call.fn(getBkmrks), { bookmarks, userId: action.payload.userId }],
])
.put({
type: GetBookmarksForUser.SUCCESS,
payload: { bookmarks, userId: action.userId }
payload: { bookmarks, userId: action.payload.userId }
})
.run();
});
......@@ -254,7 +271,7 @@ describe('sagas', () => {
])
.put({
type: GetBookmarksForUser.FAILURE,
payload: { bookmarks: [], userId: action.userId }
payload: { bookmarks: [], userId: action.payload.userId }
})
.run();
});
......@@ -285,7 +302,7 @@ describe('sagas', () => {
])
.put({
type: RemoveBookmark.SUCCESS,
payload: { resourceKey: action.resourceKey, resourceType: action.resourceType }
payload: { resourceKey: action.payload.resourceKey, resourceType: action.payload.resourceType }
})
.run();
});
......@@ -297,7 +314,7 @@ describe('sagas', () => {
])
.put({
type: RemoveBookmark.FAILURE,
payload: { resourceKey: action.resourceKey, resourceType: action.resourceType }
payload: { resourceKey: action.payload.resourceKey, resourceType: action.payload.resourceType }
})
.run();
});
......
......@@ -7,8 +7,10 @@ export enum AddBookmark {
}
export interface AddBookmarkRequest {
type: AddBookmark.REQUEST;
resourceKey: string;
resourceType: string;
payload: {
resourceKey: string;
resourceType: string;
};
}
export interface AddBookmarkResponse {
type: AddBookmark.SUCCESS | AddBookmark.FAILURE;
......@@ -24,8 +26,10 @@ export enum RemoveBookmark {
}
export interface RemoveBookmarkRequest {
type: RemoveBookmark.REQUEST;
resourceKey: string;
resourceType: string;
payload: {
resourceKey: string;
resourceType: string;
};
}
export interface RemoveBookmarkResponse {
type: RemoveBookmark.SUCCESS | RemoveBookmark.FAILURE;
......@@ -59,7 +63,9 @@ export enum GetBookmarksForUser {
}
export interface GetBookmarksForUserRequest {
type: GetBookmarksForUser.REQUEST;
userId: string;
payload: {
userId: string;
};
}
export interface GetBookmarksForUserResponse {
type: GetBookmarksForUser.SUCCESS | GetBookmarksForUser.FAILURE;
......
......@@ -2,14 +2,14 @@ import axios, { AxiosResponse } from 'axios';
import { TableResource } from 'interfaces';
export type PopularTablesResponse = {
export type PopularTablesAPI = {
msg: string;
results: TableResource[];
}
export function metadataPopularTables() {
return axios.get('/api/metadata/v0/popular_tables')
.then((response: AxiosResponse<PopularTablesResponse>) => {
.then((response: AxiosResponse<PopularTablesAPI>) => {
return response.data.results;
});
}
......@@ -6,20 +6,20 @@ import { DashboardSearchResults, TableSearchResults, UserSearchResults } from '.
const BASE_URL = '/api/search/v0';
interface SearchAllResponseAPI {
interface SearchAPI {
msg: string;
status_code: number;
search_term: string;
dashboards?: DashboardSearchResults;
tables?: TableSearchResults;
users?: UserSearchResults;
}
};
export function searchAll(options: SearchAllOptions, term: string) {
return axios.all([
axios.get(`${BASE_URL}/table?query=${term}&page_index=${options.tableIndex || 0}`),
// TODO PEOPLE - Add request for people here
]).then(axios.spread((tableResponse: AxiosResponse<SearchAllResponseAPI>) => {
]).then(axios.spread((tableResponse: AxiosResponse<SearchAPI>) => {
return {
search_term: tableResponse.data.search_term,
tables: tableResponse.data.tables,
......@@ -29,7 +29,7 @@ export function searchAll(options: SearchAllOptions, term: string) {
export function searchResource(pageIndex: number, resource: ResourceType, term: string) {
return axios.get(`${BASE_URL}/${resource}?query=${term}&page_index=${pageIndex}`)
.then((response: AxiosResponse) => {
.then((response: AxiosResponse<SearchAPI>) => {
const { data } = response;
const ret = { searchTerm: data.search_term };
['tables', 'users'].forEach((key) => {
......
......@@ -24,16 +24,20 @@ export interface SearchReducerState {
/* ACTIONS */
export function searchAll(term: string, options: SearchAllOptions = {}): SearchAllRequest {
return {
options,
term,
payload: {
options,
term,
},
type: SearchAll.REQUEST,
};
};
export function searchResource(resource: ResourceType, term: string, pageIndex: number): SearchResourceRequest {
return {
pageIndex,
term,
resource,
payload: {
pageIndex,
term,
resource,
},
type: SearchResource.REQUEST,
};
};
......@@ -72,7 +76,7 @@ export default function reducer(state: SearchReducerState = initialState, action
// updates search term to reflect action
return {
...state,
search_term: (<SearchAllRequest>action).term,
search_term: (<SearchAllRequest>action).payload.term,
isLoading: true,
};
case SearchResource.REQUEST:
......
......@@ -13,7 +13,7 @@ import {
} from './api/v0';
export function* searchAllWorker(action: SearchAllRequest): SagaIterator {
const { options, term } = action;
const { options, term } = action.payload;
try {
const searchResults = yield call(searchAll, options, term);
yield put({ type: SearchAll.SUCCESS, payload: searchResults });
......@@ -26,7 +26,7 @@ export function* searchAllWatcher(): SagaIterator {
};
export function* searchResourceWorker(action: SearchResourceRequest): SagaIterator {
const { pageIndex, resource, term } = action;
const { pageIndex, resource, term } = action.payload;
try {
const searchResults = yield call(searchResource, pageIndex, resource, term);
yield put({ type: SearchResource.SUCCESS, payload: searchResults });
......
......@@ -23,8 +23,10 @@ export enum SearchAll {
RESET = 'amundsen/search/SEARCH_ALL_RESET',
};
export interface SearchAllRequest {
options: SearchAllOptions;
term: string;
payload: {
options: SearchAllOptions;
term: string;
};
type: SearchAll.REQUEST;
};
export interface SearchAllResponse {
......@@ -47,9 +49,11 @@ export enum SearchResource {
FAILURE = 'amundsen/search/SEARCH_RESOURCE_FAILURE',
};
export interface SearchResourceRequest {
pageIndex: number;
resource: ResourceType;
term: string;
payload: {
pageIndex: number;
resource: ResourceType;
term: string;
};
type: SearchResource.REQUEST;
};
export interface SearchResourceResponse {
......
import { GetTableDataRequest } from 'ducks/tableMetadata/types';
import { filterFromObj, sortTagsAlphabetical } from 'ducks/utilMethods';
import { TableMetadata, Tag, User } from 'interfaces';
import { TableDataResponse } from './v0';
import { TableDataAPI } from './v0';
/**
* Generates the query string parameters needed for requests that act on a particular table resource.
*/
export function getTableQueryParams(tableDataObject: TableMetadata | GetTableDataRequest): string {
const { key } = tableDataObject;
return `key=${encodeURIComponent(key)}`;
export function getTableQueryParams(tableKey: string): string {
return `key=${encodeURIComponent(tableKey)}`;
}
/**
* Parses the response for table metadata to create a TableMetadata object
*/
export function getTableDataFromResponseData(responseData: TableDataResponse): TableMetadata {
export function getTableDataFromResponseData(responseData: TableDataAPI): TableMetadata {
return filterFromObj(responseData.tableData, ['owners', 'tags']) as TableMetadata;
}
/**
* Parses the response for table metadata to return the array of table owners
*/
export function getTableOwnersFromResponseData(responseData: TableDataResponse): { [id: string] : User } {
export function getTableOwnersFromResponseData(responseData: TableDataAPI): { [id: string] : User } {
// TODO: owner needs proper id, until then we have to remember that we are using display_name
const ownerObj = responseData.tableData.owners.reduce((resultObj, currentOwner) => {
resultObj[currentOwner.display_name] = currentOwner as User;
......@@ -34,6 +32,6 @@ export function getTableOwnersFromResponseData(responseData: TableDataResponse):
/**
* Parses the response for table metadata to return an array of sorted table tags
*/
export function getTableTagsFromResponseData(responseData: TableDataResponse): Tag[] {
export function getTableTagsFromResponseData(responseData: TableDataAPI): Tag[] {
return responseData.tableData.tags.sort(sortTagsAlphabetical);
}
......@@ -9,37 +9,39 @@ import { PreviewData, PreviewQueryParams, TableMetadata, User, Tag } from 'inter
const API_PATH = '/api/metadata/v0';
type MessageResponse = { msg: string };
// TODO: Consider created shared interfaces for ducks so we can reuse MessageAPI everywhere else
type MessageAPI = { msg: string };
type TableData = TableMetadata & {
owners: User[];
tags: Tag[];
};
export type DescriptionResponse = { description: string; } & MessageResponse;
export type LastIndexedResponse = { timestamp: string; } & MessageResponse;
export type PreviewDataResponse = { previewData: PreviewData; } & MessageResponse;
export type TableDataResponse = { tableData: TableData; } & MessageResponse;
export type DescriptionAPI = { description: string; } & MessageAPI;
export type LastIndexedAPI = { timestamp: string; } & MessageAPI;
export type PreviewDataAPI = { previewData: PreviewData; } & MessageAPI;
export type TableDataAPI= { tableData: TableData; } & MessageAPI;
/** HELPERS **/
import {
getTableQueryParams, getTableDataFromResponseData, getTableOwnersFromResponseData, getTableTagsFromResponseData,
} from './helpers';
export function metadataTableTags(tableData: TableMetadata) {
const tableParams = getTableQueryParams(tableData);
export function metadataTableTags(tableKey: string) {
const tableParams = getTableQueryParams(tableKey);
return axios.get(`${API_PATH}/table?${tableParams}&index=&source=`)
.then((response: AxiosResponse<TableDataResponse>) => {
.then((response: AxiosResponse<TableDataAPI>) => {
return getTableTagsFromResponseData(response.data);
});
}
/* TODO: Typing this method generates redux-saga related type errors that needs more dedicated debugging */
export function metadataUpdateTableTags(action, tableData) {
const updatePayloads = action.tagArray.map((tagObject) => {
export function metadataUpdateTableTags(tagArray, tableKey: string) {
const updatePayloads = tagArray.map((tagObject) => {
return {
method: tagObject.methodName,
url: `${API_PATH}/update_table_tags`,
data: {
key: tableData.key,
key: tableKey,
tag: tagObject.tagName,
},
}
......@@ -47,12 +49,10 @@ export function metadataUpdateTableTags(action, tableData) {
return updatePayloads.map(payload => { axios(payload) });
}
export function metadataGetTableData(action: GetTableDataRequest) {
const { searchIndex, source } = action;
const tableParams = getTableQueryParams(action);
export function metadataGetTableData(tableKey: string, searchIndex: string, source: string ) {
const tableParams = getTableQueryParams(tableKey);
return axios.get(`${API_PATH}/table?${tableParams}&index=${searchIndex}&source=${source}`)
.then((response: AxiosResponse<TableDataResponse>) => {
.then((response: AxiosResponse<TableDataAPI>) => {
return {
data: getTableDataFromResponseData(response.data),
owners: getTableOwnersFromResponseData(response.data),
......@@ -63,9 +63,9 @@ export function metadataGetTableData(action: GetTableDataRequest) {
}
export function metadataGetTableDescription(tableData: TableMetadata) {
const tableParams = getTableQueryParams(tableData);
const tableParams = getTableQueryParams(tableData.key);
return axios.get(`${API_PATH}/v0/get_table_description?${tableParams}`)
.then((response: AxiosResponse<DescriptionResponse>) => {
.then((response: AxiosResponse<DescriptionAPI>) => {
tableData.table_description = response.data.description;
return tableData;
});
......@@ -84,23 +84,22 @@ export function metadataUpdateTableDescription(description: string, tableData: T
}
}
export function metadataTableOwners(tableData: TableMetadata) {
const tableParams = getTableQueryParams(tableData);
export function metadataTableOwners(tableKey: string) {
const tableParams = getTableQueryParams(tableKey);
return axios.get(`${API_PATH}/table?${tableParams}&index=&source=`)
.then((response: AxiosResponse<TableDataResponse>) => {
.then((response: AxiosResponse<TableDataAPI>) => {
return getTableOwnersFromResponseData(response.data);
});
}
/* TODO: Typing this method generates redux-saga related type errors that need more dedicated debugging */
// TODO - Add 'key' to the action and remove 'tableData' as a param.
export function metadataUpdateTableOwner(action, tableData: TableMetadata) {
const updatePayloads = action.updateArray.map((item) => {
export function metadataUpdateTableOwner(updateArray, tableKey: string) {
const updatePayloads = updateArray.map((item) => {
return {
method: item.method,
url: `${API_PATH}/update_table_owner`,
data: {
key: tableData.key,
key: tableKey,
owner: item.id,
},
}
......@@ -109,10 +108,10 @@ export function metadataUpdateTableOwner(action, tableData: TableMetadata) {
}
export function metadataGetColumnDescription(columnIndex: number, tableData: TableMetadata) {
const tableParams = getTableQueryParams(tableData);
const tableParams = getTableQueryParams(tableData.key);
const columnName = tableData.columns[columnIndex].name;
return axios.get(`${API_PATH}/get_column_description?${tableParams}&column_name=${columnName}`)
.then((response: AxiosResponse<DescriptionResponse>) => {
.then((response: AxiosResponse<DescriptionAPI>) => {
tableData.columns[columnIndex].description = response.data.description;
return tableData;
});
......@@ -135,7 +134,7 @@ export function metadataUpdateColumnDescription(description: string, columnIndex
export function metadataGetLastIndexed() {
return axios.get(`${API_PATH}/get_last_indexed`)
.then((response: AxiosResponse<LastIndexedResponse>) => {
.then((response: AxiosResponse<LastIndexedAPI>) => {
return response.data.timestamp;
});
}
......@@ -146,7 +145,7 @@ export function metadataGetPreviewData(queryParams: PreviewQueryParams) {
method: 'POST',
data: queryParams,
})
.then((response: AxiosResponse<PreviewDataResponse>) => {
.then((response: AxiosResponse<PreviewDataAPI>) => {
return { data: response.data.previewData, status: response.status };
});
}
......@@ -8,9 +8,11 @@ import {
/* ACTIONS */
export function updateTableOwner(updateArray: UpdateOwnerPayload[], onSuccess?: () => any, onFailure?: () => any): UpdateTableOwnerRequest {
return {
onSuccess,
onFailure,
updateArray,
payload: {
onSuccess,
onFailure,
updateArray,
},
type: UpdateTableOwner.REQUEST,
};
};
......
......@@ -6,20 +6,20 @@ import { UpdateTableOwner, UpdateTableOwnerRequest } from '../types';
import { metadataUpdateTableOwner, metadataTableOwners } from '../api/v0';
export function* updateTableOwnerWorker(action: UpdateTableOwnerRequest): SagaIterator {
const { payload } = action;
const state = yield select();
const tableData = state.tableMetadata.tableData;
try {
/* TODO: Pass explicit params into api method and not action */
yield all(metadataUpdateTableOwner(action, tableData));
const newOwners = yield call(metadataTableOwners, tableData);
yield all(metadataUpdateTableOwner(payload.updateArray, tableData.key));
const newOwners = yield call(metadataTableOwners, tableData.key);
yield put({ type: UpdateTableOwner.SUCCESS, payload: { owners: newOwners } });
if (action.onSuccess) {
yield call(action.onSuccess);
if (payload.onSuccess) {
yield call(payload.onSuccess);
}
} catch (e) {
yield put({ type: UpdateTableOwner.FAILURE, payload: { owners: state.tableMetadata.tableOwners.owners } });
if (action.onFailure) {
yield call(action.onFailure);
if (payload.onFailure) {
yield call(payload.onFailure);
}
}
};
......
......@@ -17,43 +17,53 @@ import tableOwnersReducer, { initialOwnersState, TableOwnerReducerState } from '
import tableTagsReducer, { initialTagsState, TableTagsReducerState } from './tags/reducer';
/* ACTIONS */
export function getTableData(key: string, searchIndex?: string, source?: string): GetTableDataRequest {
export function getTableData(key: string, searchIndex: string = '', source: string = ''): GetTableDataRequest {
return {
key,
searchIndex,
source,
payload: {
key,
searchIndex,
source,
},
type: GetTableData.REQUEST,
};
};
export function getTableDescription(onSuccess?: () => any, onFailure?: () => any): GetTableDescriptionRequest {
return {
onSuccess,
onFailure,
payload: {
onSuccess,
onFailure,
},
type: GetTableDescription.REQUEST,
};
};
export function updateTableDescription(newValue: string, onSuccess?: () => any, onFailure?: () => any): UpdateTableDescriptionRequest {
return {
newValue,
onSuccess,
onFailure,
payload: {
newValue,
onSuccess,
onFailure,
},
type: UpdateTableDescription.REQUEST,
};
};
export function getColumnDescription(columnIndex: number, onSuccess?: () => any, onFailure?: () => any): GetColumnDescriptionRequest {
return {
onSuccess,
onFailure,
columnIndex,
payload: {
onSuccess,
onFailure,
columnIndex,
},
type: GetColumnDescription.REQUEST,
};
};
export function updateColumnDescription(newValue: string, columnIndex: number, onSuccess?: () => any, onFailure?: () => any): UpdateColumnDescriptionRequest {
return {
newValue,
columnIndex,
onSuccess,
onFailure,
payload: {
newValue,
columnIndex,
onSuccess,
onFailure,
},
type: UpdateColumnDescription.REQUEST,
};
};
......@@ -61,7 +71,7 @@ export function getLastIndexed(): GetLastIndexedRequest {
return { type: GetLastIndexed.REQUEST };
};
export function getPreviewData(queryParams: PreviewQueryParams): GetPreviewDataRequest {
return { queryParams, type: GetPreviewData.REQUEST };
return { payload: { queryParams }, type: GetPreviewData.REQUEST };
};
/* REDUCER */
......
......@@ -23,8 +23,8 @@ import {
export function* getTableDataWorker(action: GetTableDataRequest): SagaIterator {
try {
/* TODO: Pass explicit params into api method and not action */
const { data, owners, statusCode, tags } = yield call(metadataGetTableData, action);
const { key, searchIndex, source } = action.payload;
const { data, owners, statusCode, tags } = yield call(metadataGetTableData, key, searchIndex, source);
yield put({ type: GetTableData.SUCCESS, payload: { data, owners, statusCode, tags } });
} catch (e) {
yield put({ type: GetTableData.FAILURE, payload: { data: {}, owners: [], statusCode: 500, tags: [] } });
......@@ -35,18 +35,19 @@ export function* getTableDataWatcher(): SagaIterator {
};
export function* getTableDescriptionWorker(action: GetTableDescriptionRequest): SagaIterator {
const { payload } = action;
const state = yield select();
let tableData;
try {
tableData = yield call(metadataGetTableDescription, state.tableMetadata.tableData);
yield put({ type: GetTableDescription.SUCCESS, payload: { tableMetadata: tableData } });
if (action.onSuccess) {
yield call(action.onSuccess);
if (payload.onSuccess) {
yield call(payload.onSuccess);
}
} catch (e) {
yield put({ type: GetTableDescription.FAILURE, payload: { tableMetadata: tableData } });
if (action.onFailure) {
yield call(action.onFailure);
if (payload.onFailure) {
yield call(payload.onFailure);
}
}
};
......@@ -55,15 +56,16 @@ export function* getTableDescriptionWatcher(): SagaIterator {
};
export function* updateTableDescriptionWorker(action: UpdateTableDescriptionRequest): SagaIterator {
const { payload } = action;
const state = yield select();
try {
yield call(metadataUpdateTableDescription, action.newValue, state.tableMetadata.tableData);
if (action.onSuccess) {
yield call(action.onSuccess);
yield call(metadataUpdateTableDescription, payload.newValue, state.tableMetadata.tableData);
if (payload.onSuccess) {
yield call(payload.onSuccess);
}
} catch (e) {
if (action.onFailure) {
yield call(action.onFailure);
if (payload.onFailure) {
yield call(payload.onFailure);
}
}
};
......@@ -72,18 +74,19 @@ export function* updateTableDescriptionWatcher(): SagaIterator {
};
export function* getColumnDescriptionWorker(action: GetColumnDescriptionRequest): SagaIterator {
const { payload } = action;
const state = yield select();
let tableData;
try {
tableData = yield call(metadataGetColumnDescription, action.columnIndex, state.tableMetadata.tableData);
tableData = yield call(metadataGetColumnDescription, payload.columnIndex, state.tableMetadata.tableData);
yield put({ type: GetColumnDescription.SUCCESS, payload: { tableMetadata: tableData } });
if (action.onSuccess) {
yield call(action.onSuccess);
if (payload.onSuccess) {
yield call(payload.onSuccess);
}
} catch (e) {
yield put({ type: GetColumnDescription.FAILURE, payload: { tableMetadata: tableData } });
if (action.onFailure) {
yield call(action.onFailure);
if (payload.onFailure) {
yield call(payload.onFailure);
}
}
};
......@@ -92,15 +95,16 @@ export function* getColumnDescriptionWatcher(): SagaIterator {
};
export function* updateColumnDescriptionWorker(action: UpdateColumnDescriptionRequest): SagaIterator {
const { payload } = action;
const state = yield select();
try {
yield call(metadataUpdateColumnDescription, action.newValue, action.columnIndex, state.tableMetadata.tableData);
if (action.onSuccess) {
yield call(action.onSuccess);
yield call(metadataUpdateColumnDescription, payload.newValue, payload.columnIndex, state.tableMetadata.tableData);
if (payload.onSuccess) {
yield call(payload.onSuccess);
}
} catch (e) {
if (action.onFailure) {
yield call(action.onFailure);
if (payload.onFailure) {
yield call(payload.onFailure);
}
}
};
......@@ -122,7 +126,7 @@ export function* getLastIndexedWatcher(): SagaIterator {
export function* getPreviewDataWorker(action: GetPreviewDataRequest): SagaIterator {
try {
const response = yield call(metadataGetPreviewData, action.queryParams);
const response = yield call(metadataGetPreviewData, action.payload.queryParams);
const { data, status } = response;
yield put({ type: GetPreviewData.SUCCESS, payload: { data, status } });
} catch (e) {
......
......@@ -8,7 +8,9 @@ import {
/* ACTIONS */
export function updateTags(tagArray: UpdateTagData[]): UpdateTagsRequest {
return {
tagArray,
payload: {
tagArray,
},
type: UpdateTags.REQUEST,
};
};
......
......@@ -9,9 +9,8 @@ export function* updateTableTagsWorker(action: UpdateTagsRequest): SagaIterator
const state = yield select();
const tableData = state.tableMetadata.tableData;
try {
/* TODO: Pass explicit params into api method and not action */
yield all(metadataUpdateTableTags(action, tableData));
const newTags = yield call(metadataTableTags, tableData);
yield all(metadataUpdateTableTags(action.payload.tagArray, tableData.key));
const newTags = yield call(metadataTableTags, tableData.key);
yield put({ type: UpdateTags.SUCCESS, payload: { tags: newTags } });
} catch (e) {
yield put({ type: UpdateTags.FAILURE, payload: { tags: [] } });
......
......@@ -15,9 +15,11 @@ export enum GetTableData {
};
export interface GetTableDataRequest {
type: GetTableData.REQUEST;
key: string;
searchIndex?: string;
source?: string;
payload: {
key: string;
searchIndex?: string;
source?: string;
};
};
export interface GetTableDataResponse {
type: GetTableData.SUCCESS | GetTableData.FAILURE;
......@@ -36,8 +38,10 @@ export enum GetTableDescription {
};
export interface GetTableDescriptionRequest {
type: GetTableDescription.REQUEST;
onSuccess?: () => any;
onFailure?: () => any;
payload: {
onSuccess?: () => any;
onFailure?: () => any;
};
};
export interface GetTableDescriptionResponse {
type: GetTableDescription.SUCCESS | GetTableDescription.FAILURE;
......@@ -53,9 +57,11 @@ export enum UpdateTableDescription {
};
export interface UpdateTableDescriptionRequest {
type: UpdateTableDescription.REQUEST;
newValue: string;
onSuccess?: () => any;
onFailure?: () => any;
payload: {
newValue: string;
onSuccess?: () => any;
onFailure?: () => any;
};
};
export interface UpdateTableDescriptionResponse {
type: UpdateTableDescription.SUCCESS | UpdateTableDescription.FAILURE;
......@@ -68,9 +74,11 @@ export enum GetColumnDescription {
};
export interface GetColumnDescriptionRequest {
type: GetColumnDescription.REQUEST;
columnIndex: number;
onSuccess?: () => any;
onFailure?: () => any;
payload: {
columnIndex: number;
onSuccess?: () => any;
onFailure?: () => any;
};
};
export interface GetColumnDescriptionResponse {
type: GetColumnDescription.SUCCESS | GetColumnDescription.FAILURE;
......@@ -86,10 +94,12 @@ export enum UpdateColumnDescription {
};
export interface UpdateColumnDescriptionRequest {
type: UpdateColumnDescription.REQUEST;
newValue: string;
columnIndex: number;
onSuccess?: () => any;
onFailure?: () => any;
payload: {
newValue: string;
columnIndex: number;
onSuccess?: () => any;
onFailure?: () => any;
};
};
export interface UpdateColumnDescriptionResponse {
type: UpdateColumnDescription.SUCCESS | UpdateColumnDescription.FAILURE;
......@@ -117,7 +127,9 @@ export enum GetPreviewData {
};
export interface GetPreviewDataRequest {
type: GetPreviewData.REQUEST;
queryParams: PreviewQueryParams;
payload: {
queryParams: PreviewQueryParams;
};
};
export interface GetPreviewDataResponse {
type: GetPreviewData.SUCCESS | GetPreviewData.FAILURE;
......@@ -134,9 +146,11 @@ export enum UpdateTableOwner {
};
export interface UpdateTableOwnerRequest {
type: UpdateTableOwner.REQUEST;
updateArray: UpdateOwnerPayload[];
onSuccess?: () => any;
onFailure?: () => any;
payload: {
updateArray: UpdateOwnerPayload[];
onSuccess?: () => any;
onFailure?: () => any;
};
};
export interface UpdateTableOwnerResponse {
type: UpdateTableOwner.SUCCESS | UpdateTableOwner.FAILURE;
......@@ -153,7 +167,9 @@ export enum UpdateTags {
};
export interface UpdateTagsRequest {
type: UpdateTags.REQUEST,
tagArray: UpdateTagData[];
payload: {
tagArray: UpdateTagData[];
};
};
export interface UpdateTagsResponse {
type: UpdateTags.SUCCESS | UpdateTags.FAILURE,
......
......@@ -2,35 +2,35 @@ import axios, { AxiosResponse } from 'axios';
import { LoggedInUser, PeopleUser, Resource } from 'interfaces';
export type LoggedInUserResponse = { user: LoggedInUser; msg: string; };
export type UserResponse = { user: PeopleUser; msg: string; };
export type UserOwnResponse = { own: Resource[], msg: string; };
export type UserReadResponse = { read: Resource[], msg: string; };
export type LoggedInUserAPI = { user: LoggedInUser; msg: string; };
export type UserAPI = { user: PeopleUser; msg: string; };
export type UserOwnAPI= { own: Resource[], msg: string; };
export type UserReadAPI = { read: Resource[], msg: string; };
export function getLoggedInUser() {
return axios.get(`/api/auth_user`)
.then((response: AxiosResponse<LoggedInUserResponse>) => {
.then((response: AxiosResponse<LoggedInUserAPI>) => {
return response.data.user;
});
}
export function getUserById(userId: string) {
return axios.get(`/api/metadata/v0/user?user_id=${userId}`)
.then((response: AxiosResponse<UserResponse>) => {
.then((response: AxiosResponse<UserAPI>) => {
return response.data.user;
});
}
export function getUserOwn(userId: string) {
return axios.get(`/api/metadata/v0/user/own?user_id=${userId}`)
.then((response: AxiosResponse<UserOwnResponse>) => {
.then((response: AxiosResponse<UserOwnAPI>) => {
return response.data
});
}
export function getUserRead(userId: string) {
return axios.get(`/api/metadata/v0/user/read?user_id=${userId}`)
.then((response: AxiosResponse<UserReadResponse>) => {
.then((response: AxiosResponse<UserReadAPI>) => {
return response.data
});
}
......@@ -22,7 +22,7 @@ export function getLoggedInUser(): GetLoggedInUserRequest {
return { type: GetLoggedInUser.REQUEST };
};
export function getUserById(userId: string): GetUserRequest {
return { userId, type: GetUser.REQUEST };
return { payload: { userId }, type: GetUser.REQUEST };
};
export function getUserOwn(userId: string): GetUserOwnRequest {
......
......@@ -26,7 +26,7 @@ export function* getLoggedInUserWatcher(): SagaIterator {
export function* getUserWorker(action: GetUserRequest): SagaIterator {
try {
const user = yield call(getUserById, action.userId);
const user = yield call(getUserById, action.payload.userId);
yield put({ type: GetUser.SUCCESS, payload: { user } });
} catch (e) {
yield put({ type: GetUser.FAILURE });
......
......@@ -23,7 +23,9 @@ export enum GetUser {
};
export interface GetUserRequest {
type: GetUser.REQUEST;
userId: string;
payload: {
userId: string;
};
};
export interface GetUserResponse {
type: GetUser.SUCCESS | GetUser.FAILURE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment