Skip to content

Commit

Permalink
upgrade xstate to v5.13.2
Browse files Browse the repository at this point in the history
@types/lodash
@typescript-eslint/parser
  • Loading branch information
sabrine33 committed Dec 3, 2024
1 parent 72f9533 commit 3f4daee
Show file tree
Hide file tree
Showing 7 changed files with 1,923 additions and 3,137 deletions.
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/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
Loading

0 comments on commit 3f4daee

Please sign in to comment.