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

Xstate ugrade #826

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"use-immer": "^0.9.0",
"webpack": "5.94.0",
"xlsx": "^0.18.5",
"xstate": "^5.3.1",
"xstate": "^5.13.2",
"yup": "^1.2.0"
},
"scripts": {
Expand Down
29 changes: 20 additions & 9 deletions public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* - Please do NOT serve this file on production.
*/

const PACKAGE_VERSION = '2.2.10'
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
const PACKAGE_VERSION = '2.6.6'
const INTEGRITY_CHECKSUM = 'ca7800994cc8bfb5eb961e037c877074'
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
const activeClientIds = new Set()

Expand Down Expand Up @@ -62,7 +62,12 @@ self.addEventListener('message', async function (event) {

sendToClient(client, {
type: 'MOCKING_ENABLED',
payload: true,
payload: {
client: {
id: client.id,
frameType: client.frameType,
},
},
})
break
}
Expand Down Expand Up @@ -155,6 +160,10 @@ async function handleRequest(event, requestId) {
async function resolveMainClient(event) {
const client = await self.clients.get(event.clientId)

if (activeClientIds.has(event.clientId)) {
return client
}

if (client?.frameType === 'top-level') {
return client
}
Expand Down Expand Up @@ -183,12 +192,14 @@ async function getResponse(event, client, requestId) {
const requestClone = request.clone()

function passthrough() {
const headers = Object.fromEntries(requestClone.headers.entries())

// Remove internal MSW request header so the passthrough request
// complies with any potential CORS preflight checks on the server.
// Some servers forbid unknown request headers.
delete headers['x-msw-intention']
// Cast the request headers to a new Headers instance
// so the headers can be manipulated with.
const headers = new Headers(requestClone.headers)

// Remove the "accept" header value that marked this request as passthrough.
// This prevents request alteration and also keeps it compliant with the
// user-defined CORS policies.
headers.delete('accept', 'msw/passthrough')

return fetch(requestClone, { headers })
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/LayoutPlanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { buildSlotColor, buildSlotSecondaryText, buildSlotText } from '../pages/
import { ActorRef, MachineSnapshot } from 'xstate';

interface LayoutPlannerProps {
actor: ActorRef<MachineSnapshot<LayoutContext, LayoutEvents, any, any, any, any>, any>;
actor: ActorRef<MachineSnapshot<LayoutContext, LayoutEvents, any, any, any, any, any, any>, any>;
children: React.ReactNode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { OutputSlotCopyData } from '../slotMapper/slotMapper.types';
type DualIndexPlateParams = {
destinationLabware?: LabwareFlaggedFieldsFragment;
send: (event: ReagentTransferEvent) => void;
current: MachineSnapshot<ReagentTransferContext, any, any, any, any, any>;
current: MachineSnapshot<ReagentTransferContext, any, any, any, any, any, any, any>;
outputSlotCopies?: Array<OutputSlotCopyData>;
destinationCleanedOutAddresses?: string[];
};
Expand Down
12 changes: 6 additions & 6 deletions src/components/libraryGeneration/SlotCopyComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type SlotCopyParams = {
initialOutputLabware: NewFlaggedLabwareLayout[];
initialOutputSlotCopy: Array<Destination>;
send: (event: SlotCopyEvent) => void;
current: MachineSnapshot<SlotCopyContext, SlotCopyEvent, any, any, any, any>;
current: MachineSnapshot<SlotCopyContext, SlotCopyEvent, any, any, any, any, any, any>;
slotCopyModes: Array<SlotCopyMode>;
addPlateOption?: boolean;
labwareDestinationSelectionMode?: DestinationSelectionMode;
Expand Down Expand Up @@ -329,7 +329,7 @@ function SlotCopyComponent({
? (plateFactory.build() as NewFlaggedLabwareLayout)
: (stripTubeFactory.build() as NewFlaggedLabwareLayout);

const labwareArray = destinations.map((dest) => dest.labware);
const labwareArray = destinations.map((dest: Destination) => dest.labware);
labwareArray.push(labware);
toast(addDestinationPlateNotification(labware.labwareType.name), {
position: toast.POSITION.TOP_RIGHT,
Expand Down Expand Up @@ -378,7 +378,7 @@ function SlotCopyComponent({
);

const cleanedOutInputAddresses: Map<number, string[]> = new Map();
sources.forEach((source) => {
sources.forEach((source: Source) => {
cleanedOutInputAddresses.set(source.labware.id, source.cleanedOutAddresses ?? []);
});

Expand Down Expand Up @@ -410,15 +410,15 @@ function SlotCopyComponent({
cleanedOutAddresses: output.cleanedOutAddresses
};
})}
initialInputLabware={sources.map((source) => source.labware)}
initialInputLabware={sources.map((source: Source) => source.labware)}
onInputLabwareChange={handleInputLabwareChange}
onChange={handleOnSlotMapperChange}
onOutputLabwareChange={handleOutputLabwareChange}
inputLabwareConfigPanel={
sources.length > 0 && (
<SlotCopySourceConfigPanel
onChangeState={onSourceLabwareStateChange}
selectedSource={sources.find((src) => src.labware.barcode === selectedSource?.barcode)}
selectedSource={sources.find((src: Source) => src.labware.barcode === selectedSource?.barcode)}
/>
)
}
Expand All @@ -428,7 +428,7 @@ function SlotCopyComponent({
onChangeBioState={onChangeBioState}
onLabwareScan={onDestinationLabwareScan}
onDestinationSelectionModeChange={onDestinationSelectionModeChange}
labware={destinations.find((dest) => dest.labware.id === selectedDestination.id)}
labware={destinations.find((dest: Destination) => dest.labware.id === selectedDestination.id)}
destinationSelectionMode={updateDestinationModeWhenPaginating()}
/>
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/sectioningConfirm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { ConfirmLabwareContext, ConfirmLabwareEvent } from './confirmLabware.mac
import { MachineSnapshot } from 'xstate';

export const selectConfirmOperationLabware = (
state: MachineSnapshot<ConfirmLabwareContext, ConfirmLabwareEvent, any, any, any, any, any>
state: MachineSnapshot<ConfirmLabwareContext, ConfirmLabwareEvent, any, any, any, any, any, any>
) => state.context.confirmSectionLabware;
29 changes: 21 additions & 8 deletions src/components/slotMapper/slotMapper.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,23 @@ import { buildAddresses, cycleColors } from '../../lib/helpers';
import { sortWithDirection } from '../../lib/helpers/addressHelper';
import { find, indexOf, intersection, map } from 'lodash';
import { stanCore } from '../../lib/sdk';
import { assign, createMachine, fromPromise, MachineImplementations } from 'xstate';
import { produce } from '../../dependencies/immer';
import { assign, createMachine, fromPromise, InternalMachineImplementations } from 'xstate';
import { produce } from 'immer';

const colors = cycleColors();

const machineImplementations: MachineImplementations<SlotMapperContext, SlotMapperEvent> = {
type SlotMapperMachineImplementation = {
context: SlotMapperContext;
events: SlotMapperEvent;
actors: any;
actions: any;
guards: any;
delays: any;
tags: any;
emitted: any;
};

const machineImplementations: InternalMachineImplementations<SlotMapperMachineImplementation> = {
actions: {
assignInputLabware: assign(({ context, event }) => {
if (event.type === 'UPDATE_INPUT_LABWARE') {
Expand All @@ -26,20 +37,22 @@ const machineImplementations: MachineImplementations<SlotMapperContext, SlotMapp

// Update the failedSlots array if it has entries for any removed labware
let keys = Array.from(draft.failedSlots.keys()).filter(
(key) => draft.inputLabware.findIndex((labware) => labware.barcode === key) === -1
(key) =>
draft.inputLabware.findIndex((labware: LabwareFlaggedFieldsFragment) => labware.barcode === key) === -1
);
keys.forEach((key) => draft.failedSlots.delete(key));

// Update the errors array if it has entries for any removed labware
keys = Array.from(draft.errors.keys()).filter(
(key) => draft.inputLabware.findIndex((labware) => labware.barcode === key) === -1
(key) =>
draft.inputLabware.findIndex((labware: LabwareFlaggedFieldsFragment) => labware.barcode === key) === -1
);
keys.forEach((key) => draft.errors.delete(key));

// Update destination slotCopyContent if it has entries for any removed labware
draft.outputSlotCopies.forEach((outputScc) => {
outputScc.slotCopyContent = outputScc.slotCopyContent.filter((scc) =>
draft.inputLabware.some((lw) => lw.barcode === scc.sourceBarcode)
draft.outputSlotCopies.forEach((outputScc: OutputSlotCopyData) => {
outputScc.slotCopyContent = outputScc.slotCopyContent.filter((scc: SlotCopyContent) =>
draft.inputLabware.some((lw: LabwareFlaggedFieldsFragment) => lw.barcode === scc.sourceBarcode)
);
});
});
Expand Down
16 changes: 14 additions & 2 deletions src/lib/machines/labelPrinter/labelPrinterMachine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assign, createMachine, fromPromise, MachineConfig, MachineImplementations } from 'xstate';
import { assign, createMachine, fromPromise, InternalMachineImplementations, MachineConfig } from 'xstate';
import { LabelPrinterContext, LabelPrinterEvent } from './labelPrinterMachineTypes';
import { find } from 'lodash';
import { castDraft, produce } from '../../../dependencies/immer';
Expand All @@ -8,7 +8,19 @@ import { LabelType, LabwareFieldsFragment, PrinterFieldsFragment } from '../../.
/**
* LabelPrinter Machine Options
*/
const machineOptions: MachineImplementations<LabelPrinterContext, LabelPrinterEvent> = {

type LabelPrinterMachineImplementation = {
context: LabelPrinterContext;
events: LabelPrinterEvent;
actors: any;
actions: any;
guards: any;
delays: any;
tags: any;
emitted: any;
};

const machineOptions: InternalMachineImplementations<LabelPrinterMachineImplementation> = {
actions: {
assignPrinters: assign(({ context, event }) => {
if (event.type !== 'xstate.done.actor.fetchPrinters') {
Expand Down
24 changes: 19 additions & 5 deletions src/lib/machines/layout/layoutMachineOptions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { LayoutContext, Source } from './layoutContext';
import { isEqual } from 'lodash';
import { tissue } from '../../helpers/labwareHelper';
import { LabwareFieldsFragment } from '../../../types/sdk';
import { assign, MachineImplementations, sendParent } from 'xstate';
import { LabwareFieldsFragment, Slot } from '../../../types/sdk';
import { assign, InternalMachineImplementations, sendParent } from 'xstate';
import { LayoutEvents } from './layoutEvents';
import { produce } from '../../../dependencies/immer';
import { LayoutSchema } from './layoutStates';
import { produce } from 'immer';

export const layoutMachineKey = 'layoutMachine';

Expand All @@ -21,7 +22,19 @@ export enum Actions {
CANCEL_EDIT_LAYOUT = 'layoutMachine.cancelEditLayout'
}

export const machineOptions: MachineImplementations<LayoutContext, LayoutEvents> = {
type LayoutMachineImplementation = {
context: LayoutContext;
events: LayoutEvents;
schema: LayoutSchema;
actors: any;
actions: any;
guards: any;
delays: any;
tags: any;
emitted: any;
};

export const machineOptions: InternalMachineImplementations<LayoutMachineImplementation> = {
actions: {
[Actions.ASSIGN_SELECTED]: assign(({ context, event }) => {
if (event.type !== 'SELECT_SOURCE') {
Expand Down Expand Up @@ -72,7 +85,8 @@ export const machineOptions: MachineImplementations<LayoutContext, LayoutEvents>
return context;
}
return produce(context, (draft) => {
draft.layoutPlan.destinationLabware.slots.forEach((slot) => {
// @ts-ignore
draft.layoutPlan.destinationLabware.slots.forEach((slot: Slot) => {
draft.layoutPlan.plannedActions.set(slot.address, [event.source]);
});
});
Expand Down
15 changes: 13 additions & 2 deletions src/lib/machines/locations/locationMachine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assign, createMachine, fromPromise, MachineConfig, MachineImplementations, raise } from 'xstate';
import { assign, createMachine, fromPromise, InternalMachineImplementations, MachineConfig, raise } from 'xstate';
import {
LocationContext,
LocationEvent,
Expand Down Expand Up @@ -33,7 +33,18 @@ enum Service {
/**
* Location Machine Options
*/
export const machineOptions: MachineImplementations<LocationContext, LocationEvent> = {
type LocationMachineImplementation = {
context: LocationContext;
events: LocationEvent;
actors: any;
actions: any;
guards: any;
delays: any;
tags: any;
emitted: any;
};

export const machineOptions: InternalMachineImplementations<LocationMachineImplementation> = {
actions: {
[Action.ASSIGN_LOCATION_SEARCH_PARAMS]: assign(({ context, event }) => {
if (event.type !== 'FETCH_LOCATION') {
Expand Down
1 change: 0 additions & 1 deletion src/mocks/handlers/xeniumHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const xeniumHandlers = [
{
data: {
analyserScanData: {
barcode: variables.barcode,
workNumbers: ['SGP1008'],
probes: [
faker.string.alphanumeric({ length: { min: 5, max: 8 } }),
Expand Down
Loading
Loading