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

Delete Scale UI #528

Open
wants to merge 4 commits into
base: lyra2019
Choose a base branch
from
Open
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
49 changes: 44 additions & 5 deletions src/js/components/encodings/ScaleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ import sg from '../../ctrl/signals';
import {channelName} from '../../actions/bindChannel';
import {MODE, SELECTED, CELL} from '../../store/factory/Signal';
import {ScaleDraggingState, DraggingStateRecord, ScaleDraggingStateRecord} from '../../store/factory/Inspector';
import {startDragging, stopDragging} from '../../actions/inspectorActions';
import { startDragging, stopDragging} from '../../actions/inspectorActions';
import {setMarkVisual} from '../../actions/markActions';
import {NumericValueRef, StringValueRef, tupleid} from 'vega';
import { deleteScale } from '../../actions/scaleActions';
import { Icon } from '../Icon';
import ReactTooltip from 'react-tooltip';
import { ThunkDispatch } from 'redux-thunk';
import { AnyAction } from 'redux';

const ctrl = require('../../ctrl');

const imutils = require('../../util/immutable-utils');
const getInVis = imutils.getInVis;
const assets = require('../../util/assets');
const capitalize = require('capitalize');

interface StateProps {
selectedId: number;
Expand All @@ -28,6 +35,7 @@ interface DispatchProps {
startDragging: (d: DraggingStateRecord) => void;
stopDragging: () => void;
setMarkVisual: (payload: {property: string, def: NumericValueRef | StringValueRef}, markId: number) => void;
deleteScale: (_: any, id: number, evt: any) => void;
}

function mapStateToProps(reduxState: State, ownProps): StateProps {
Expand All @@ -40,7 +48,28 @@ function mapStateToProps(reduxState: State, ownProps): StateProps {
};
}

const actionCreators: DispatchProps = {startDragging, stopDragging, selectScale, setMarkVisual};
function mapDispatchToProps(dispatch: ThunkDispatch<State, null, AnyAction>): DispatchProps {
return {
startDragging: function (d) {
dispatch(startDragging(d));
},
stopDragging: function () {
dispatch(stopDragging());
},
selectScale: function (guideId) {
dispatch(selectScale(guideId));
},
setMarkVisual: function (payload, markId) {
dispatch(setMarkVisual(payload, markId));
},
deleteScale: function (selectedId, scaleId, evt) {
dispatch(deleteScale(null, scaleId));
evt.preventDefault();
evt.stopPropagation();
ReactTooltip.hide();
},
};
}

class ScaleList extends React.Component<StateProps & DispatchProps> {
private handleDragStart = (evt) => {
Expand Down Expand Up @@ -86,12 +115,17 @@ class ScaleList extends React.Component<StateProps & DispatchProps> {
ctrl.update();
}
}

public componentDidUpdate() {
ReactTooltip.rebuild();
}

public render() {
const props = this.props;
const scales = [...props.scales.values()]

return (
<div id='scale-list'>
<div id='scale-list' className="expandingMenu">
<h2>Scales</h2>
<ul>
{scales.map((scale) => {
Expand All @@ -109,7 +143,12 @@ class ScaleList extends React.Component<StateProps & DispatchProps> {
data-scale={scale.get('_id')}
data-field={field}>
{/* <ContentEditable value={name} save={updateScaleName} /> */}
{name}
<div style={{ "marginLeft": "26px" }}>
Copy link
Member

@jonathanzong jonathanzong Dec 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's try to avoid inline styles if possible. can we put this in the stylesheet?

{capitalize(name)}
</div>
<Icon glyph={assets.trash} className='delete'
onClick={props.deleteScale.bind(null, props.selectedId, id)}
data-tip={'Delete ' + name + ' scale'} data-place='right'/>
</div>
</li>
);
Expand All @@ -120,4 +159,4 @@ class ScaleList extends React.Component<StateProps & DispatchProps> {
}
}

export default connect(mapStateToProps, actionCreators)(ScaleList);
export default connect(mapStateToProps, mapDispatchToProps)(ScaleList);
22 changes: 21 additions & 1 deletion src/js/reducers/marksReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Map} from 'immutable';
import {ActionType, getType} from 'typesafe-actions';
import * as helperActions from '../actions/bindChannel/helperActions';
import * as guideActions from '../actions/guideActions';
import * as scaleActions from '../actions/scaleActions';
import * as markActions from '../actions/markActions';
import * as sceneActions from '../actions/sceneActions';
import * as interactionActions from '../actions/interactionActions';
Expand Down Expand Up @@ -29,7 +30,7 @@ const ensureValuePresentImmutable = function(state: MarkState, path: string[], v
};

const ensureValueAbsent = function(state: MarkState, path: string[], valToRemove): MarkState {
return state.updateIn(path, children => children.filter(c => c !== valToRemove));
return state.updateIn(path, children => children != null ? children.filter(c => c !== valToRemove) : children);
};

// Helper reducer to add a mark to the store. Runs the mark through a method to
Expand Down Expand Up @@ -155,6 +156,7 @@ export function marksReducer(
| ActionType<typeof guideActions.deleteGuide>
| ActionType<typeof interactionActions.deleteInteraction>
| ActionType<typeof widgetActions.deleteWidget>
| ActionType<typeof scaleActions.deleteScale>
): MarkState {
if (typeof state === 'undefined') {
return Map();
Expand Down Expand Up @@ -257,6 +259,24 @@ export function marksReducer(
return ensureValueAbsent(state, [String(action.payload.groupId), 'legends'], id);
}

if (action.type === getType(scaleActions.deleteScale)) {
const groupIds = state.keySeq().toArray();
groupIds.forEach(function (groupId) {
state = ensureValueAbsent(state, [String(groupId), 'scales'], id);

// clean up encoding references
let encodingKeys = Object.keys(state.getIn([String(groupId), 'encode', 'update']));
encodingKeys.forEach(function (encodingKey) {
let needsDelete = state.getIn([String(groupId), 'encode', 'update', encodingKey, 'scale']) === id;
if (needsDelete) {
state = state.setIn([String(groupId), 'encode', 'update', encodingKey], undefined);
}
});

});
return state;
}

if (action.type === getType(interactionActions.deleteInteraction)) {
return ensureValueAbsent(state, [String(action.payload.groupId), '_interactions'], id);
}
Expand Down
6 changes: 3 additions & 3 deletions src/scss/layers.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
}

li {
float: left;
margin: $inner-padding;
margin-top: 0;
list-style-type: none;
}

.scale.name {
display: inline-block;
padding: $inner-padding;
display: flex;
padding: 2*$inner-padding;
text-align: center;
border-radius: 2px;

background-color: skyblue;
color: black;
Expand Down