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