Passed
Push — master ( 4762c7...2b838c )
by Guangyu
08:55
created

src/components/MyEMS/FDD/SpaceFault.js   A

Complexity

Total Complexity 9
Complexity/F 0

Size

Lines of Code 865
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 771
mnd 9
bc 9
fnc 0
dl 0
loc 865
rs 9.829
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React, { createRef, Fragment, useEffect, useState } from 'react';
2
import paginationFactory, { PaginationProvider } from 'react-bootstrap-table2-paginator';
3
import BootstrapTable from 'react-bootstrap-table-next';
4
import {
5
  Breadcrumb,
6
  BreadcrumbItem,
7
  Row,
8
  Col,
9
  Card,
10
  CardBody,
11
  Button,
12
  ButtonGroup,
13
  Form,
14
  FormGroup,
15
  Input,
16
  Label,
17
  CustomInput,
18
  DropdownItem,
19
  DropdownMenu,
20
  DropdownToggle,
21
  InputGroup,
22
  UncontrolledDropdown,
23
  Spinner,
24
} from 'reactstrap';
25
import Datetime from 'react-datetime';
26
import moment from 'moment';
27
import Cascader from 'rc-cascader';
28
import { Link } from 'react-router-dom';
29
import Badge from 'reactstrap/es/Badge';
30
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
31
import FalconCardHeader from '../../common/FalconCardHeader';
32
import uuid from 'uuid/v1';
33
import { getPaginationArray } from '../../../helpers/utils';
34
import { getCookieValue, createCookie } from '../../../helpers/utils';
35
import withRedirect from '../../../hoc/withRedirect';
36
import { withTranslation } from 'react-i18next';
37
import { toast } from 'react-toastify';
38
import ButtonIcon from '../../common/ButtonIcon';
39
import { APIBaseURL } from '../../../config';
40
41
42
const SpaceFault = ({ setRedirect, setRedirectUrl, t }) => {
43
  let current_moment = moment();
44
  useEffect(() => {
45
    let is_logged_in = getCookieValue('is_logged_in');
46
    let user_name = getCookieValue('user_name');
47
    let user_display_name = getCookieValue('user_display_name');
48
    let user_uuid = getCookieValue('user_uuid');
49
    let token = getCookieValue('token');
50
    if (is_logged_in === null || !is_logged_in) {
51
      setRedirectUrl(`/authentication/basic/login`);
52
      setRedirect(true);
53
    } else {
54
      //update expires time of cookies
55
      createCookie('is_logged_in', true, 1000 * 60 * 60 * 8);
56
      createCookie('user_name', user_name, 1000 * 60 * 60 * 8);
57
      createCookie('user_display_name', user_display_name, 1000 * 60 * 60 * 8);
58
      createCookie('user_uuid', user_uuid, 1000 * 60 * 60 * 8);
59
      createCookie('token', token, 1000 * 60 * 60 * 8);
60
    }
61
  });
62
  // State
63
  // Query Parameters
64
  const [selectedSpaceName, setSelectedSpaceName] = useState(undefined);
65
  const [selectedSpaceID, setSelectedSpaceID] = useState(undefined);
66
  const [reportingPeriodBeginsDatetime, setReportingPeriodBeginsDatetime] = useState(current_moment.clone().startOf('month'));
67
  const [reportingPeriodEndsDatetime, setReportingPeriodEndsDatetime] = useState(current_moment);
68
  const [cascaderOptions, setCascaderOptions] = useState(undefined);
69
  
70
  // buttons
71
  const [submitButtonDisabled, setSubmitButtonDisabled] = useState(true);
72
  const [spinnerHidden, setSpinnerHidden] = useState(true);
73
  const [exportButtonHidden, setExportButtonHidden] = useState(true);
74
75
  //Results
76
  const [detailedDataTableData, setDetailedDataTableData] = useState([]);
77
  const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]);
78
  const [excelBytesBase64, setExcelBytesBase64] = useState(undefined);
79
80
  useEffect(() => {
81
    let isResponseOK = false;
82
    fetch(APIBaseURL + '/spaces/tree', {
83
      method: 'GET',
84
      headers: {
85
        "Content-type": "application/json",
86
        "User-UUID": getCookieValue('user_uuid'),
87
        "Token": getCookieValue('token')
88
      },
89
      body: null,
90
91
    }).then(response => {
92
      console.log(response);
93
      if (response.ok) {
94
        isResponseOK = true;
95
        // enable submit button
96
        setSubmitButtonDisabled(false);
97
      }
98
      return response.json();
99
    }).then(json => {
100
      console.log(json);
101
      if (isResponseOK) {
102
        // rename keys 
103
        json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
104
        setCascaderOptions(json);
105
        setSelectedSpaceName([json[0]].map(o => o.label));
106
        setSelectedSpaceID([json[0]].map(o => o.value));
107
      } else {
108
        toast.error(json.description);
109
      }
110
    }).catch(err => {
111
      console.log(err);
112
    });
113
114
  }, []);
115
  const orderFormatter = (dataField, { id, name, email }) => (
116
    <Fragment>
117
      <Link to="/e-commerce/order-details">
118
        <strong>#{id}</strong>
119
      </Link>{' '}
120
      by <strong>{name}</strong>
121
      <br />
122
      <a href={`mailto:${email}`}>{email}</a>
123
    </Fragment>
124
  );
125
126
  const shippingFormatter = (address, { shippingType }) => (
127
    <Fragment>
128
      {address}
129
      <p className="mb-0 text-500">{shippingType}</p>
130
    </Fragment>
131
  );
132
133
  const badgeFormatter = status => {
134
    let color = '';
135
    let icon = '';
136
    let text = '';
137
    switch (status) {
138
      case 'success':
139
        color = 'success';
140
        icon = 'check';
141
        text = 'Completed';
142
        break;
143
      case 'hold':
144
        color = 'secondary';
145
        icon = 'ban';
146
        text = 'On hold';
147
        break;
148
      case 'processing':
149
        color = 'primary';
150
        icon = 'redo';
151
        text = 'Processing';
152
        break;
153
      case 'pending':
154
        color = 'warning';
155
        icon = 'stream';
156
        text = 'Pending';
157
        break;
158
      default:
159
        color = 'warning';
160
        icon = 'stream';
161
        text = 'Pending';
162
    }
163
164
    return (
165
      <Badge color={`soft-${color}`} className="rounded-capsule fs--1 d-block">
166
        {text}
167
        <FontAwesomeIcon icon={icon} transform="shrink-2" className="ml-1" />
168
      </Badge>
169
    );
170
  };
171
172
  const actionFormatter = (dataField, { id }) => (
173
    // Control your row with this id
174
    <UncontrolledDropdown>
175
      <DropdownToggle color="link" size="sm" className="text-600 btn-reveal mr-3">
176
        <FontAwesomeIcon icon="ellipsis-h" className="fs--1" />
177
      </DropdownToggle>
178
      <DropdownMenu right className="border py-2">
179
        <DropdownItem onClick={() => console.log('Completed: ', id)}>Completed</DropdownItem>
180
        <DropdownItem onClick={() => console.log('Processing: ', id)}>Processing</DropdownItem>
181
        <DropdownItem onClick={() => console.log('On hold: ', id)}>On hold</DropdownItem>
182
        <DropdownItem onClick={() => console.log('Pending: ', id)}>Pending</DropdownItem>
183
        <DropdownItem divider />
184
        <DropdownItem onClick={() => console.log('Delete: ', id)} className="text-danger">
185
          Delete
186
        </DropdownItem>
187
      </DropdownMenu>
188
    </UncontrolledDropdown>
189
  );
190
191
  const options = {
192
    custom: true,
193
    sizePerPage: 10,
194
    totalSize: detailedDataTableData.length
195
  };
196
197
  const SelectRowInput = ({ indeterminate, rowIndex, ...rest }) => (
198
    <div className="custom-control custom-checkbox">
199
      <input
200
        className="custom-control-input"
201
        {...rest}
202
        onChange={() => { }}
203
        ref={input => {
204
          if (input) input.indeterminate = indeterminate;
205
        }}
206
      />
207
      <label className="custom-control-label" />
208
    </div>
209
  );
210
211
  const selectRow = onSelect => ({
212
    mode: 'checkbox',
213
    classes: 'py-2 align-middle',
214
    clickToSelect: false,
215
    selectionHeaderRenderer: ({ mode, ...rest }) => <SelectRowInput type="checkbox" {...rest} />,
216
    selectionRenderer: ({ mode, ...rest }) => <SelectRowInput type={mode} {...rest} />,
217
    onSelect: onSelect,
218
    onSelectAll: onSelect
219
  });
220
  const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0';
221
222
  let table = createRef();
223
224
  const [isSelected, setIsSelected] = useState(false);
225
  const handleNextPage = ({ page, onPageChange }) => () => {
226
    onPageChange(page + 1);
227
  };
228
229
  const handlePrevPage = ({ page, onPageChange }) => () => {
230
    onPageChange(page - 1);
231
  };
232
233
  const onSelect = () => {
234
    setImmediate(() => {
235
      setIsSelected(!!table.current.selectionContext.selected.length);
236
    });
237
  };
238
239
  let onSpaceCascaderChange = (value, selectedOptions) => {
240
    console.log(value, selectedOptions);
241
    setSelectedSpaceName(selectedOptions.map(o => o.label).join('/'));
242
    setSelectedSpaceID(value[value.length - 1]);
243
  }
244
  let onReportingPeriodBeginsDatetimeChange = (newDateTime) => {
245
    setReportingPeriodBeginsDatetime(newDateTime);
246
  }
247
248
  let onReportingPeriodEndsDatetimeChange = (newDateTime) => {
249
    setReportingPeriodEndsDatetime(newDateTime);
250
  }
251
252
  var getValidReportingPeriodBeginsDatetimes = function (currentDate) {
253
    return currentDate.isBefore(moment(reportingPeriodEndsDatetime, 'MM/DD/YYYY, hh:mm:ss a'));
254
  }
255
256
  var getValidReportingPeriodEndsDatetimes = function (currentDate) {
257
    return currentDate.isAfter(moment(reportingPeriodBeginsDatetime, 'MM/DD/YYYY, hh:mm:ss a'));
258
  }
259
260
  // Handler
261
  const handleSubmit = e => {
262
    e.preventDefault();
263
    console.log('handleSubmit');
264
    console.log(selectedSpaceID);
265
    console.log(reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss'));
266
    console.log(reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'));
267
268
    // disable submit button
269
    setSubmitButtonDisabled(true);
270
    // show spinner
271
    setSpinnerHidden(false);
272
    // hide export buttion
273
    setExportButtonHidden(true)
274
275
    // Reinitialize tables
276
    setDetailedDataTableData([]);
277
    
278
    let isResponseOK = false;
279
    fetch(APIBaseURL + '/reports/fddspacefault?' +
280
      'spaceid=' + selectedSpaceID + 
281
      '&reportingperiodstartdatetime=' + reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') +
282
      '&reportingperiodenddatetime=' + reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'), {
283
      method: 'GET',
284
      headers: {
285
        "Content-type": "application/json",
286
        "User-UUID": getCookieValue('user_uuid'),
287
        "Token": getCookieValue('token')
288
      },
289
      body: null,
290
291
    }).then(response => {
292
      if (response.ok) {
293
        isResponseOK = true;
294
      }
295
296
      // enable submit button
297
      setSubmitButtonDisabled(false);
298
      // hide spinner
299
      setSpinnerHidden(true);
300
      // show export buttion
301
      setExportButtonHidden(false)
302
303
      return response.json();
304
    }).then(json => {
305
      if (isResponseOK) {
306
        console.log(json)
307
        setDetailedDataTableData([
308
          {
309
            id: uuid().split('-')[0],
310
            // id: 181,
311
            name: 'Ricky Antony',
312
            email: '[email protected]',
313
            date: '20/04/2019',
314
            address: 'Ricky Antony, 2392 Main Avenue, Penasauka, New Jersey 02149',
315
            shippingType: 'Via Flat Rate',
316
            status: 'success',
317
            amount: 99
318
          },
319
          {
320
            id: uuid().split('-')[0],
321
            // id: 182,
322
            name: 'Kin Rossow',
323
            email: '[email protected]',
324
            date: '20/04/2019',
325
            address: 'Kin Rossow, 1 Hollywood Blvd,Beverly Hills, California 90210',
326
            shippingType: 'Via Free Shipping',
327
            status: 'success',
328
            amount: 120
329
          },
330
          {
331
            id: uuid().split('-')[0],
332
            // id: 183,
333
            name: 'Merry Diana',
334
            email: '[email protected]',
335
            date: '30/04/2019',
336
            address: 'Merry Diana, 1 Infinite Loop, Cupertino, California 90210',
337
            shippingType: 'Via Link Road',
338
            status: 'hold',
339
            amount: 70
340
          },
341
          {
342
            id: uuid().split('-')[0],
343
            // id: 184,
344
            name: 'Bucky Robert',
345
            email: '[email protected]',
346
            date: '30/04/2019',
347
            address: 'Bucky Robert, 1 Infinite Loop, Cupertino, California 90210',
348
            shippingType: 'Via Free Shipping',
349
            status: 'pending',
350
            amount: 92
351
          },
352
          {
353
            id: uuid().split('-')[0],
354
            // id: 185,
355
            name: 'Rocky Zampa',
356
            email: '[email protected]',
357
            date: '30/04/2019',
358
            address: 'Rocky Zampa, 1 Infinite Loop, Cupertino, California 90210',
359
            shippingType: 'Via Free Road',
360
            status: 'hold',
361
            amount: 120
362
          },
363
          {
364
            id: uuid().split('-')[0],
365
            // id: 186,
366
            name: 'Ricky John',
367
            email: '[email protected]',
368
            date: '30/04/2019',
369
            address: 'Ricky John, 1 Infinite Loop, Cupertino, California 90210',
370
            shippingType: 'Via Free Shipping',
371
            status: 'processing',
372
            amount: 145
373
          },
374
          {
375
            id: uuid().split('-')[0],
376
            // id: 187,
377
            name: 'Cristofer Henric',
378
            email: '[email protected]',
379
            date: '30/04/2019',
380
            address: 'Cristofer Henric, 1 Infinite Loop, Cupertino, California 90210',
381
            shippingType: 'Via Flat Rate',
382
            status: 'success',
383
            amount: 55
384
          },
385
          {
386
            id: uuid().split('-')[0],
387
            // id: 188,
388
            name: 'Brate Lee',
389
            email: '[email protected]',
390
            date: '29/04/2019',
391
            address: 'Brate Lee, 1 Infinite Loop, Cupertino, California 90210',
392
            shippingType: 'Via Link Road',
393
            status: 'hold',
394
            amount: 90
395
          },
396
          {
397
            id: uuid().split('-')[0],
398
            // id: 189,
399
            name: 'Thomas Stephenson',
400
            email: '[email protected]',
401
            date: '29/04/2019',
402
            address: 'Thomas Stephenson, 116 Ballifeary Road, Bamff',
403
            shippingType: 'Via Flat Rate',
404
            status: 'processing',
405
            amount: 52
406
          },
407
          {
408
            id: uuid().split('-')[0],
409
            // id: 190,
410
            name: 'Evie Singh',
411
            email: '[email protected]',
412
            date: '29/04/2019',
413
            address: 'Evie Singh, 54 Castledore Road, Tunstead',
414
            shippingType: 'Via Flat Rate',
415
            status: 'success',
416
            amount: 90
417
          },
418
          {
419
            id: uuid().split('-')[0],
420
            // id: 191,
421
            name: 'David Peters',
422
            email: '[email protected]',
423
            date: '29/04/2019',
424
            address: 'David Peters, Rhyd Y Groes, Rhosgoch, LL66 0AT',
425
            shippingType: 'Via Link Road',
426
            status: 'success',
427
            amount: 69
428
          },
429
          {
430
            id: uuid().split('-')[0],
431
            // id: 192,
432
            name: 'Jennifer Johnson',
433
            email: '[email protected]',
434
            date: '28/04/2019',
435
            address: 'Jennifer Johnson, Rhyd Y Groes, Rhosgoch, LL66 0AT',
436
            shippingType: 'Via Flat Rate',
437
            status: 'processing',
438
            amount: 112
439
          },
440
          {
441
            id: uuid().split('-')[0],
442
            // id: 193,
443
            name: ' Demarcus Okuneva',
444
            email: '[email protected]',
445
            date: '28/04/2019',
446
            address: ' Demarcus Okuneva, 90555 Upton Drive Jeffreyview, UT 08771',
447
            shippingType: 'Via Flat Rate',
448
            status: 'success',
449
            amount: 99
450
          },
451
          {
452
            id: uuid().split('-')[0],
453
            // id: 194,
454
            name: 'Simeon Harber',
455
            email: '[email protected]',
456
            date: '27/04/2019',
457
            address: 'Simeon Harber, 702 Kunde Plain Apt. 634 East Bridgetview, HI 13134-1862',
458
            shippingType: 'Via Free Shipping',
459
            status: 'hold',
460
            amount: 129
461
          },
462
          {
463
            id: uuid().split('-')[0],
464
            // id: 195,
465
            name: 'Lavon Haley',
466
            email: '[email protected]',
467
            date: '27/04/2019',
468
            address: 'Lavon Haley, 30998 Adonis Locks McGlynnside, ID 27241',
469
            shippingType: 'Via Free Shipping',
470
            status: 'pending',
471
            amount: 70
472
          },
473
          {
474
            id: uuid().split('-')[0],
475
            // id: 196,
476
            name: 'Ashley Kirlin',
477
            email: '[email protected]',
478
            date: '26/04/2019',
479
            address: 'Ashley Kirlin, 43304 Prosacco Shore South Dejuanfurt, MO 18623-0505',
480
            shippingType: 'Via Link Road',
481
            status: 'processing',
482
            amount: 39
483
          },
484
          {
485
            id: uuid().split('-')[0],
486
            // id: 197,
487
            name: 'Johnnie Considine',
488
            email: '[email protected]',
489
            date: '26/04/2019',
490
            address: 'Johnnie Considine, 6008 Hermann Points Suite 294 Hansenville, TN 14210',
491
            shippingType: 'Via Flat Rate',
492
            status: 'pending',
493
            amount: 70
494
          },
495
          {
496
            id: uuid().split('-')[0],
497
            // id: 198,
498
            name: 'Trace Farrell',
499
            email: '[email protected]',
500
            date: '26/04/2019',
501
            address: 'Trace Farrell, 431 Steuber Mews Apt. 252 Germanland, AK 25882',
502
            shippingType: 'Via Free Shipping',
503
            status: 'success',
504
            amount: 70
505
          },
506
          {
507
            id: uuid().split('-')[0],
508
            // id: 199,
509
            name: 'Estell Nienow',
510
            email: '[email protected]',
511
            date: '26/04/2019',
512
            address: 'Estell Nienow, 4167 Laverna Manor Marysemouth, NV 74590',
513
            shippingType: 'Via Free Shipping',
514
            status: 'success',
515
            amount: 59
516
          },
517
          {
518
            id: uuid().split('-')[0],
519
            // id: 200,
520
            name: 'Daisha Howe',
521
            email: '[email protected]',
522
            date: '25/04/2019',
523
            address: 'Daisha Howe, 829 Lavonne Valley Apt. 074 Stehrfort, RI 77914-0379',
524
            shippingType: 'Via Free Shipping',
525
            status: 'success',
526
            amount: 39
527
          },
528
          {
529
            id: uuid().split('-')[0],
530
            // id: 201,
531
            name: 'Miles Haley',
532
            email: '[email protected]',
533
            date: '24/04/2019',
534
            address: 'Miles Haley, 53150 Thad Squares Apt. 263 Archibaldfort, MO 00837',
535
            shippingType: 'Via Flat Rate',
536
            status: 'success',
537
            amount: 55
538
          },
539
          {
540
            id: uuid().split('-')[0],
541
            // id: 202,
542
            name: 'Brenda Watsica',
543
            email: '[email protected]',
544
            date: '24/04/2019',
545
            address: "Brenda Watsica, 9198 O'Kon Harbors Morarborough, IA 75409-7383",
546
            shippingType: 'Via Free Shipping',
547
            status: 'success',
548
            amount: 89
549
          },
550
          {
551
            id: uuid().split('-')[0],
552
            // id: 203,
553
            name: "Ellie O'Reilly",
554
            email: '[email protected]',
555
            date: '24/04/2019',
556
            address: "Ellie O'Reilly, 1478 Kaitlin Haven Apt. 061 Lake Muhammadmouth, SC 35848",
557
            shippingType: 'Via Free Shipping',
558
            status: 'success',
559
            amount: 47
560
          },
561
          {
562
            id: uuid().split('-')[0],
563
            // id: 204,
564
            name: 'Garry Brainstrow',
565
            email: '[email protected]',
566
            date: '23/04/2019',
567
            address: 'Garry Brainstrow, 13572 Kurt Mews South Merritt, IA 52491',
568
            shippingType: 'Via Free Shipping',
569
            status: 'success',
570
            amount: 139
571
          },
572
          {
573
            id: uuid().split('-')[0],
574
            // id: 205,
575
            name: 'Estell Pollich',
576
            email: '[email protected]',
577
            date: '23/04/2019',
578
            address: 'Estell Pollich, 13572 Kurt Mews South Merritt, IA 52491',
579
            shippingType: 'Via Free Shipping',
580
            status: 'hold',
581
            amount: 49
582
          },
583
          {
584
            id: uuid().split('-')[0],
585
            // id: 206,
586
            name: 'Ara Mueller',
587
            email: '[email protected]',
588
            date: '23/04/2019',
589
            address: 'Ara Mueller, 91979 Kohler Place Waelchiborough, CT 41291',
590
            shippingType: 'Via Flat Rate',
591
            status: 'hold',
592
            amount: 19
593
          },
594
          {
595
            id: uuid().split('-')[0],
596
            // id: 207,
597
            name: 'Lucienne Blick',
598
            email: '[email protected]',
599
            date: '23/04/2019',
600
            address: 'Lucienne Blick, 6757 Giuseppe Meadows Geraldinemouth, MO 48819-4970',
601
            shippingType: 'Via Flat Rate',
602
            status: 'hold',
603
            amount: 59
604
          },
605
          {
606
            id: uuid().split('-')[0],
607
            // id: 208,
608
            name: 'Laverne Haag',
609
            email: '[email protected]',
610
            date: '22/04/2019',
611
            address: 'Laverne Haag, 2327 Kaylee Mill East Citlalli, AZ 89582-3143',
612
            shippingType: 'Via Flat Rate',
613
            status: 'hold',
614
            amount: 49
615
          },
616
          {
617
            id: uuid().split('-')[0],
618
            // id: 209,
619
            name: 'Brandon Bednar',
620
            email: '[email protected]',
621
            date: '22/04/2019',
622
            address: 'Brandon Bednar, 25156 Isaac Crossing Apt. 810 Lonborough, CO 83774-5999',
623
            shippingType: 'Via Flat Rate',
624
            status: 'hold',
625
            amount: 39
626
          },
627
          {
628
            id: uuid().split('-')[0],
629
            // id: 210,
630
            name: 'Dimitri Boehm',
631
            email: '[email protected]',
632
            date: '23/04/2019',
633
            address: 'Dimitri Boehm, 71603 Wolff Plains Apt. 885 Johnstonton, MI 01581',
634
            shippingType: 'Via Flat Rate',
635
            status: 'hold',
636
            amount: 111
637
          }
638
        ]);
639
        setDetailedDataTableColumns([
640
          {
641
            dataField: 'id',
642
            text: 'Space',
643
            classes: 'py-2 align-middle',
644
            formatter: orderFormatter,
645
            sort: true
646
          },
647
          {
648
            dataField: 'date',
649
            text: 'Date',
650
            classes: 'py-2 align-middle',
651
            sort: true
652
          },
653
          {
654
            dataField: 'address',
655
            text: 'Description',
656
            classes: 'py-2 align-middle',
657
            formatter: shippingFormatter,
658
            sort: true
659
          },
660
          {
661
            dataField: 'status',
662
            text: 'Status',
663
            classes: 'py-2 align-middle',
664
            formatter: badgeFormatter,
665
            sort: true
666
          },
667
          {
668
            dataField: '',
669
            text: '',
670
            classes: 'py-2 align-middle',
671
            formatter: actionFormatter,
672
            align: 'right'
673
          }
674
        ]);
675
        
676
        setExcelBytesBase64(json['excel_bytes_base64']);
677
      } else {
678
        toast.error(json.description)
679
      }
680
    }).catch(err => {
681
      console.log(err);
682
    });
683
  
684
  };
685
  
686
  const handleExport = e => {
687
    e.preventDefault();
688
    const mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
689
    const fileName = 'spacefault.xlsx'
690
    var fileUrl = "data:" + mimeType + ";base64," + excelBytesBase64;
691
    fetch(fileUrl)
692
        .then(response => response.blob())
693
        .then(blob => {
694
            var link = window.document.createElement("a");
695
            link.href = window.URL.createObjectURL(blob, { type: mimeType });
696
            link.download = fileName;
697
            document.body.appendChild(link);
698
            link.click();
699
            document.body.removeChild(link);
700
        });
701
  };
702
  
703
704
  return (
705
    <Fragment>
706
      <div>
707
        <Breadcrumb>
708
          <BreadcrumbItem>{t('Fault Detection & Diagnostics')}</BreadcrumbItem><BreadcrumbItem active>{t('Space Faults Data')}</BreadcrumbItem>
709
        </Breadcrumb>
710
      </div>
711
      <Card className="bg-light mb-3">
712
        <CardBody className="p-3">
713
          <Form onSubmit={handleSubmit}>
714
            <Row form>
715
              <Col xs="auto">
716
                <FormGroup className="form-group">
717
                  <Label className={labelClasses} for="space">
718
                    {t('Space')}
719
                  </Label>
720
                  <br />
721
                  <Cascader options={cascaderOptions}
722
                    onChange={onSpaceCascaderChange}
723
                    changeOnSelect
724
                    expandTrigger="hover">
725
                    <Input value={selectedSpaceName || ''} readOnly />
726
                  </Cascader>
727
                </FormGroup>
728
              </Col>
729
              <Col xs="auto">
730
                <FormGroup className="form-group">
731
                  <Label className={labelClasses} for="reportingPeriodBeginsDatetime">
732
                    {t('Reporting Period Begins')}
733
                  </Label>
734
                  <Datetime id='reportingPeriodBeginsDatetime'
735
                    value={reportingPeriodBeginsDatetime}
736
                    onChange={onReportingPeriodBeginsDatetimeChange}
737
                    isValidDate={getValidReportingPeriodBeginsDatetimes}
738
                    closeOnSelect={true} />
739
                </FormGroup>
740
              </Col>
741
              <Col xs="auto">
742
                <FormGroup className="form-group">
743
                  <Label className={labelClasses} for="reportingPeriodEndsDatetime">
744
                    {t('Reporting Period Ends')}
745
                  </Label>
746
                  <Datetime id='reportingPeriodEndsDatetime'
747
                    value={reportingPeriodEndsDatetime}
748
                    onChange={onReportingPeriodEndsDatetimeChange}
749
                    isValidDate={getValidReportingPeriodEndsDatetimes}
750
                    closeOnSelect={true} />
751
                </FormGroup>
752
              </Col>
753
              <Col xs="auto">
754
                <FormGroup>
755
                  <br></br>
756
                  <ButtonGroup id="submit">
757
                    <Button color="success" disabled={submitButtonDisabled} >{t('Submit')}</Button>
758
                  </ButtonGroup>
759
                </FormGroup>
760
              </Col>
761
              <Col xs="auto">
762
                <FormGroup>
763
                  <br></br>
764
                  <Spinner color="primary" hidden={spinnerHidden}  />
765
                </FormGroup>
766
              </Col>
767
              <Col xs="auto">
768
                  <br></br>
769
                  <ButtonIcon icon="external-link-alt" transform="shrink-3 down-2" color="falcon-default" 
770
                  hidden={exportButtonHidden}
771
                  onClick={handleExport} >
772
                    {t('Export')}
773
                  </ButtonIcon>
774
              </Col>
775
            </Row>
776
          </Form>
777
        </CardBody>
778
      </Card>
779
      <Card className="mb-3">
780
        <FalconCardHeader title={t('Fault List')} light={false}>
781
          {isSelected ? (
782
            <InputGroup size="sm" className="input-group input-group-sm">
783
              <CustomInput type="select" id="bulk-select">
784
                <option>Bulk actions</option>
785
                <option value="Refund">Refund</option>
786
                <option value="Delete">Delete</option>
787
                <option value="Archive">Archive</option>
788
              </CustomInput>
789
              <Button color="falcon-default" size="sm" className="ml-2">
790
                Apply
791
                </Button>
792
            </InputGroup>
793
          ) : (
794
              <Fragment>
795
                
796
              </Fragment>
797
            )}
798
        </FalconCardHeader>
799
        <CardBody className="p-0">
800
          <PaginationProvider pagination={paginationFactory(options)}>
801
            {({ paginationProps, paginationTableProps }) => {
802
              const lastIndex = paginationProps.page * paginationProps.sizePerPage;
803
804
              return (
805
                <Fragment>
806
                  <div className="table-responsive">
807
                    <BootstrapTable
808
                      ref={table}
809
                      bootstrap4
810
                      keyField="id"
811
                      data={detailedDataTableData}
812
                      columns={detailedDataTableColumns}
813
                      selectRow={selectRow(onSelect)}
814
                      bordered={false}
815
                      classes="table-dashboard table-striped table-sm fs--1 border-bottom mb-0 table-dashboard-th-nowrap"
816
                      rowClasses="btn-reveal-trigger"
817
                      headerClasses="bg-200 text-900"
818
                      {...paginationTableProps}
819
                    />
820
                  </div>
821
                  <Row noGutters className="px-1 py-3 flex-center">
822
                    <Col xs="auto">
823
                      <Button
824
                        color="falcon-default"
825
                        size="sm"
826
                        onClick={handlePrevPage(paginationProps)}
827
                        disabled={paginationProps.page === 1}
828
                      >
829
                        <FontAwesomeIcon icon="chevron-left" />
830
                      </Button>
831
                      {getPaginationArray(paginationProps.totalSize, paginationProps.sizePerPage).map(pageNo => (
832
                        <Button
833
                          color={paginationProps.page === pageNo ? 'falcon-primary' : 'falcon-default'}
834
                          size="sm"
835
                          className="ml-2"
836
                          onClick={() => paginationProps.onPageChange(pageNo)}
837
                          key={pageNo}
838
                        >
839
                          {pageNo}
840
                        </Button>
841
                      ))}
842
                      <Button
843
                        color="falcon-default"
844
                        size="sm"
845
                        className="ml-2"
846
                        onClick={handleNextPage(paginationProps)}
847
                        disabled={lastIndex >= paginationProps.totalSize}
848
                      >
849
                        <FontAwesomeIcon icon="chevron-right" />
850
                      </Button>
851
                    </Col>
852
                  </Row>
853
                </Fragment>
854
              );
855
            }}
856
          </PaginationProvider>
857
        </CardBody>
858
      </Card>
859
860
    </Fragment>
861
  );
862
};
863
864
export default withTranslation()(withRedirect(SpaceFault));
865