-
Notifications
You must be signed in to change notification settings - Fork 487
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
Timeline Expand and Collapse Features #221
Changes from 16 commits
b4d1f23
1969f44
0d3996a
04bcb26
1d00d88
dd98ace
31ebe58
e75c5de
6152402
1f23496
40db4b2
5bd0006
85b638d
ece37e9
a7cc97e
d0a009b
495328a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright (c) 2017 Uber Technologies, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
.TimelineCollapser { | ||
float: right; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is float right? |
||
margin: 0 0.8rem 0 0; | ||
display: inline-block; | ||
} | ||
|
||
.TimelineCollapserBtn { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be consistent with the other class names, can you rename this to |
||
margin-right: 0.3rem; | ||
} | ||
|
||
.ExpandBtn { | ||
transform: rotate(90deg); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would you want all of the icons rotated 90 degrees? |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Also, if written in the following way both classes don't need to be added to the component: .TimelineCollapser--btn,
.TimelineCollapser--btn-expand {
margin-right: 0.3rem;
}
.TimelineCollapser--btn-expand {
transform: rotate(90deg);
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// @flow | ||
|
||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import React from 'react'; | ||
|
||
import { Tooltip, Icon } from 'antd'; | ||
|
||
import './TimelineCollapser.css'; | ||
|
||
type CollapserProps = { | ||
onCollapseAll: () => void, | ||
onCollapseOne: () => void, | ||
onExpandOne: () => void, | ||
onExpandAll: () => void, | ||
}; | ||
|
||
export default function TimelineCollapser(props: CollapserProps) { | ||
const { onExpandAll, onExpandOne, onCollapseAll, onCollapseOne } = props; | ||
return ( | ||
<span className="TimelineCollapser"> | ||
<Tooltip title="Expand +1"> | ||
<Icon type="right" onClick={onExpandOne} className="TimelineCollapserBtn ExpandBtn" /> | ||
</Tooltip> | ||
<Tooltip title="Collapse +1"> | ||
<Icon type="right" onClick={onCollapseOne} className="TimelineCollapserBtn" /> | ||
</Tooltip> | ||
<Tooltip title="Expand All"> | ||
<Icon type="double-right" onClick={onExpandAll} className="TimelineCollapserBtn ExpandBtn" /> | ||
</Tooltip> | ||
<Tooltip title="Collapse All"> | ||
<Icon type="double-right" onClick={onCollapseAll} className="TimelineCollapserBtn" /> | ||
</Tooltip> | ||
</span> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import TimelineCollapser from './TimelineCollapser'; | ||
|
||
describe('<TimelineCollapser>', () => { | ||
it('renders without exploding', () => { | ||
const props = { | ||
onCollapseAll: () => {}, | ||
onCollapseOne: () => {}, | ||
onExpandAll: () => {}, | ||
onExpandOne: () => {}, | ||
}; | ||
const wrapper = shallow(<TimelineCollapser {...props} />); | ||
expect(wrapper).toBeDefined(); | ||
expect(wrapper.find('.TimelineCollapser').length).toBe(1); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,10 @@ export const actionTypes = generateActionTypes('@jaeger-ui/trace-timeline-viewer | |
'SET_TRACE', | ||
'SET_SPAN_NAME_COLUMN_WIDTH', | ||
'CHILDREN_TOGGLE', | ||
'EXPAND_ALL', | ||
'COLLAPSE_ALL', | ||
'EXPAND_ONE', | ||
'COLLAPSE_ONE', | ||
'DETAIL_TOGGLE', | ||
'DETAIL_TAGS_TOGGLE', | ||
'DETAIL_PROCESS_TOGGLE', | ||
|
@@ -61,6 +65,10 @@ const fullActions = createActions({ | |
[actionTypes.SET_TRACE]: traceID => ({ traceID }), | ||
[actionTypes.SET_SPAN_NAME_COLUMN_WIDTH]: width => ({ width }), | ||
[actionTypes.CHILDREN_TOGGLE]: spanID => ({ spanID }), | ||
[actionTypes.EXPAND_ALL]: () => ({}), | ||
[actionTypes.EXPAND_ONE]: spans => ({ spans }), | ||
[actionTypes.COLLAPSE_ALL]: spans => ({ spans }), | ||
[actionTypes.COLLAPSE_ONE]: spans => ({ spans }), | ||
[actionTypes.DETAIL_TOGGLE]: spanID => ({ spanID }), | ||
[actionTypes.DETAIL_TAGS_TOGGLE]: spanID => ({ spanID }), | ||
[actionTypes.DETAIL_PROCESS_TOGGLE]: spanID => ({ spanID }), | ||
|
@@ -97,6 +105,70 @@ function childrenToggle(state, { payload }) { | |
return { ...state, childrenHiddenIDs }; | ||
} | ||
|
||
function shouldDisableCollapse(allSpans, hiddenSpansIds) { | ||
const allParentSpans = allSpans.filter(s => s.hasChildren); | ||
return allParentSpans.length === hiddenSpansIds.size; | ||
} | ||
|
||
export function expandAll(state) { | ||
const childrenHiddenIDs = new Set(); | ||
return { ...state, childrenHiddenIDs }; | ||
} | ||
|
||
export function collapseAll(state, { payload }) { | ||
const { spans } = payload; | ||
if (shouldDisableCollapse(spans, state.childrenHiddenIDs)) { | ||
return state; | ||
} | ||
const childrenHiddenIDs = spans.reduce((res, s) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, why prefer
Applies generally to these reducers. |
||
if (s.hasChildren) { | ||
res.add(s.spanID); | ||
} | ||
return res; | ||
}, new Set()); | ||
return { ...state, childrenHiddenIDs }; | ||
} | ||
|
||
export function collapseOne(state, { payload }) { | ||
const { spans } = payload; | ||
if (shouldDisableCollapse(spans, state.childrenHiddenIDs)) { | ||
return state; | ||
} | ||
let nearestCollapsedAncestor; | ||
const childrenHiddenIDs = spans.reduce((res, curSpan) => { | ||
if (nearestCollapsedAncestor && curSpan.depth <= nearestCollapsedAncestor.depth) { | ||
res.add(nearestCollapsedAncestor.spanID); | ||
nearestCollapsedAncestor = curSpan; | ||
} else if (curSpan.hasChildren && !res.has(curSpan.spanID)) { | ||
nearestCollapsedAncestor = curSpan; | ||
} | ||
return res; | ||
}, new Set(state.childrenHiddenIDs)); | ||
childrenHiddenIDs.add(nearestCollapsedAncestor.spanID); | ||
return { ...state, childrenHiddenIDs }; | ||
} | ||
|
||
export function expandOne(state, { payload }) { | ||
const { spans } = payload; | ||
if (state.childrenHiddenIDs.size === 0) { | ||
return state; | ||
} | ||
let prevExpandedDepth = -1; | ||
let expandNextHiddenSpan = true; | ||
const childrenHiddenIDs = spans.reduce((res, s) => { | ||
if (s.depth <= prevExpandedDepth) { | ||
expandNextHiddenSpan = true; | ||
} | ||
if (expandNextHiddenSpan && res.has(s.spanID)) { | ||
res.delete(s.spanID); | ||
expandNextHiddenSpan = false; | ||
prevExpandedDepth = s.depth; | ||
} | ||
return res; | ||
}, new Set(state.childrenHiddenIDs)); | ||
return { ...state, childrenHiddenIDs }; | ||
} | ||
|
||
function detailToggle(state, { payload }) { | ||
const { spanID } = payload; | ||
const detailStates = new Map(state.detailStates); | ||
|
@@ -149,6 +221,10 @@ export default handleActions( | |
[actionTypes.SET_TRACE]: setTrace, | ||
[actionTypes.SET_SPAN_NAME_COLUMN_WIDTH]: setColumnWidth, | ||
[actionTypes.CHILDREN_TOGGLE]: childrenToggle, | ||
[actionTypes.EXPAND_ALL]: expandAll, | ||
[actionTypes.EXPAND_ONE]: expandOne, | ||
[actionTypes.COLLAPSE_ALL]: collapseAll, | ||
[actionTypes.COLLAPSE_ONE]: collapseOne, | ||
[actionTypes.DETAIL_TOGGLE]: detailToggle, | ||
[actionTypes.DETAIL_TAGS_TOGGLE]: detailTagsToggle, | ||
[actionTypes.DETAIL_PROCESS_TOGGLE]: detailProcessToggle, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be
Collapse One Level
andExpand One Level
to make it clearer in the help modal?