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

fix-graph-crash #145

Merged
merged 3 commits into from
Mar 8, 2021
Merged
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,8 @@
"start:server": "node ./server/server.js",
"storybook": "NODE_PATH=src/ start-storybook --port 9001",
"prettify": "prettier --write src/**/*.js",
"lint:fix": "eslint src/**/*.js --fix"
"lint:fix": "eslint src/**/*.js --fix",
"lint": "eslint src/**/*.js"
},
"browserslist": {
"production": [
@@ -102,7 +103,7 @@
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged && lint-staged"
"pre-commit": "npm run lint"
}
},
"lint-staged": {
4 changes: 0 additions & 4 deletions src/actions/experiments.action.js
Original file line number Diff line number Diff line change
@@ -5,10 +5,6 @@ export const experimentChange = value => ({
value,
});

export const triggerExperimentLoading = () => ({
type: actions.EXPERIMENT_TRIGGER_LOADING,
});

export const addExperiment = ({ name, description }) => ({
type: actions.REST_REQ_POST,
payload: {
2 changes: 0 additions & 2 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ import {
addExperiment,
deleteExperiment,
experimentChange,
triggerExperimentLoading as triggerExperiment,
} from 'actions/experiments.action';
import { filterByType } from 'actions/filter.action';
import { getCaching, getKubernetesLogsData } from 'actions/jobs.action';
@@ -68,7 +67,6 @@ const actions = {
startBoard,
stopPipeline,
toggleViewType,
triggerExperiment,
triggerUserGuide,
updateStored,
};
139 changes: 66 additions & 73 deletions src/components/common/Json/JsonTable/JsonTable.react.js
Original file line number Diff line number Diff line change
@@ -23,97 +23,90 @@ const isEmptyObject = obj => Object.entries(obj).length === 0;
const Margin = styled(Descriptions)`
margin-top: ${prop('isMargin', 'none')};
`;

// Recursion Step
const RenderItemByValueType = ({
obj,
vertical,
isMargin = false,
key,
jobId,
}) => {
// Entry
const JsonTable = ({ obj: mainObj, vertical = false, jobId, ...props }) => {
const socketUrl = useSelector(state => state[STATE_SOURCES.SOCKET_URL]);
const downloadLinkRef = useRef();
const handleDownload = useCallback(
() => downloadLinkRef.current && downloadLinkRef.current?.click(),
[downloadLinkRef]
);
// Recursion Step
const RenderItemByValueType = ({ obj, isMargin = false, key }) => {
if (isPureObject(obj)) {
if (key === 'flowInput' && obj.truncated) {
return (
<>
<Button onClick={handleDownload}>Download</Button>
<a
style={{ display: 'none' }}
ref={downloadLinkRef}
href={`${socketUrl}/flowInput/${jobId}?download=true`}
download>
hidden download link
</a>
</>
);
}

if (isPureObject(obj)) {
if (key === 'flowInput' && obj.truncated) {
return (
<Margin
key={key}
column={getTotalColumns({ obj, vertical })}
vertical={vertical}
isMargin={isMargin}>
{objToItem({ obj })}
</Margin>
);
}
if (Array.isArray(obj)) {
return (
<>
<Button onClick={handleDownload}>Download</Button>
<a
style={{ display: 'none' }}
ref={downloadLinkRef}
href={`${socketUrl}/flowInput/${jobId}?download=true`}
download>
hidden download link
</a>
{obj.map((value, i) =>
RenderItemByValueType({
obj: value,
vertical,
isMargin: i !== 0 || i === obj.length - 1,
key: i,
jobId,
})
)}
</>
);
}
return String(obj);
};

return (
<Margin
key={key}
column={getTotalColumns({ obj, vertical })}
vertical={vertical}
isMargin={isMargin}>
{objToItem({ obj })}
</Margin>
);
}
if (Array.isArray(obj)) {
return (
<>
{obj.map((value, i) =>
RenderItemByValueType({
obj: value,
vertical,
isMargin: i !== 0 || i === obj.length - 1,
key: i,
jobId,
})
RenderItemByValueType.propTypes = {
obj: PropTypes.object,
vertical: PropTypes.bool,
isMargin: PropTypes.bool,
key: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
jobId: PropTypes.string,
};

// Item
function objToItem({ obj }) {
return Object.entries(obj).map(([key, value]) => (
<Descriptions.Item key={key} label={<Text strong>{key}</Text>}>
{isPureObject(value) && isEmptyObject(value) ? (
<Tag>{EMPTY}</Tag>
) : (
RenderItemByValueType({ obj: value, key, jobId })
)}
</>
);
</Descriptions.Item>
));
}
return String(obj);
};

RenderItemByValueType.propTypes = {
obj: PropTypes.object,
vertical: PropTypes.bool,
isMargin: PropTypes.bool,
key: PropTypes.oneOf([PropTypes.string, PropTypes.number]),
jobId: PropTypes.string,
return (
<Descriptions
column={getTotalColumns({ obj: mainObj, vertical })}
vertical={vertical}>
{objToItem({ obj: mainObj, vertical, jobId })}
</Descriptions>
);
};

// Item
function objToItem({ obj, vertical, jobId }) {
return Object.entries(obj).map(([key, value]) => (
<Descriptions.Item key={key} label={<Text strong>{key}</Text>}>
{isPureObject(value) && isEmptyObject(value) ? (
<Tag>{EMPTY}</Tag>
) : (
RenderItemByValueType({ obj: value, vertical, key, jobId })
)}
</Descriptions.Item>
));
}

// Entry
const JsonTable = ({ obj, vertical = false, jobId, ...props }) => (
<Descriptions
column={getTotalColumns({ obj, vertical })}
vertical={vertical}
{...props}>
{objToItem({ obj, vertical, jobId })}
</Descriptions>
);

JsonTable.propTypes = {
obj: PropTypes.object,
vertical: PropTypes.bool,
1 change: 0 additions & 1 deletion src/const/application-actions.js
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@ const actionType = {
DRAWER_OPEN: `DRAWER_OPEN`,
DRAWER_TOGGLE: `DRAWER_TOGGLE`,
EXPERIMENT_CHANGE: `EXPERIMENT_CHANGE`,
EXPERIMENT_TRIGGER_LOADING: `EXPERIMENT_TRIGGER_LOADING`,
EXPERIMENT_ADD: `EXPERIMENT_ADD`,
EXPERIMENT_DELETE: `EXPERIMENT_DELETE`,
FILTER_TYPES: `FILTER_TYPES`,
20 changes: 2 additions & 18 deletions src/hooks/useExperiments.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
import { experimentsSchema } from 'config';
import { LOCAL_STORAGE_KEYS, STATE_SOURCES } from 'const';
import isEqual from 'lodash/isEqual';
import { useEffect } from 'react';
import { useSelector } from 'react-redux';
import useActions from './useActions';
import useLocalStorage from './useLocalStorage';

const useExperiments = () => {
const { dataSource, value, loading } = useSelector(
const { dataSource, value } = useSelector(
state => state[STATE_SOURCES.EXPERIMENTS],
isEqual
);
const {
experimentChange,
addExperiment,
deleteExperiment,
triggerExperiment,
} = useActions();

const { experimentName } = useSelector(state => state[STATE_SOURCES.META]);

useEffect(() => {
if (!loading && experimentName !== value) {
triggerExperiment();
} else if (loading && experimentName === value) {
triggerExperiment();
}
}, [experimentName, loading, triggerExperiment, value]);
const { experimentChange, addExperiment, deleteExperiment } = useActions();

useLocalStorage({ value, key: LOCAL_STORAGE_KEYS.EXPERIMENT });

11 changes: 5 additions & 6 deletions src/reducers/experiment.reducer.js
Original file line number Diff line number Diff line change
@@ -18,15 +18,14 @@ export const experiments = handleActions(
currState,
{ payload: { experiments: nextExperiments } }
) {
return Immutable.merge(currState, { dataSource: nextExperiments });
return Immutable.merge(currState, {
dataSource: nextExperiments,
loading: false,
});
},
[actions.EXPERIMENT_CHANGE](currState, { value }) {
const { value: lastValue } = currState;
return Immutable.merge(currState, { value, lastValue });
},
[actions.EXPERIMENT_TRIGGER_LOADING](currState) {
const { loading } = currState;
return Immutable.set(currState, `loading`, !loading);
return Immutable.merge(currState, { value, lastValue, loading: true });
},
},
initial