• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vanvalenlab / deepcell-label / 5720827273

pending completion
5720827273

Pull #519

github

web-flow
Merge 11c4d796a into 556f9652b
Pull Request #519: More reqs cleanup

470 of 1239 branches covered (37.93%)

Branch coverage included in aggregate %.

2559 of 4707 relevant lines covered (54.37%)

288.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.17
/frontend/src/Load/loadMachine.js
1
import axios from 'axios';
2
import { assign, Machine } from 'xstate';
3

4
const loadMachine = Machine(
18✔
5
  {
6
    context: {
7
      exampleFile: null,
8
      uploadFile: null,
9
      axes: 'ZYXC',
10
      errorText: '',
11
    },
12
    initial: 'idle',
13
    states: {
14
      idle: {
15
        on: {
16
          SET_EXAMPLE_FILE: { actions: 'setExampleFile' },
17
          SET_UPLOAD_FILE: [
18
            { cond: 'isSingleFile', target: 'uploaded', actions: 'setUploadFile' },
19
            { target: 'error', actions: 'setSingleFileError' },
20
          ],
21
          SUBMIT_EXAMPLE: { target: 'submittingExample' },
22
        },
23
      },
24
      uploaded: {
25
        on: {
26
          SET_AXES: { actions: 'setAxes' },
27
          SUBMIT_UPLOAD: { target: 'submittingUpload' },
28
        },
29
      },
30
      submittingExample: {
31
        invoke: {
32
          src: 'submitExample',
33
          onDone: { actions: 'redirectToProject' },
34
          onError: { target: 'error', actions: 'setErrorText' },
35
        },
36
      },
37
      submittingUpload: {
38
        invoke: {
39
          src: 'submitUpload',
40
          onDone: { actions: 'redirectToProject' },
41
          onError: { target: 'error', actions: 'setErrorText' },
42
        },
43
      },
44
      error: {
45
        on: {
46
          SUBMIT_UPLOAD: { target: 'submittingUpload' },
47
          SUBMIT_EXAMPLE: { target: 'submittingExample' },
48
          SET_UPLOAD_FILE: [
49
            { cond: 'isSingleFile', target: 'uploaded', actions: 'setUploadFile' },
50
            { actions: 'setSingleFileError' },
51
          ],
52
        },
53
      },
54
    },
55
  },
56
  {
57
    guards: {
58
      isSingleFile: (_, { files }) => files.length === 1,
×
59
    },
60
    services: {
61
      submitExample: (context) => {
62
        const { exampleFile } = context;
×
63
        const formData = new FormData();
×
64
        formData.append('images', exampleFile);
×
65
        return axios.post('/api/project', formData, {
×
66
          headers: { 'Content-Type': 'multipart/form-data' },
67
        });
68
      },
69
      submitUpload: (context) => {
70
        const { uploadFile, axes } = context;
×
71
        const formData = new FormData();
×
72
        formData.append('images', uploadFile);
×
73
        formData.append('axes', axes);
×
74
        return axios.post('/api/project/dropped', formData, {
×
75
          headers: { 'Content-Type': 'multipart/form-data' },
76
        });
77
      },
78
    },
79
    actions: {
80
      setExampleFile: assign({
81
        exampleFile: (_, { file }) => file,
×
82
      }),
83
      setUploadFile: assign({
84
        uploadFile: ({ uploadFile }, { files }) => {
85
          // Revoke the data uris of existing file previews to avoid memory leaks
86
          if (uploadFile) {
×
87
            URL.revokeObjectURL(uploadFile.preview);
×
88
          }
89
          const file = files[0];
×
90
          Object.assign(file, { preview: URL.createObjectURL(file) });
×
91
          return file;
×
92
        },
93
      }),
94
      setAxes: assign({ axes: (_, { axes }) => axes }),
×
95
      setErrorText: assign({ errorText: (_, event) => `${event.error}` }),
×
96
      setSingleFileError: assign({ errorText: 'Please upload a single file.' }),
97
      redirectToProject: (ctx, evt) => {
98
        const projectId = evt.data.data;
×
99
        let url = `${document.location.origin}/project?projectId=${projectId}&download=true`;
×
100
        window.location.href = url;
×
101
      },
102
    },
103
  }
104
);
105

106
export default loadMachine;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc