Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Datasources bugfixes #133

Merged
merged 5 commits into from
Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Routes/Base/SidebarLeft/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ const LogoContainer = styled.div`
display: flex;
`;

const equalByGuideOn = (a, b) => a.isOn === b.isOn;

const sidebarSelector = state => ({
[LEFT_SIDEBAR_NAMES.JOBS]: selectors.jobs.count(state),
[LEFT_SIDEBAR_NAMES.PIPELINES]: selectors.pipelines.collection.count(state),
Expand All @@ -100,7 +98,7 @@ const Name = styled.span`

const SidebarLeft = () => {
const dataCountSource = useSelector(sidebarSelector, isEqual);
const { isOn } = useSelector(state => state.userGuide, equalByGuideOn);
const { isOn } = useSelector(selectors.userGuide);
const location = useLocation();
const dataCount = isOn ? dataCountMock : dataCountSource;
const { isCollapsed, toggle } = useLeftSidebar();
Expand Down
5 changes: 2 additions & 3 deletions src/Routes/Base/UserGuide/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useCallback } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import Joyride, { EVENTS, ACTIONS } from 'react-joyride';
import { useHistory } from 'react-router-dom';
import { selectors } from 'reducers';
import {
triggerUserGuide,
changeStep as _changeStep,
Expand All @@ -13,13 +14,11 @@ import UserGuideTooltip from './UserGuideTooltip.react';

const stepAction = [ACTIONS.NEXT, ACTIONS.PREV, ACTIONS.INIT, ACTIONS.UPDATE];

const isOnEqual = (a, b) => a.isOn === b.isOn;

const UserGuide = () => {
const history = useHistory();
const { setCollapsed } = useLeftSidebar();

const { isOn } = useSelector(state => state.userGuide, isOnEqual);
const { isOn } = useSelector(selectors.userGuide);
const dispatch = useDispatch();

const trigger = useCallback(() => dispatch(triggerUserGuide()), [dispatch]);
Expand Down
14 changes: 9 additions & 5 deletions src/Routes/SidebarRight/AddDataSource/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useCallback, useContext, useState } from 'react';
import PropTypes from 'prop-types';
import { useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { Input, Icon, Form, Button, Alert } from 'antd';
import { BottomContent } from 'components/common';
import { createDataSource } from 'actions/dataSources';
import UploadDragger, { useDragger } from 'components/UploadDragger';
import { DRAWER_SIZE } from 'const';
import { selectors } from 'reducers';
import ctx from './../ctx';

/** @type {import('antd/lib/upload/interface').UploadFile[]} */
Expand All @@ -15,12 +16,11 @@ const AddDataSource = ({ form }) => {
const context = useContext(ctx);
const { getFieldDecorator, validateFields } = form;
const dispatch = useDispatch();

const [addedFiles, setAddedFiles] = useState(initialState);
const { onChange, customRequest } = useDragger({
setFileList: setAddedFiles,
});

const SubmittingStatus = useSelector(selectors.dataSources.createStatus);
const onSubmit = useCallback(
e => {
e.preventDefault();
Expand Down Expand Up @@ -67,8 +67,12 @@ const AddDataSource = ({ form }) => {
</UploadDragger>
</Form.Item>
<BottomContent.Divider />
<BottomContent width={DRAWER_SIZE.ADD_DATASOURCE} extra={[]}>
<Button key="Submit" type="primary" onClick={onSubmit}>
<BottomContent width={DRAWER_SIZE.ADD_DATASOURCE}>
<Button
key="Submit"
type="primary"
onClick={onSubmit}
loading={SubmittingStatus === 'PENDING'}>
Create
</Button>
</BottomContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ export const stratify = flatList => {
*/
let pathsMap = {};

if (flatList.length === 0)
return {
'/': {
children: 0,
childrenIds: [],
id: '/',
isDir: true,
name: '/',
},
};

/** @type {StratifiedMap} */
const stratifiedMap = flatList.reduce((acc, file) => {
/** @type {PathsMap} */
Expand Down Expand Up @@ -106,6 +117,7 @@ export const stratify = flatList => {
},
};
}, {});

return stratifiedMap;
};

Expand Down
1 change: 0 additions & 1 deletion src/Routes/Tables/Pipelines/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const PipelinesTable = () => {
}),
[goTo]
);

return (
<>
<Table
Expand Down
4 changes: 0 additions & 4 deletions src/hooks/useDataSources.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export default () => {
dispatch,
]);

useEffect(() => {
reFetchAll();
}, [reFetchAll]);

const fetchDataSource = useCallback(
name => dispatch(actions.fetchDataSource({ name })),
[dispatch]
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/usePipeline.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useCallback } from 'react';
import { useSelector } from 'react-redux';
import { selectors } from 'reducers/pipeline.reducer';
import { selectors } from 'reducers';
import useActions from './useActions';
import { useFilter } from './useSearch';

const usePipeline = () => {
const collection = useSelector(selectors.collection.all);
const collection = useSelector(selectors.pipelines.collection.all);

const dataStats = useSelector(selectors.stats.all);
const dataStats = useSelector(selectors.pipelines.stats.all);
const filtered = useFilter(collection, 'name');
const { updateStored } = useActions();
const updateCron = useCallback(
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useSearch.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { selectors } from 'reducers';

/**
* @template T
* @type {(collection: T[], key: string) => T[]}
*/
export const useFilter = (collection, key) => {
const filter = useSelector(state => state.autoCompleteFilter.filter);
const filter = useSelector(selectors.autoCompleteFilter);
const data = useMemo(
() => collection.filter(item => item[key].includes(filter)),
[collection, key, filter]
Expand Down
4 changes: 3 additions & 1 deletion src/reducers/dataSources/actionTypes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import actionTypes from './../../const/application-actions';

export default {
const types = {
fetchAll: {
pending: `${actionTypes.DATASOURCE_FETCH_ALL}_PENDING`,
success: `${actionTypes.DATASOURCE_FETCH_ALL}_SUCCESS`,
Expand Down Expand Up @@ -37,3 +37,5 @@ export default {
fail: `${actionTypes.SNAPSHOT_POST}_REJECT`,
},
};

export default types;
3 changes: 3 additions & 0 deletions src/reducers/dataSources/datasource.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import types from './actionTypes';

export type AsyncType = typeof types.fetchAll;
export type FetchStatus = 'SUCCESS' | 'PENDING' | 'FAIL' | 'IDLE';

export type FileMeta = {
Expand Down
22 changes: 17 additions & 5 deletions src/reducers/dataSources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export { snapshotsActions };
* @typedef {import('@reduxjs/toolkit').EntityState<DataSource>} CollectionState
* @typedef {import('./datasource').DataSourceEntry} DataSourceEntry
* @typedef {import('./datasource').FetchStatus} FetchStatus
* @typedef {import('./datasource').AsyncType} AsyncType
* @typedef {import('./versions').VersionsState} VersionsState
* @typedef {import('./snapshots').SnapshotsState} SnapshotsState
* @typedef {{
* dataSources: {
* collection: CollectionState;
* snapshots: SnapshotsState;
* status: FetchStatus;
* createStatus: FetchStatus;
* error: string | null;
* versions: VersionsState;
* };
Expand Down Expand Up @@ -120,20 +122,27 @@ const dataSources = createSlice({
},
});

/** @type {(state: FetchStatus, action: { type: string }) => FetchStatus} */
const status = (state = 'IDLE', { type }) => {
/**
* @type {(
* asyncType: AsyncType
* ) => (state: FetchStatus, action: { type: string }) => FetchStatus}
*/
const statusReducer = asyncType => (state = 'IDLE', { type }) => {
switch (type) {
case types.fetchAll.pending:
case asyncType.pending:
return 'PENDING';
case types.fetchAll.success:
case asyncType.success:
return 'SUCCESS';
case types.fetchAll.fail:
case asyncType.fail:
return 'FAIL';
default:
return state;
}
};

const status = statusReducer(types.fetchAll);
const createStatus = statusReducer(types.create);

const error = (state = null, { type }) => {
if (type !== types.fetchAll.fail) return state;
// return different types of errors by payload
Expand All @@ -145,6 +154,7 @@ export const reducer = combineReducers({
versions: versionsReducer,
snapshots: snapshotsReducer,
status,
createStatus,
error,
});

Expand Down Expand Up @@ -190,4 +200,6 @@ export const selectors = {
/** @param {State} state */
snapshots: (state, dataSourceName) =>
state.dataSources.snapshots[dataSourceName],
/** @param {State} state */
createStatus: state => state.dataSources.createStatus,
};