Unverified Commit 89df42c8 authored by Tamika Tannis's avatar Tamika Tannis Committed by GitHub

Reorganize ducks folder (#39)

* Reorganize all but ducks/tableMetadata

* Reorganize ducks/tableMetadata + some cleanup

* Cleanup type
parent 59bab761
......@@ -6,7 +6,7 @@ import SanitizedHTML from 'react-sanitized-html';
// TODO: Use css-modules instead of 'import'
import './styles.scss';
import { AnnouncementsGetRequest } from "../../ducks/announcements/reducer";
import { AnnouncementsGetRequest } from "../../ducks/announcements/types";
import { AnnouncementPost } from "./types";
interface AnnouncementPageState {
......
......@@ -7,7 +7,7 @@ import AppConfig from '../../../config/config';
import LoadingSpinner from '../common/LoadingSpinner';
import TagInfo from "../Tags/TagInfo";
import { Tag } from "../Tags/types";
import { GetAllTagsRequest } from "../../ducks/allTags/reducer";
import { GetAllTagsRequest } from "../../ducks/allTags/types";
export interface StateFromProps {
allTags: Tag[];
......
......@@ -5,7 +5,8 @@ import { bindActionCreators } from 'redux';
// TODO: Use css-modules instead of 'import'
import './styles.scss';
import { GlobalState } from "../../ducks/rootReducer";
import { getLastIndexed, GetLastIndexedRequest } from "../../ducks/tableMetadata/reducer";
import { getLastIndexed } from "../../ducks/tableMetadata/reducer";
import { GetLastIndexedRequest } from "../../ducks/tableMetadata/types";
// Props
interface StateFromProps {
......
......@@ -6,8 +6,8 @@ import { bindActionCreators } from 'redux';
import AppConfig from '../../../config/config';
import { GlobalState } from "../../ducks/rootReducer";
import { getCurrentUser, GetCurrentUserRequest } from "../../ducks/user/reducer";
import { CurrentUser } from "../../ducks/user/types";
import { getCurrentUser } from "../../ducks/user/reducer";
import { CurrentUser, GetCurrentUserRequest } from "../../ducks/user/types";
import './styles.scss';
......
......@@ -8,15 +8,15 @@ import SearchList from './SearchList';
import InfoButton from '../common/InfoButton';
import { TableResource } from "../common/ResourceListItem/types";
import { ExecuteSearchRequest } from '../../ducks/search/reducer';
import { GetPopularTablesRequest } from '../../ducks/popularTables/reducer';
// TODO: Use css-modules instead of 'import'
import './styles.scss';
import {
ExecuteSearchRequest,
DashboardSearchResults,
TableSearchResults,
UserSearchResults
} from "../../ducks/search/types";
import { GetPopularTablesRequest } from '../../ducks/popularTables/types';
// TODO: Use css-modules instead of 'import'
import './styles.scss';
const RESULTS_PER_PAGE = 10;
......
......@@ -3,7 +3,7 @@ import * as DocumentTitle from 'react-document-title';
import * as $ from 'jquery';
import * as qs from 'simple-query-string';
import { GetTableDataRequest } from '../../ducks/tableMetadata/reducer';
import { GetTableDataRequest } from '../../ducks/tableMetadata/types';
import DataPreviewButton from '../../containers/TableDetail/DataPreviewButton';
import TableDescEditableText from '../../containers/TableDetail/TableDescEditableText';
......@@ -58,7 +58,9 @@ class TableDetail extends React.Component<TableDetailProps & RouteComponentProps
isLoading: true,
statusCode: null,
tableData: {
cluster: '',
columns: [],
database: '',
is_editable: false,
schema: '',
table_name: '',
......
......@@ -71,7 +71,9 @@ export interface TableOwners {
}
export interface TableMetadata {
cluster: string;
columns: TableColumn[];
database: string;
is_editable: boolean;
schema: string;
table_name: string;
......
......@@ -6,8 +6,8 @@ import Select, { components } from 'react-select';
import CreatableSelect from 'react-select/lib/Creatable';
import makeAnimated from 'react-select/lib/animated';
import { GetAllTagsRequest } from '../../../ducks/allTags/reducer';
import { UpdateTagsRequest } from '../../../ducks/tableMetadata/tags/reducer';
import { GetAllTagsRequest } from '../../../ducks/allTags/types';
import { UpdateTagsRequest } from '../../../ducks/tableMetadata/types';
import TagInfo from "../TagInfo";
import { Tag, UpdateTagMethod, UpdateTagData } from '../types';
......
......@@ -3,7 +3,7 @@ import LoadingSpinner from '../../LoadingSpinner';
// TODO: Use css-modules instead of 'import'
import './styles.scss';
import { ResetFeedbackAction, SubmitFeedbackRequest } from "../../../../ducks/feedback/reducer";
import { ResetFeedbackRequest, SubmitFeedbackRequest } from "../../../../ducks/feedback/types";
import { SendingState } from '../types';
......@@ -17,7 +17,7 @@ export interface StateFromProps {
export interface DispatchFromProps {
submitFeedback: (data: FormData) => SubmitFeedbackRequest;
resetFeedback: () => ResetFeedbackAction;
resetFeedback: () => ResetFeedbackRequest;
}
type FeedbackFormProps = StateFromProps & DispatchFromProps;
......
import axios from 'axios';
import axios, { AxiosResponse, AxiosError } from 'axios';
import { AllTagsResponse } from '../types';
import { sortTagsAlphabetical } from '../../utilMethods';
export function metadataAllTags() {
return axios.get('/api/metadata/v0/tags').then((response) => {
return axios.get('/api/metadata/v0/tags').then((response: AxiosResponse<AllTagsResponse>) => {
return response.data.tags.sort(sortTagsAlphabetical);
})
.catch((error) => {
return error.response.data.tags.sort(sortTagsAlphabetical);
.catch((error: AxiosError) => {
if (error.response) {
return error.response.data.tags.sort(sortTagsAlphabetical);
}
return [];
});
}
import { Tag } from '../../components/Tags/types';
import {
GetAllTags, GetAllTagsRequest, GetAllTagsResponse,
Tag,
} from './types';
/* getAllTags */
export enum GetAllTags {
ACTION = 'amundsen/allTags/GET_ALL_TAGS',
SUCCESS = 'amundsen/allTags/GET_ALL_TAGS_SUCCESS',
FAILURE = 'amundsen/allTags/GET_ALL_TAGS_FAILURE',
}
export type AllTagsReducerAction = GetAllTagsRequest | GetAllTagsResponse;
export interface GetAllTagsRequest {
type: GetAllTags.ACTION;
}
interface GetAllTagsResponse {
type: GetAllTags.SUCCESS | GetAllTags.FAILURE;
payload: Tag[];
export interface AllTagsReducerState {
allTags: Tag[];
isLoading: boolean;
}
type GetAllTagsAction = GetAllTagsRequest | GetAllTagsResponse;
export function getAllTags(): GetAllTagsRequest {
return { type: GetAllTags.ACTION };
}
/* end getAllTags */
export type TagReducerAction = GetAllTagsAction;
export interface TagReducerState {
allTags: Tag[];
isLoading: boolean;
}
const initialState: TagReducerState = {
const initialState: AllTagsReducerState = {
allTags: [],
isLoading: false,
};
export default function reducer(state: TagReducerState = initialState, action: TagReducerAction): TagReducerState {
export default function reducer(state: AllTagsReducerState = initialState, action: AllTagsReducerAction): AllTagsReducerState {
switch (action.type) {
case GetAllTags.ACTION:
return { ...state, isLoading: true };
......
import { call, put, takeEvery } from 'redux-saga/effects';
import { SagaIterator } from 'redux-saga';
import {
GetAllTags,
} from './reducer';
import { GetAllTags } from './types';
import {
metadataAllTags,
} from './api/v0';
import { metadataAllTags } from './api/v0';
export function* getAllTagsWorker(): SagaIterator {
try {
......
import { Tag } from '../../components/Tags/types';
export { Tag };
/* API */
export type AllTagsResponse = {
msg: string;
tags: Tag[];
}
/* getAllTags */
export enum GetAllTags {
ACTION = 'amundsen/allTags/GET_ALL_TAGS',
SUCCESS = 'amundsen/allTags/GET_ALL_TAGS_SUCCESS',
FAILURE = 'amundsen/allTags/GET_ALL_TAGS_FAILURE',
}
export interface GetAllTagsRequest {
type: GetAllTags.ACTION;
}
export interface GetAllTagsResponse {
type: GetAllTags.SUCCESS | GetAllTags.FAILURE;
payload: Tag[];
}
import axios from 'axios';
import axios, { AxiosResponse, AxiosError } from 'axios';
// TODO - Add better typing for response and error
import { AnnouncementsResponse } from '../types';
export function announcementsGet() {
return axios({
method: 'get',
url: '/api/announcements/v0/',
})
.then((response) => {
return response.data.posts
.then((response: AxiosResponse<AnnouncementsResponse>) => {
return response.data.posts;
})
.catch((error) => {
console.log(error.response.data.msg);
return error
.catch((error: AxiosError) => {
return [];
});
}
import { AnnouncementPost } from '../../components/AnnouncementPage/types';
import {
AnnouncementsGet, AnnouncementsGetRequest, AnnouncementsGetResponse,
AnnouncementPost,
} from './types';
export enum AnnouncementsGet {
ACTION = 'amundsen/announcements/GET_ACTION',
SUCCESS = 'amundsen/announcements/GET_SUCCESS',
FAILURE = 'amundsen/announcements/GET_FAILURE',
}
export type AnnouncementsReducerAction = AnnouncementsGetRequest | AnnouncementsGetResponse;
// announcementsGet
export interface AnnouncementsGetRequest {
type: AnnouncementsGet.ACTION;
export interface AnnouncementsReducerState {
posts: AnnouncementPost[];
}
export function announcementsGet(): AnnouncementsGetRequest {
return { type: AnnouncementsGet.ACTION };
}
interface AnnouncementsGetResponse {
type: AnnouncementsGet.SUCCESS | AnnouncementsGet.FAILURE;
payload: AnnouncementPost[];
}
type AnnouncementsGetAction = AnnouncementsGetRequest | AnnouncementsGetResponse;
export type AnnouncementsReducerAction = AnnouncementsGetAction;
export interface AnnouncementsReducerState {
posts: AnnouncementPost[];
}
const initialState: AnnouncementsReducerState = {
posts: []
posts: [],
};
export default function reducer(state: AnnouncementsReducerState = initialState, action: AnnouncementsReducerAction): AnnouncementsReducerState {
switch (action.type) {
case AnnouncementsGet.ACTION:
return state;
case AnnouncementsGet.FAILURE:
case AnnouncementsGet.SUCCESS:
return { posts: action.payload };
case AnnouncementsGet.FAILURE:
return { posts: [] };
default:
return state;
}
......
import { SagaIterator } from 'redux-saga';
import { call, put, takeEvery } from 'redux-saga/effects';
import { announcementsGet } from '../api/announcements/v0';
import { AnnouncementsGet, AnnouncementsGetRequest } from "./reducer";
import { announcementsGet } from './api/v0';
export function* announcementsGetWorker(action: AnnouncementsGetRequest): SagaIterator {
import { AnnouncementsGet } from './types';
export function* announcementsGetWorker(): SagaIterator {
try {
const announcements = yield call(announcementsGet);
yield put({ type: AnnouncementsGet.SUCCESS, payload: announcements });
} catch(error) {
yield put({ type: AnnouncementsGet.FAILURE });
yield put({ type: AnnouncementsGet.FAILURE, payload: [] });
}
}
......
import { AnnouncementPost } from '../../components/AnnouncementPage/types';
export { AnnouncementPost }
/* API */
export type AnnouncementsResponse = {
msg: string;
posts: AnnouncementPost[];
}
/* getAnnouncements */
export enum AnnouncementsGet {
ACTION = 'amundsen/announcements/GET_ACTION',
SUCCESS = 'amundsen/announcements/GET_SUCCESS',
FAILURE = 'amundsen/announcements/GET_FAILURE',
}
export interface AnnouncementsGetRequest {
type: AnnouncementsGet.ACTION;
}
export interface AnnouncementsGetResponse {
type: AnnouncementsGet.SUCCESS | AnnouncementsGet.FAILURE;
payload: AnnouncementPost[];
}
import axios from 'axios';
import { SubmitFeedbackRequest } from '../../feedback/reducer';
export function feedbackSubmitFeedback(action: SubmitFeedbackRequest) {
const { data } = action;
return axios({
data,
method: 'post',
url: '/api/mail/v0/feedback',
timeout: 5000,
headers: {'Content-Type': 'multipart/form-data' }
})
.then((response) => {
return response
})
.catch((error) => {
return error
});
}
import axios, { AxiosResponse, AxiosError } from 'axios';
import { SubmitFeedbackRequest } from '../types';
export function feedbackSubmitFeedback(action: SubmitFeedbackRequest) {
return axios({
data: action.data,
method: 'post',
url: '/api/mail/v0/feedback',
timeout: 5000,
headers: {'Content-Type': 'multipart/form-data' }
})
.then((response: AxiosResponse<any>) => {
return response;
})
.catch((error: AxiosError) => {
return error;
});
}
import { SendingState } from '../../components/common/Feedback/types';
/* SubmitFeedback */
export enum SubmitFeedback {
ACTION = 'amundsen/feedback/SUBMIT_FEEDBACK',
SUCCESS = 'amundsen/feedback/SUBMIT_FEEDBACK_SUCCESS',
FAILURE = 'amundsen/feedback/SUBMIT_FEEDBACK_FAILURE',
}
import {
ResetFeedback, ResetFeedbackRequest,
SubmitFeedback, SubmitFeedbackRequest, SubmitFeedbackResponse,
} from './types';
export interface SubmitFeedbackRequest {
type: SubmitFeedback.ACTION;
data: FormData;
}
export type SubmitFeedbackAction = SubmitFeedbackRequest | SubmitFeedbackResponse;
export type ResetFeedbackAction = ResetFeedbackRequest;
interface SubmitFeedbackResponse {
type: SubmitFeedback.SUCCESS | SubmitFeedback.FAILURE;
payload?: FeedbackReducerState;
export type FeedbackReducerAction = SubmitFeedbackAction | ResetFeedbackAction;
export interface FeedbackReducerState {
sendState: SendingState;
}
export function submitFeedback(formData): SubmitFeedbackRequest {
export function submitFeedback(formData: FormData): SubmitFeedbackRequest {
return {
data: formData,
type: SubmitFeedback.ACTION,
};
}
type SubmitFeedbackAction = SubmitFeedbackRequest | SubmitFeedbackResponse;
/* end SubmitFeedback */
/* ResetFeedback */
export enum ResetFeedback {
ACTION = 'amundsen/feedback/RESET_FEEDBACK',
}
export interface ResetFeedbackAction {
type: ResetFeedback.ACTION;
}
export function resetFeedback(): ResetFeedbackAction {
return {
type: ResetFeedback.ACTION,
};
}
/* end ResetFeedback */
export type FeedbackReducerAction = SubmitFeedbackAction | ResetFeedbackAction;
export interface FeedbackReducerState {
sendState: SendingState;
}
const initialState: FeedbackReducerState = {
sendState: SendingState.IDLE
sendState: SendingState.IDLE,
};
export default function reducer(state: FeedbackReducerState = initialState, action: FeedbackReducerAction): FeedbackReducerState {
......
......@@ -2,9 +2,8 @@
import { delay, SagaIterator } from 'redux-saga';
import { call, put, takeEvery } from 'redux-saga/effects';
import { ResetFeedback, SubmitFeedback, SubmitFeedbackRequest } from './reducer';
import { feedbackSubmitFeedback } from '../api/feedback/v0';
import { ResetFeedback, SubmitFeedback, SubmitFeedbackRequest } from './types';
import { feedbackSubmitFeedback } from './api/v0';
function* submitFeedbackWorker(action: SubmitFeedbackRequest): SagaIterator {
try {
......
/* SubmitFeedback */
export enum SubmitFeedback {
ACTION = 'amundsen/feedback/SUBMIT_FEEDBACK',
SUCCESS = 'amundsen/feedback/SUBMIT_FEEDBACK_SUCCESS',
FAILURE = 'amundsen/feedback/SUBMIT_FEEDBACK_FAILURE',
}
export interface SubmitFeedbackRequest {
type: SubmitFeedback.ACTION;
data: FormData;
}
export interface SubmitFeedbackResponse {
type: SubmitFeedback.SUCCESS | SubmitFeedback.FAILURE;
}
/* ResetFeedback */
export enum ResetFeedback {
ACTION = 'amundsen/feedback/RESET_FEEDBACK',
}
export interface ResetFeedbackRequest {
type: ResetFeedback.ACTION;
}
import axios from 'axios';
import axios, { AxiosResponse, AxiosError } from 'axios';
import { PopularTablesResponse } from '../types';
export function metadataPopularTables() {
return axios.get('/api/metadata/v0/popular_tables').then((response) => {
return axios.get('/api/metadata/v0/popular_tables')
.then((response: AxiosResponse<PopularTablesResponse>) => {
return response.data.results;
})
.catch((error) => {
return error.response.data.results;
.catch((error: AxiosError) => {
if (error.response) {
return error.response.data.results;
}
return [];
});
}
import { TableResource } from "../../components/common/ResourceListItem/types";
import {
GetPopularTables,
GetPopularTablesRequest,
GetPopularTablesResponse,
TableResource,
} from './types';
/* getPopularTables */
export enum GetPopularTables {
ACTION = 'amundsen/popularTables/GET_POPULAR_TABLES',
SUCCESS = 'amundsen/popularTables/GET_POPULAR_TABLES_SUCCESS',
FAILURE = 'amundsen/popularTables/GET_POPULAR_TABLES_FAILURE',
}
export interface GetPopularTablesRequest {
type: GetPopularTables.ACTION;
}
export type PopularTablesReducerAction = GetPopularTablesRequest | GetPopularTablesResponse;
interface GetPopularTablesResponse {
type: GetPopularTables.SUCCESS | GetPopularTables.FAILURE;
payload: TableResource[];
}
export type PopularTablesReducerState = TableResource[];
export function getPopularTables(): GetPopularTablesRequest {
return { type: GetPopularTables.ACTION };
}
/* end getPopularTables */
export type PopularTablesReducerAction = GetPopularTablesRequest | GetPopularTablesResponse;
export type PopularTablesReducerState = TableResource[];
const initialState: PopularTablesReducerState = [];
......
import { call, put, takeEvery } from 'redux-saga/effects';
import { SagaIterator } from 'redux-saga';
import {
GetPopularTables,
GetPopularTablesRequest,
} from './reducer';
import {
metadataPopularTables,
} from './api/v0';
import { GetPopularTables, GetPopularTablesRequest } from './types';
import { metadataPopularTables} from './api/v0';
export function* getPopularTablesWorker(): SagaIterator {
try {
......
import { TableResource } from '../../components/common/ResourceListItem/types';
export { TableResource };
/* API */
export type PopularTablesResponse = {
msg: string;
results: TableResource[];
}
/* getPopularTables */
export enum GetPopularTables {
ACTION = 'amundsen/popularTables/GET_POPULAR_TABLES',
SUCCESS = 'amundsen/popularTables/GET_POPULAR_TABLES_SUCCESS',
FAILURE = 'amundsen/popularTables/GET_POPULAR_TABLES_FAILURE',
}
export interface GetPopularTablesRequest {
type: GetPopularTables.ACTION;
}
export interface GetPopularTablesResponse {
type: GetPopularTables.SUCCESS | GetPopularTables.FAILURE;
payload: TableResource[];
}
......@@ -5,7 +5,7 @@ import feedback, { FeedbackReducerState } from './feedback/reducer';
import popularTables, { PopularTablesReducerState } from './popularTables/reducer';
import search, { SearchReducerState } from './search/reducer';
import tableMetadata, { TableMetadataReducerState } from './tableMetadata/reducer';
import allTags, { TagReducerState } from './allTags/reducer';
import allTags, { AllTagsReducerState } from './allTags/reducer';
import user, { UserReducerState } from './user/reducer';
export interface GlobalState {
......@@ -14,7 +14,7 @@ export interface GlobalState {
popularTables: PopularTablesReducerState;
search: SearchReducerState;
tableMetadata: TableMetadataReducerState;
allTags: TagReducerState;
allTags: AllTagsReducerState;
user: UserReducerState;
}
......
import axios, { AxiosResponse, AxiosError } from 'axios';
import {
DashboardSearchResults,
TableSearchResults,
UserSearchResults,
} from '../types';
import { SearchReducerState } from "../reducer";
import { SearchResponse } from '../types';
interface SearchResponse {
msg: string;
status_code: number;
search_term: string;
dashboards: DashboardSearchResults;
tables: TableSearchResults;
users: UserSearchResults;
}
import { SearchReducerState } from '../reducer';
function transformSearchResults(data: SearchResponse): SearchReducerState {
return {
......@@ -28,6 +16,9 @@ function transformSearchResults(data: SearchResponse): SearchReducerState {
export function searchExecuteSearch(action) {
const { term, pageIndex } = action;
return axios.get(`/api/search/v0/?query=${term}&page_index=${pageIndex}`)
.then((response: AxiosResponse<SearchResponse>)=> transformSearchResults(response.data))
.catch((error: AxiosError) => transformSearchResults(error.response.data));
.then((response: AxiosResponse<SearchResponse>) => transformSearchResults(response.data))
.catch((error: AxiosError) => {
const data = error.response ? error.response.data : {};
return transformSearchResults(data);
});
}
import {
ExecuteSearch,
ExecuteSearchRequest,
ExecuteSearchResponse,
DashboardSearchResults,
TableSearchResults,
UserSearchResults,
} from './types';
/* executeSearch */
export enum ExecuteSearch {
ACTION = 'amundsen/search/EXECUTE_SEARCH',
SUCCESS = 'amundsen/search/EXECUTE_SEARCH_SUCCESS',
FAILURE = 'amundsen/search/EXECUTE_SEARCH_FAILURE',
}
export interface ExecuteSearchRequest {
type: ExecuteSearch.ACTION;
term: string;
pageIndex: number;
}
export type SearchReducerAction = ExecuteSearchRequest | ExecuteSearchResponse;
interface ExecuteSearchResponse {
type: ExecuteSearch.SUCCESS | ExecuteSearch.FAILURE;
payload?: SearchReducerState;
export interface SearchReducerState {
searchTerm: string;
dashboards: DashboardSearchResults;
tables: TableSearchResults;
users: UserSearchResults;
}
export function executeSearch(term: string, pageIndex: number): ExecuteSearchRequest {
......@@ -29,16 +23,6 @@ export function executeSearch(term: string, pageIndex: number): ExecuteSearchReq
type: ExecuteSearch.ACTION,
};
}
/* end executeSearch */
export type SearchReducerAction = ExecuteSearchRequest | ExecuteSearchResponse;
export interface SearchReducerState {
searchTerm: string;
dashboards: DashboardSearchResults;
tables: TableSearchResults;
users: UserSearchResults;
}
const initialState: SearchReducerState = {
searchTerm: '',
......
......@@ -4,7 +4,7 @@ import { SagaIterator } from 'redux-saga';
import {
ExecuteSearch,
ExecuteSearchRequest,
} from './reducer';
} from './types';
import {
searchExecuteSearch,
......
import { Resource, DashboardResource, TableResource, UserResource } from "../../components/common/ResourceListItem/types";
import { SearchReducerState } from './reducer';
interface SearchResults<T extends Resource> {
page_index: number;
......@@ -9,3 +10,29 @@ interface SearchResults<T extends Resource> {
export type DashboardSearchResults = SearchResults<DashboardResource>;
export type TableSearchResults = SearchResults<TableResource>;
export type UserSearchResults = SearchResults<UserResource>;
export type SearchResponse = {
msg: string;
status_code: number;
search_term: string;
dashboards: DashboardSearchResults;
tables: TableSearchResults;
users: UserSearchResults;
}
/* executeSearch */
export enum ExecuteSearch {
ACTION = 'amundsen/search/EXECUTE_SEARCH',
SUCCESS = 'amundsen/search/EXECUTE_SEARCH_SUCCESS',
FAILURE = 'amundsen/search/EXECUTE_SEARCH_FAILURE',
}
export interface ExecuteSearchRequest {
type: ExecuteSearch.ACTION;
term: string;
pageIndex: number;
}
export interface ExecuteSearchResponse {
type: ExecuteSearch.SUCCESS | ExecuteSearch.FAILURE;
payload?: SearchReducerState;
}
/** TODO: We will introduce better typing for function parameters return types */
import { GetTableDataRequest, TableMetadata, TableDataResponse, Tag, User } from '../../tableMetadata/types';
import { filterFromObj, sortTagsAlphabetical } from '../../utilMethods';
/**
* Generates the query string parameters needed for requests that act on a particular table resource.
*/
export function getTableParams(tableDataObject) {
export function getTableParams(tableDataObject: TableMetadata | GetTableDataRequest): string {
const { cluster, database, schema, table_name } = tableDataObject;
return `db=${database}&cluster=${cluster}&schema=${schema}&table=${table_name}`;
}
......@@ -13,17 +13,17 @@ export function getTableParams(tableDataObject) {
/**
* Parses the response for table metadata to create a TableMetadata object
*/
export function getTableDataFromResponseData(responseData) {
return filterFromObj(responseData, ['owners', 'tags']);
export function getTableDataFromResponseData(responseData: TableDataResponse): 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) {
export function getTableOwnersFromResponseData(responseData: TableDataResponse): { [id: string] : User } {
// TODO: owner needs proper id, until then we have to remember that we are using display_name
const ownerObj = responseData.owners.reduce((resultObj, currentOwner) => {
resultObj[currentOwner.display_name] = currentOwner;
const ownerObj = responseData.tableData.owners.reduce((resultObj, currentOwner) => {
resultObj[currentOwner.display_name] = currentOwner as User;
return resultObj;
}, {});
return ownerObj;
......@@ -32,6 +32,6 @@ export function getTableOwnersFromResponseData(responseData) {
/**
* Parses the response for table metadata to return an array of sorted table tags
*/
export function getTableTagsFromResponseData(responseData) {
return responseData.tags.sort(sortTagsAlphabetical);
export function getTableTagsFromResponseData(responseData: TableDataResponse): Tag[] {
return responseData.tableData.tags.sort(sortTagsAlphabetical);
}
/** TODO: We will introduce better typing for requests and responses */
import axios from 'axios';
import axios, { AxiosResponse, AxiosError } from 'axios';
import { Effect } from 'redux-saga';
import { GetPreviewDataRequest } from '../../tableMetadata/reducer';
import {
DescriptionResponse, LastIndexedResponse, PreviewDataResponse, TableDataResponse,
GetPreviewDataRequest, GetTableDataRequest, UpdateTableOwnerRequest, UpdateTagsRequest,
PreviewData, TableMetadata, User, Tag
} from '../../tableMetadata/types';
const API_PATH = '/api/metadata/v0';
/** HELPERS **/
import {
getTableParams,
getTableDataFromResponseData,
getTableOwnersFromResponseData,
getTableTagsFromResponseData
getTableParams, getTableDataFromResponseData, getTableOwnersFromResponseData, getTableTagsFromResponseData,
} from './helpers';
export function metadataTableTags(tableData) {
export function metadataTableTags(tableData: TableMetadata) {
const tableParams = getTableParams(tableData);
return axios.get(`${API_PATH}/table?${tableParams}&index=&source=`).then((response) => {
return getTableTagsFromResponseData(response.data.tableData);
return axios.get(`${API_PATH}/table?${tableParams}&index=&source=`)
.then((response: AxiosResponse<TableDataResponse>) => {
return getTableTagsFromResponseData(response.data);
})
.catch((error) => {
.catch((error: AxiosError) => {
return [];
});
}
/* 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 => ({
const updatePayloads = action.tagArray.map((tagObject) => {
return {
method: tagObject.methodName,
url: `${API_PATH}/update_table_tags`,
data: {
......@@ -36,40 +40,42 @@ export function metadataUpdateTableTags(action, tableData) {
tag: tagObject.tagName,
},
}
));
return updatePayloads.map(payload => { axios(payload) })
});
return updatePayloads.map(payload => { axios(payload) });
}
export function metadataGetTableData(action) {
export function metadataGetTableData(action: GetTableDataRequest) {
const { searchIndex, source } = action;
const tableParams = getTableParams(action);
return axios.get(`${API_PATH}/table?${tableParams}&index=${searchIndex}&source=${source}`).then((response) => {
const responseData = response.data.tableData;
return axios.get(`${API_PATH}/table?${tableParams}&index=${searchIndex}&source=${source}`)
.then((response: AxiosResponse<TableDataResponse>) => {
return {
data: getTableDataFromResponseData(responseData),
owners: getTableOwnersFromResponseData(responseData),
tags: getTableTagsFromResponseData(responseData),
data: getTableDataFromResponseData(response.data),
owners: getTableOwnersFromResponseData(response.data),
tags: getTableTagsFromResponseData(response.data),
statusCode: response.status,
};
})
.catch((error) => {
return { data: {}, owners: {}, tags: [], statusCode: error.response.status };
.catch((error: AxiosError) => {
const statusCode = error.response ? error.response.status : 500;
return { statusCode, data: {}, owners: {}, tags: [] };
});
}
export function metadataGetTableDescription(tableData) {
export function metadataGetTableDescription(tableData: TableMetadata) {
const tableParams = getTableParams(tableData);
return axios.get(`${API_PATH}/v0/get_table_description?${tableParams}`).then((response) => {
return axios.get(`${API_PATH}/v0/get_table_description?${tableParams}`)
.then((response: AxiosResponse<DescriptionResponse>) => {
tableData.table_description = response.data.description;
return tableData;
})
.catch((error) => {
.catch((error: AxiosError) => {
return tableData;
});
}
export function metadataUpdateTableDescription(description, tableData) {
export function metadataUpdateTableDescription(description: string, tableData: TableMetadata) {
if (description.length === 0) {
throw new Error();
}
......@@ -85,19 +91,22 @@ export function metadataUpdateTableDescription(description, tableData) {
}
}
export function metadataTableOwners(tableData) {
export function metadataTableOwners(tableData: TableMetadata) {
const tableParams = getTableParams(tableData);
return axios.get(`${API_PATH}/table?${tableParams}&index=&source=`).then((response) => {
return getTableOwnersFromResponseData(response.data.tableData);
return axios.get(`${API_PATH}/table?${tableParams}&index=&source=`)
.then((response: AxiosResponse<TableDataResponse>) => {
return getTableOwnersFromResponseData(response.data);
})
.catch((error) => {
return {};
});
}
/* TODO: Typing this method generates redux-saga related type errors that need more dedicated debugging */
export function metadataUpdateTableOwner(action, tableData) {
const updatePayloads = action.updateArray.map(item => ({
const updatePayloads = action.updateArray.map((item) => {
return {
method: item.method,
url: `${API_PATH}/update_table_owner`,
data: {
......@@ -108,23 +117,24 @@ export function metadataUpdateTableOwner(action, tableData) {
table: tableData.table_name,
},
}
));
});
return updatePayloads.map(payload => { axios(payload) });
}
export function metadataGetColumnDescription(columnIndex, tableData) {
export function metadataGetColumnDescription(columnIndex: number, tableData: TableMetadata) {
const tableParams = getTableParams(tableData);
const columnName = tableData.columns[columnIndex].name;
return axios.get(`${API_PATH}/get_column_description?${tableParams}&column_name=${columnName}`).then((response) => {
return axios.get(`${API_PATH}/get_column_description?${tableParams}&column_name=${columnName}`)
.then((response: AxiosResponse<DescriptionResponse>) => {
tableData.columns[columnIndex].description = response.data.description;
return tableData;
})
.catch((error) => {
.catch((error: AxiosError) => {
return tableData;
});
}
export function metadataUpdateColumnDescription(description, columnIndex, tableData) {
export function metadataUpdateColumnDescription(description: string, columnIndex: number, tableData: TableMetadata) {
if (description.length === 0) {
throw new Error();
}
......@@ -143,7 +153,8 @@ export function metadataUpdateColumnDescription(description, columnIndex, tableD
}
export function metadataGetLastIndexed() {
return axios.get(`${API_PATH}/get_last_indexed`).then((response) => {
return axios.get(`${API_PATH}/get_last_indexed`)
.then((response: AxiosResponse<LastIndexedResponse>) => {
return response.data.timestamp;
});
}
......@@ -154,10 +165,12 @@ export function metadataGetPreviewData(action: GetPreviewDataRequest) {
method: 'POST',
data: action.queryParams,
})
.then((response) => {
.then((response: AxiosResponse<PreviewDataResponse>) => {
return { data: response.data.previewData, status: response.status };
})
.catch((error) => {
return { data: {}, status: error.response.status };
.catch((error: AxiosError) => {
const data = error.response ? error.response.data : {};
const status = error.response ? error.response.status : null;
return { data, status };
});
}
import { GetTableData, GetTableDataRequest, GetTableDataResponse } from '../reducer';
import { UpdateMethod } from '.../../../components/OwnerEditor/types';
import { User } from '.../../../components/TableDetail/types';
import {
GetTableData, GetTableDataRequest, GetTableDataResponse,
UpdateTableOwner, UpdateTableOwnerRequest, UpdateTableOwnerResponse,
UpdatePayload, User
} from '../types';
/* updateTableOwner */
export enum UpdateTableOwner {
ACTION = 'amundsen/tableMetadata/UPDATE_TABLE_OWNER',
SUCCESS = 'amundsen/tableMetadata/UPDATE_TABLE_OWNER_SUCCESS',
FAILURE = 'amundsen/tableMetadata/UPDATE_TABLE_OWNER_FAILURE',
}
interface UpdatePayload {
method: UpdateMethod;
id: string;
}
export interface UpdateTableOwnerRequest {
type: UpdateTableOwner.ACTION;
updateArray: UpdatePayload[];
onSuccess?: () => any;
onFailure?: () => any;
}
export type TableOwnerReducerAction =
GetTableDataRequest | GetTableDataResponse |
UpdateTableOwnerRequest | UpdateTableOwnerResponse ;
export interface UpdateTableOwnerResponse {
type: UpdateTableOwner.SUCCESS | UpdateTableOwner.FAILURE;
payload: { [id: string] : User };
export interface TableOwnerReducerState {
isLoading: boolean;
owners: { [id: string] : User };
}
export function updateTableOwner(updateArray: UpdatePayload[], onSuccess?: () => any, onFailure?: () => any): UpdateTableOwnerRequest {
......@@ -34,16 +21,6 @@ export function updateTableOwner(updateArray: UpdatePayload[], onSuccess?: () =>
type: UpdateTableOwner.ACTION,
};
}
/* end updateTableOwner */
export type TableOwnerReducerAction =
GetTableDataRequest | GetTableDataResponse |
UpdateTableOwnerRequest | UpdateTableOwnerResponse;
export interface TableOwnerReducerState {
isLoading: boolean;
owners: { [id: string] : User };
}
export const initialOwnersState: TableOwnerReducerState = {
isLoading: true,
......
import { all, call, put, select, takeEvery } from 'redux-saga/effects';
import { SagaIterator } from 'redux-saga';
import { UpdateTableOwner, UpdateTableOwnerRequest } from './reducer';
import { UpdateTableOwner, UpdateTableOwnerRequest } from '../types';
import { metadataUpdateTableOwner, metadataTableOwners } from '../api/v0';
......
/* TODO: Reorganize types to allow for some consistency with imports */
import { PreviewData, PreviewQueryParams, TableMetadata, User } from '../../components/TableDetail/types';
import { Tag } from '../../components/Tags/types';
import {
GetTableData, GetTableDataRequest, GetTableDataResponse, TableMetadata,
GetTableDescription, GetTableDescriptionRequest, GetTableDescriptionResponse,
UpdateTableDescription, UpdateTableDescriptionRequest, UpdateTableDescriptionResponse,
GetColumnDescription, GetColumnDescriptionResponse, GetColumnDescriptionRequest,
UpdateColumnDescription, UpdateColumnDescriptionRequest, UpdateColumnDescriptionResponse,
GetLastIndexed, GetLastIndexedRequest, GetLastIndexedResponse,
GetPreviewData, GetPreviewDataRequest, GetPreviewDataResponse, PreviewQueryParams, PreviewDataState,
UpdateTableOwner,
UpdateTags,
} from './types';
import tableOwnersReducer, {
initialOwnersState,
TableOwnerReducerState,
UpdateTableOwner,
UpdateTableOwnerRequest,
UpdateTableOwnerResponse,
initialOwnersState, TableOwnerReducerAction, TableOwnerReducerState,
} from './owners/reducer';
import tableTagsReducer, {
initialTagsState,
TableTagsReducerState,
UpdateTags,
UpdateTagsRequest,
UpdateTagsResponse,
initialTagsState, TableTagsReducerAction, TableTagsReducerState,
} from './tags/reducer';
/* getTableData */
export enum GetTableData {
ACTION = 'amundsen/tableMetadata/GET_TABLE_DATA',
SUCCESS = 'amundsen/tableMetadata/GET_TABLE_DATA_SUCCESS',
FAILURE = 'amundsen/tableMetadata/GET_TABLE_DATA_FAILURE',
}
export interface GetTableDataRequest {
type: GetTableData.ACTION;
cluster: string;
database: string;
schema: string;
searchIndex?: string;
source?: string;
table_name: string;
}
export type TableMetadataReducerAction =
GetTableDataRequest | GetTableDataResponse |
GetTableDescriptionRequest | GetTableDescriptionResponse |
UpdateTableDescriptionRequest | UpdateTableDescriptionResponse |
GetColumnDescriptionRequest | GetColumnDescriptionResponse |
UpdateColumnDescriptionRequest | UpdateColumnDescriptionResponse |
GetLastIndexedRequest | GetLastIndexedResponse |
GetPreviewDataRequest | GetPreviewDataResponse |
TableOwnerReducerAction | TableTagsReducerAction ;
export interface GetTableDataResponse {
type: GetTableData.SUCCESS | GetTableData.FAILURE;
payload: {
statusCode: number;
data: TableMetadata;
owners: { [id: string] : User };
tags: Tag[];
}
export interface TableMetadataReducerState {
isLoading: boolean;
lastIndexed: number;
preview: PreviewDataState;
statusCode: number;
tableData: TableMetadata;
tableOwners: TableOwnerReducerState;
tableTags: TableTagsReducerState;
}
export function getTableData(cluster: string, database: string, schema: string, tableName: string, searchIndex?: string, source?: string): GetTableDataRequest {
......@@ -55,25 +49,6 @@ export function getTableData(cluster: string, database: string, schema: string,
type: GetTableData.ACTION,
};
}
/* end getTableData */
/* getTableDescription */
export enum GetTableDescription {
ACTION = 'amundsen/tableMetadata/GET_TABLE_DESCRIPTION',
SUCCESS = 'amundsen/tableMetadata/GET_TABLE_DESCRIPTION_SUCCESS',
FAILURE = 'amundsen/tableMetadata/GET_TABLE_DESCRIPTION_FAILURE',
}
export interface GetTableDescriptionRequest {
type: GetTableDescription.ACTION;
onSuccess?: () => any;
onFailure?: () => any;
}
interface GetTableDescriptionResponse {
type: GetTableDescription.SUCCESS | GetTableDescription.FAILURE;
payload: TableMetadata;
}
export function getTableDescription(onSuccess?: () => any, onFailure?: () => any): GetTableDescriptionRequest {
return {
......@@ -82,25 +57,6 @@ export function getTableDescription(onSuccess?: () => any, onFailure?: () => any
type: GetTableDescription.ACTION,
};
}
/* end getTableDescription */
/* updateTableDescription */
export enum UpdateTableDescription {
ACTION = 'amundsen/tableMetadata/UPDATE_TABLE_DESCRIPTION',
SUCCESS = 'amundsen/tableMetadata/UPDATE_TABLE_DESCRIPTION_SUCCESS',
FAILURE = 'amundsen/tableMetadata/UPDATE_TABLE_DESCRIPTION_FAILURE',
}
export interface UpdateTableDescriptionRequest {
type: UpdateTableDescription.ACTION;
newValue: string;
onSuccess?: () => any;
onFailure?: () => any;
}
interface UpdateTableDescriptionResponse {
type: UpdateTableDescription.SUCCESS | UpdateTableDescription.FAILURE;
}
export function updateTableDescription(newValue: string, onSuccess?: () => any, onFailure?: () => any): UpdateTableDescriptionRequest {
return {
......@@ -110,26 +66,6 @@ export function updateTableDescription(newValue: string, onSuccess?: () => any,
type: UpdateTableDescription.ACTION,
};
}
/* end updateTableDescription */
/* getColumnDescription */
export enum GetColumnDescription {
ACTION = 'amundsen/tableMetadata/GET_COLUMN_DESCRIPTION',
SUCCESS = 'amundsen/tableMetadata/GET_COLUMN_DESCRIPTION_SUCCESS',
FAILURE = 'amundsen/tableMetadata/GET_COLUMN_DESCRIPTION_FAILURE',
}
export interface GetColumnDescriptionRequest {
type: GetColumnDescription.ACTION;
columnIndex: number;
onSuccess?: () => any;
onFailure?: () => any;
}
interface GetColumnDescriptionResponse {
type: GetColumnDescription.SUCCESS | GetColumnDescription.FAILURE;
payload: TableMetadata;
}
export function getColumnDescription(columnIndex: number, onSuccess?: () => any, onFailure?: () => any): GetColumnDescriptionRequest {
return {
......@@ -139,25 +75,6 @@ export function getColumnDescription(columnIndex: number, onSuccess?: () => any,
type: GetColumnDescription.ACTION,
};
}
/* end getColumnDescription */
/* updateColumnDescription */
export enum UpdateColumnDescription {
ACTION = 'amundsen/tableMetadata/UPDATE_COLUMN_DESCRIPTION',
SUCCESS = 'amundsen/tableMetadata/UPDATE_COLUMN_DESCRIPTION_SUCCESS',
FAILURE = 'amundsen/tableMetadata/UPDATE_COLUMN_DESCRIPTION_FAILURE',
}
export interface UpdateColumnDescriptionRequest {
type: UpdateColumnDescription.ACTION;
newValue: string;
columnIndex: number;
onSuccess?: () => any;
onFailure?: () => any;
}
interface UpdateColumnDescriptionResponse {
type: UpdateColumnDescription.SUCCESS | UpdateColumnDescription.FAILURE;
}
export function updateColumnDescription(newValue: string, columnIndex: number, onSuccess?: () => any, onFailure?: () => any): UpdateColumnDescriptionRequest {
return {
......@@ -168,80 +85,23 @@ export function updateColumnDescription(newValue: string, columnIndex: number, o
type: UpdateColumnDescription.ACTION,
};
}
/* end updateColumnDescription */
/* getLastIndexed */
export enum GetLastIndexed {
ACTION = 'amundsen/tableMetadata/GET_LAST_UPDATED',
SUCCESS = 'amundsen/tableMetadata/GET_LAST_UPDATED_SUCCESS',
FAILURE = 'amundsen/tableMetadata/GET_LAST_UPDATED_FAILURE',
}
export interface GetLastIndexedRequest {
type: GetLastIndexed.ACTION;
}
interface GetLastIndexedResponse {
type: GetLastIndexed.SUCCESS | GetLastIndexed.FAILURE;
payload?: number;
}
export function getLastIndexed(): GetLastIndexedRequest {
return { type: GetLastIndexed.ACTION };
}
/* end getLastIndexed */
/* getPreviewData */
export enum GetPreviewData {
ACTION = 'amundsen/preview/GET_PREVIEW_DATA',
SUCCESS = 'amundsen/preview/GET_PREVIEW_DATA_SUCCESS',
FAILURE = 'amundsen/preview/GET_PREVIEW_DATA_FAILURE',
}
interface PreviewDataState {
data: PreviewData;
status: number | null;
}
export interface GetPreviewDataRequest {
type: GetPreviewData.ACTION;
queryParams: PreviewQueryParams;
}
interface GetPreviewDataResponse {
type: GetPreviewData.SUCCESS | GetPreviewData.FAILURE;
payload: PreviewDataState;
}
export function getPreviewData(queryParams: PreviewQueryParams): GetPreviewDataRequest {
return { queryParams, type: GetPreviewData.ACTION };
}
/* end getPreviewData */
export type TableMetadataReducerAction =
GetTableDataRequest | GetTableDataResponse |
GetTableDescriptionRequest | GetTableDescriptionResponse |
UpdateTableDescriptionRequest | UpdateTableDescriptionResponse |
GetColumnDescriptionRequest | GetColumnDescriptionResponse |
UpdateColumnDescriptionRequest | UpdateColumnDescriptionResponse |
GetLastIndexedRequest | GetLastIndexedResponse |
GetPreviewDataRequest | GetPreviewDataResponse |
UpdateTagsRequest | UpdateTagsResponse |
UpdateTableOwnerRequest | UpdateTableOwnerResponse ;
export interface TableMetadataReducerState {
isLoading: boolean;
lastIndexed: number;
preview: PreviewDataState;
statusCode: number;
tableData: TableMetadata;
tableOwners: TableOwnerReducerState;
tableTags: TableTagsReducerState;
}
const initialPreviewState = {
data: {},
status: null,
};
const initialTableDataState: TableMetadata = {
cluster: '',
columns: [],
database: '',
is_editable: false,
schema: '',
table_name: '',
......
......@@ -2,14 +2,14 @@ import { all, call, put, select, takeEvery } from 'redux-saga/effects';
import { SagaIterator } from 'redux-saga';
import {
GetLastIndexedRequest, GetLastIndexed,
GetLastIndexed, GetLastIndexedRequest,
GetPreviewData, GetPreviewDataRequest,
GetTableData, GetTableDataRequest,
GetColumnDescription, GetColumnDescriptionRequest,
GetTableDescription, GetTableDescriptionRequest,
UpdateColumnDescription, UpdateColumnDescriptionRequest,
UpdateTableDescription, UpdateTableDescriptionRequest,
} from './reducer';
} from './types';
import {
metadataGetLastIndexed,
......@@ -23,7 +23,6 @@ import {
// getTableData
export function* getTableDataWorker(action: GetTableDataRequest): SagaIterator {
let tableData;
try {
const { data, owners, tags } = yield call(metadataGetTableData, action);
yield put({ type: GetTableData.SUCCESS, payload: { data, owners, tags } });
......
import { GetTableData, GetTableDataRequest, GetTableDataResponse } from '../reducer';
import { UpdateTagData, Tag } from '../../../components/Tags/types';
import {
GetTableData, GetTableDataRequest, GetTableDataResponse,
UpdateTags, UpdateTagsRequest, UpdateTagsResponse,
UpdateTagData, Tag,
} from '../types';
/* updateTags */
export enum UpdateTags {
ACTION = 'amundsen/tags/UPDATE_TAGS',
SUCCESS = 'amundsen/tags/UPDATE_TAGS_SUCCESS',
FAILURE = 'amundsen/tags/UPDATE_TAGS_FAILURE',
}
export interface UpdateTagsRequest {
type: UpdateTags.ACTION,
tagArray: UpdateTagData[];
}
export type TableTagsReducerAction =
GetTableDataRequest | GetTableDataResponse |
UpdateTagsRequest | UpdateTagsResponse;
export interface UpdateTagsResponse {
type: UpdateTags.SUCCESS | UpdateTags.FAILURE,
payload: Tag[];
export interface TableTagsReducerState {
isLoading: boolean;
tags: Tag[];
}
export function updateTags(tagArray: UpdateTagData[]): UpdateTagsRequest {
......@@ -24,16 +19,6 @@ export function updateTags(tagArray: UpdateTagData[]): UpdateTagsRequest {
type: UpdateTags.ACTION,
};
}
/* end updateTags */
export type TableTagsReducerAction =
GetTableDataRequest | GetTableDataResponse |
UpdateTagsRequest | UpdateTagsResponse;
export interface TableTagsReducerState {
isLoading: boolean;
tags: Tag[];
}
export const initialTagsState: TableTagsReducerState = {
isLoading: true,
......
import { all, call, put, select, takeEvery } from 'redux-saga/effects';
import { SagaIterator } from 'redux-saga';
import { UpdateTags, UpdateTagsRequest } from './reducer';
import { UpdateTags, UpdateTagsRequest } from '../types';
import { metadataUpdateTableTags, metadataTableTags } from '../api/v0';
......
import { PreviewData, PreviewQueryParams, TableMetadata, User } from '../../components/TableDetail/types';
import { UpdateTagData, Tag } from '../../components/Tags/types';
import { UpdateMethod } from '../../components/OwnerEditor/types';
export { PreviewData, PreviewQueryParams, TableMetadata, Tag, User, UpdateMethod, UpdateTagData };
type MessageResponse = { 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;
/* getTableData */
export enum GetTableData {
ACTION = 'amundsen/tableMetadata/GET_TABLE_DATA',
SUCCESS = 'amundsen/tableMetadata/GET_TABLE_DATA_SUCCESS',
FAILURE = 'amundsen/tableMetadata/GET_TABLE_DATA_FAILURE',
}
export interface GetTableDataRequest {
type: GetTableData.ACTION;
cluster: string;
database: string;
schema: string;
searchIndex?: string;
source?: string;
table_name: string;
}
export interface GetTableDataResponse {
type: GetTableData.SUCCESS | GetTableData.FAILURE;
payload: {
statusCode: number;
data: TableMetadata;
owners: { [id: string] : User };
tags: Tag[];
}
}
/* getTableDescription */
export enum GetTableDescription {
ACTION = 'amundsen/tableMetadata/GET_TABLE_DESCRIPTION',
SUCCESS = 'amundsen/tableMetadata/GET_TABLE_DESCRIPTION_SUCCESS',
FAILURE = 'amundsen/tableMetadata/GET_TABLE_DESCRIPTION_FAILURE',
}
export interface GetTableDescriptionRequest {
type: GetTableDescription.ACTION;
onSuccess?: () => any;
onFailure?: () => any;
}
export interface GetTableDescriptionResponse {
type: GetTableDescription.SUCCESS | GetTableDescription.FAILURE;
payload: TableMetadata;
}
/* updateTableDescription */
export enum UpdateTableDescription {
ACTION = 'amundsen/tableMetadata/UPDATE_TABLE_DESCRIPTION',
SUCCESS = 'amundsen/tableMetadata/UPDATE_TABLE_DESCRIPTION_SUCCESS',
FAILURE = 'amundsen/tableMetadata/UPDATE_TABLE_DESCRIPTION_FAILURE',
}
export interface UpdateTableDescriptionRequest {
type: UpdateTableDescription.ACTION;
newValue: string;
onSuccess?: () => any;
onFailure?: () => any;
}
export interface UpdateTableDescriptionResponse {
type: UpdateTableDescription.SUCCESS | UpdateTableDescription.FAILURE;
}
/* getColumnDescription */
export enum GetColumnDescription {
ACTION = 'amundsen/tableMetadata/GET_COLUMN_DESCRIPTION',
SUCCESS = 'amundsen/tableMetadata/GET_COLUMN_DESCRIPTION_SUCCESS',
FAILURE = 'amundsen/tableMetadata/GET_COLUMN_DESCRIPTION_FAILURE',
}
export interface GetColumnDescriptionRequest {
type: GetColumnDescription.ACTION;
columnIndex: number;
onSuccess?: () => any;
onFailure?: () => any;
}
export interface GetColumnDescriptionResponse {
type: GetColumnDescription.SUCCESS | GetColumnDescription.FAILURE;
payload: TableMetadata;
}
/* updateColumnDescription */
export enum UpdateColumnDescription {
ACTION = 'amundsen/tableMetadata/UPDATE_COLUMN_DESCRIPTION',
SUCCESS = 'amundsen/tableMetadata/UPDATE_COLUMN_DESCRIPTION_SUCCESS',
FAILURE = 'amundsen/tableMetadata/UPDATE_COLUMN_DESCRIPTION_FAILURE',
}
export interface UpdateColumnDescriptionRequest {
type: UpdateColumnDescription.ACTION;
newValue: string;
columnIndex: number;
onSuccess?: () => any;
onFailure?: () => any;
}
export interface UpdateColumnDescriptionResponse {
type: UpdateColumnDescription.SUCCESS | UpdateColumnDescription.FAILURE;
}
/* getLastIndexed */
export enum GetLastIndexed {
ACTION = 'amundsen/tableMetadata/GET_LAST_UPDATED',
SUCCESS = 'amundsen/tableMetadata/GET_LAST_UPDATED_SUCCESS',
FAILURE = 'amundsen/tableMetadata/GET_LAST_UPDATED_FAILURE',
}
export interface GetLastIndexedRequest {
type: GetLastIndexed.ACTION;
}
export interface GetLastIndexedResponse {
type: GetLastIndexed.SUCCESS | GetLastIndexed.FAILURE;
payload?: number;
}
/* getPreviewData */
export interface PreviewDataState {
data: PreviewData;
status: number | null;
}
export enum GetPreviewData {
ACTION = 'amundsen/preview/GET_PREVIEW_DATA',
SUCCESS = 'amundsen/preview/GET_PREVIEW_DATA_SUCCESS',
FAILURE = 'amundsen/preview/GET_PREVIEW_DATA_FAILURE',
}
export interface GetPreviewDataRequest {
type: GetPreviewData.ACTION;
queryParams: PreviewQueryParams;
}
export interface GetPreviewDataResponse {
type: GetPreviewData.SUCCESS | GetPreviewData.FAILURE;
payload: PreviewDataState;
}
/* updateTableOwner */
export interface UpdatePayload {
method: UpdateMethod;
id: string;
}
export enum UpdateTableOwner {
ACTION = 'amundsen/tableMetadata/UPDATE_TABLE_OWNER',
SUCCESS = 'amundsen/tableMetadata/UPDATE_TABLE_OWNER_SUCCESS',
FAILURE = 'amundsen/tableMetadata/UPDATE_TABLE_OWNER_FAILURE',
}
export interface UpdateTableOwnerRequest {
type: UpdateTableOwner.ACTION;
updateArray: UpdatePayload[];
onSuccess?: () => any;
onFailure?: () => any;
}
export interface UpdateTableOwnerResponse {
type: UpdateTableOwner.SUCCESS | UpdateTableOwner.FAILURE;
payload: { [id: string] : User };
}
/* updateTags */
export enum UpdateTags {
ACTION = 'amundsen/tags/UPDATE_TAGS',
SUCCESS = 'amundsen/tags/UPDATE_TAGS_SUCCESS',
FAILURE = 'amundsen/tags/UPDATE_TAGS_FAILURE',
}
export interface UpdateTagsRequest {
type: UpdateTags.ACTION,
tagArray: UpdateTagData[];
}
export interface UpdateTagsResponse {
type: UpdateTags.SUCCESS | UpdateTags.FAILURE,
payload: Tag[];
}
......@@ -7,6 +7,6 @@ export function getCurrentUser() {
.then((response: AxiosResponse<CurrentUser>) => {
return response.data;
}).catch((error: AxiosError) => {
console.log(error.response);
return {};
});
}
import { CurrentUser } from './types';
import {
GetCurrentUser,
GetCurrentUserRequest,
GetCurrentUserResponse,
CurrentUser
} from './types';
export enum GetCurrentUser {
ACTION = 'amundsen/user/GET_ACTION',
SUCCESS = 'amundsen/user/GET_SUCCESS',
FAILURE = 'amundsen/user/GET_FAILURE',
}
type UserReducerAction = GetCurrentUserRequest | GetCurrentUserResponse;
export interface GetCurrentUserRequest {
type: GetCurrentUser.ACTION;
export interface UserReducerState {
currentUser: CurrentUser;
}
export function getCurrentUser(): GetCurrentUserRequest {
return { type: GetCurrentUser.ACTION };
}
interface GetCurrentUserResponse {
type: GetCurrentUser.SUCCESS | GetCurrentUser.FAILURE;
payload?: CurrentUser;
}
type GetUserAction = GetCurrentUserRequest | GetCurrentUserResponse;
type UserReducerAction = GetUserAction
export interface UserReducerState {
currentUser: CurrentUser;
}
const initialState: UserReducerState = {
currentUser: null,
};
export default function reducer(state: UserReducerState = initialState, action: UserReducerAction): UserReducerState {
switch (action.type) {
case GetCurrentUser.FAILURE:
return state;
case GetCurrentUser.SUCCESS:
return { ...state, currentUser: action.payload };
default:
......
import { SagaIterator } from 'redux-saga';
import { call, put, takeEvery } from 'redux-saga/effects';
import { GetCurrentUser } from './reducer';
import { GetCurrentUser } from './types';
import { getCurrentUser } from './api/v0';
export function* getUserWorker(): SagaIterator {
......
......@@ -5,3 +5,18 @@ export interface CurrentUser {
last_name: string;
profile_url: string;
}
export enum GetCurrentUser {
ACTION = 'amundsen/user/GET_ACTION',
SUCCESS = 'amundsen/user/GET_SUCCESS',
FAILURE = 'amundsen/user/GET_FAILURE',
}
export interface GetCurrentUserRequest {
type: GetCurrentUser.ACTION;
}
export interface GetCurrentUserResponse {
type: GetCurrentUser.SUCCESS | GetCurrentUser.FAILURE;
payload?: CurrentUser;
}
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