Skip to content

Commit

Permalink
Inline some methods and logic
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc authored and marcus-oscarsson committed Nov 12, 2024
1 parent 17b360d commit 2542acb
Showing 1 changed file with 59 additions and 64 deletions.
123 changes: 59 additions & 64 deletions ui/src/components/SampleView/ContextMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const BESPOKE_TASK_NAMES = new Set([
export default class ContextMenu extends React.Component {
constructor(props) {
super(props);
this.toggleDrawGrid = this.toggleDrawGrid.bind(this);
this.menuOptions = this.menuOptions.bind(this);
}

Expand All @@ -34,24 +33,6 @@ export default class ContextMenu extends React.Component {
grid: [],
none: [],
};
let twoDPoints = [];

if (this.props.enable2DPoints) {
twoDPoints = [
{ text: 'divider', key: 4 },
{
text: 'Data Collection (Limited OSC)',
action: () => this.createPointAndShowModal('DataCollection'),
key: 5,
},
{
text: 'Characterisation (1 Image)',
action: () =>
this.createPointAndShowModal('Characterisation', { num_imags: 1 }),
key: 6,
},
];
}

generalTaskNames.forEach((tname) => {
const task = this.props.taskForm.defaultParameters[tname];
Expand Down Expand Up @@ -160,8 +141,10 @@ export default class ContextMenu extends React.Component {
key: 'energy_scan',
},
{
text: 'Go To Point',
action: () => this.goToPoint(),
text: 'Go to Point',
action: () => {
this.props.sampleViewActions.moveToPoint(this.props.shape.id);
},
key: 5,
},
{
Expand Down Expand Up @@ -242,9 +225,25 @@ export default class ContextMenu extends React.Component {
],
GridGroup: [{ text: 'Save Grid', action: () => this.saveGrid(), key: 1 }],
GridGroupSaved: [
...(this.props.enableNativeMesh
? [
{
text: 'Mesh Scan',
action: () => this.showModal('Mesh'),
key: 'mesh_scan',
},
]
: []),
{
text: 'Centring Point on cell',
action: () => this.createCollectionOnCell(),
text: 'Centring Point on Cell',
action: () => {
const { cellCenter } = this.props.shape;
this.props.sampleViewActions.add2DPoint(
cellCenter[0],
cellCenter[1],
'SAVED',
);
},
key: 5,
},
{ text: 'divider', key: 2 },
Expand All @@ -253,32 +252,53 @@ export default class ContextMenu extends React.Component {
{ text: 'Delete', action: () => this.removeShape(), key: 4 },
],
NONE: [
{ text: 'Go To Beam', action: () => this.goToBeam(), key: 1 },
{
text: 'Go to Beam',
action: () => {
{
const { sampleViewX, sampleViewY } = this.props;
this.props.sampleViewActions.moveToBeam(sampleViewX, sampleViewY);
}
},
key: 1,
},
{
text: 'Measure Distance',
action: () => this.measureDistance(),
action: () => {
this.props.sampleViewActions.measureDistance(true);
},
key: 2,
},
this.props.getControlAvailability('draw_grid') && {
text: 'Draw Grid',
action: () => this.toggleDrawGrid(),
action: () => {
this.props.sampleViewActions.toggleDrawGrid();
},
key: 3,
},
...twoDPoints,
...(this.props.enable2DPoints
? [
{ text: 'divider', key: 4 },
{
text: 'Data Collection (Limited OSC)',
action: () => this.createPointAndShowModal('DataCollection'),
key: 5,
},
{
text: 'Characterisation (1 Image)',
action: () =>
this.createPointAndShowModal('Characterisation', {
num_imags: 1,
}),
key: 6,
},
]
: []),
{ text: 'divider', key: 7 },
...genericTasks.none,
genericTasks.grid.none > 0 ? { text: 'divider', key: 7 } : {},
],
};

if (this.props.enableNativeMesh) {
options.GridGroupSaved.unshift({
text: 'Mesh Scan',
action: () => this.showModal('Mesh'),
key: 'mesh_scan',
});
}

Object.keys(this.props.availableMethods).forEach((key) => {
if (!this.props.availableMethods[key]) {
Object.keys(options).forEach((k) => {
Expand Down Expand Up @@ -369,21 +389,13 @@ export default class ContextMenu extends React.Component {
);
}

createCollectionOnCell() {
const { cellCenter } = this.props.shape;
this.props.sampleViewActions.add2DPoint(
cellCenter[0],
cellCenter[1],
'SAVED',
);
}

savePoint() {
if (this.props.clickCentring) {
this.props.sampleViewActions.stopClickCentring();
}

this.props.sampleViewActions.acceptCentring();

// associate the newly saved shape to an existing task with -1 shape.
// Fixes issues when the task is added before a shape
const { tasks } = this.props.sampleData;
Expand All @@ -403,15 +415,6 @@ export default class ContextMenu extends React.Component {
}
}

goToPoint() {
this.props.sampleViewActions.moveToPoint(this.props.shape.id);
}

goToBeam() {
const { sampleViewX, sampleViewY } = this.props;
this.props.sampleViewActions.moveToBeam(sampleViewX, sampleViewY);
}

removeShape() {
if (this.props.clickCentring) {
this.props.sampleViewActions.abortCentring();
Expand All @@ -420,17 +423,9 @@ export default class ContextMenu extends React.Component {
this.props.sampleViewActions.deleteShape(this.props.shape.id);
}

measureDistance() {
this.props.sampleViewActions.measureDistance(true);
}

toggleDrawGrid() {
this.props.sampleViewActions.toggleDrawGrid();
}

saveGrid() {
const gd = { ...this.props.shape.gridData };
this.props.sampleViewActions.addShape({ t: 'G', ...gd });
const { gridData } = this.props.shape;
this.props.sampleViewActions.addShape({ t: 'G', ...gridData });
this.props.sampleViewActions.toggleDrawGrid();
}

Expand Down

0 comments on commit 2542acb

Please sign in to comment.