Skip to content

Commit bd73f83

Browse files
committed
default blocks editor zoom level; other minor corrections
1 parent d0cb2fb commit bd73f83

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

src/containers/blocks.jsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import ExtensionLibrary from './extension-library.jsx';
1414
import extensionData from '../lib/libraries/extensions/index.jsx';
1515
import CustomProcedures from './custom-procedures.jsx';
1616
import errorBoundaryHOC from '../lib/error-boundary-hoc.jsx';
17-
import {STAGE_DISPLAY_SIZES} from '../lib/layout-constants';
17+
import {BLOCKS_DEFAULT_SCALE, STAGE_DISPLAY_SIZES} from '../lib/layout-constants';
1818
import DropAreaHOC from '../lib/drop-area-hoc.jsx';
1919
import DragConstants from '../lib/drag-constants';
2020
import defineDynamicBlock from '../lib/define-dynamic-block';
@@ -509,7 +509,7 @@ class Blocks extends React.Component {
509509
});
510510
}
511511
render () {
512-
/* eslint-disable no-unused-vars, no-shadow */
512+
/* eslint-disable no-unused-vars */
513513
const {
514514
anyModalVisible,
515515
canUseCloud,
@@ -528,11 +528,11 @@ class Blocks extends React.Component {
528528
onRequestCloseExtensionLibrary,
529529
onRequestCloseCustomProcedures,
530530
toolboxXML,
531+
updateMetrics: updateMetricsProp,
531532
workspaceMetrics,
532-
updateMetrics,
533533
...props
534534
} = this.props;
535-
/* eslint-enable no-unused-vars, no-shadow */
535+
/* eslint-enable no-unused-vars */
536536
return (
537537
<React.Fragment>
538538
<DroppableBlocks
@@ -612,15 +612,19 @@ Blocks.propTypes = {
612612
}),
613613
stageSize: PropTypes.oneOf(Object.keys(STAGE_DISPLAY_SIZES)).isRequired,
614614
toolboxXML: PropTypes.string,
615+
updateMetrics: PropTypes.func,
615616
updateToolboxState: PropTypes.func,
616-
vm: PropTypes.instanceOf(VM).isRequired
617+
vm: PropTypes.instanceOf(VM).isRequired,
618+
workspaceMetrics: PropTypes.shape({
619+
targets: PropTypes.objectOf(PropTypes.object)
620+
})
617621
};
618622

619623
Blocks.defaultOptions = {
620624
zoom: {
621625
controls: true,
622626
wheel: true,
623-
startScale: 0.675
627+
startScale: BLOCKS_DEFAULT_SCALE
624628
},
625629
grid: {
626630
spacing: 40,

src/containers/target-pane.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {showStandardAlert, closeAlertWithId} from '../reducers/alerts';
1414
import {setRestore} from '../reducers/restore-deletion';
1515
import DragConstants from '../lib/drag-constants';
1616
import TargetPaneComponent from '../components/target-pane/target-pane.jsx';
17+
import {BLOCKS_DEFAULT_SCALE} from '../lib/layout-constants';
1718
import spriteLibraryContent from '../lib/libraries/sprites.json';
1819
import {handleFileUpload, spriteUpload} from '../lib/file-uploader.js';
1920
import sharedMessages from '../lib/shared-messages';
@@ -171,7 +172,7 @@ class TargetPane extends React.Component {
171172
metrics = {
172173
scrollX: 0,
173174
scrollY: 0,
174-
scale: 0.675 // TODO: Define this in a constant somewhere.
175+
scale: BLOCKS_DEFAULT_SCALE
175176
};
176177
}
177178

src/lib/layout-constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const STAGE_DISPLAY_SIZES = keyMirror({
3737
small: null
3838
});
3939

40+
// zoom level to start with
41+
const BLOCKS_DEFAULT_SCALE = 0.675;
42+
4043
const STAGE_DISPLAY_SCALES = {};
4144
STAGE_DISPLAY_SCALES[STAGE_DISPLAY_SIZES.large] = 1; // large mode, wide browser (standard)
4245
STAGE_DISPLAY_SCALES[STAGE_DISPLAY_SIZES.largeConstrained] = 0.85; // large mode but narrow browser
@@ -50,6 +53,7 @@ export default {
5053
};
5154

5255
export {
56+
BLOCKS_DEFAULT_SCALE,
5357
STAGE_DISPLAY_SCALES,
5458
STAGE_DISPLAY_SIZES,
5559
STAGE_SIZE_MODES
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* eslint-env jest */
2+
import workspaceMetricsReducer, {updateMetrics} from '../../../src/reducers/workspace-metrics';
3+
4+
test('initialState', () => {
5+
let defaultState;
6+
/* workspaceMetricsReducer(state, action) */
7+
expect(workspaceMetricsReducer(defaultState, {type: 'anything'})).toBeDefined();
8+
expect(workspaceMetricsReducer(defaultState, {type: 'anything'})).toEqual({targets: {}});
9+
});
10+
11+
test('updateMetrics action creator', () => {
12+
let defaultState;
13+
const action = updateMetrics({
14+
targetID: 'abcde',
15+
scrollX: 225,
16+
scrollY: 315,
17+
scale: 1.25
18+
});
19+
const resultState = workspaceMetricsReducer(defaultState, action);
20+
expect(Object.keys(resultState.targets).length).toBe(1);
21+
expect(resultState.targets.abcde).toBeDefined();
22+
expect(resultState.targets.abcde.scrollX).toBe(225);
23+
expect(resultState.targets.abcde.scrollY).toBe(315);
24+
expect(resultState.targets.abcde.scale).toBe(1.25);
25+
});

0 commit comments

Comments
 (0)