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