@imposium-hub/components 1.30.0 → 1.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,21 +52,42 @@ class AssetField extends React.PureComponent<IAssetFieldProps, IAssetFieldState>
52
52
 
53
53
  // get the asset name from the API
54
54
  if (assetId && !this.state.assetName) {
55
- api.getAssetItem(assetId).then((data : any) => {
56
- this.setState({
57
- error: false,
58
- assetName: data.name
59
- });
60
- })
61
- .catch((e : Error) => {
62
- this.setState({
63
- error: true,
64
- assetName: `Cound not find asset: ${assetId}`
65
- });
55
+ this.loadAsset();
56
+ }
57
+ }
58
+
59
+ public componentDidUpdate(prevProps, prevState) {
60
+
61
+ const {assetId} = this.props;
62
+
63
+ if (assetId && assetId !== prevProps.assetId) {
64
+ this.loadAsset();
65
+ } else if (!assetId) {
66
+ this.setState({
67
+ error: false,
68
+ assetName: ''
66
69
  });
67
70
  }
68
71
  }
69
72
 
73
+ private loadAsset() {
74
+
75
+ const {assetId, api} = this.props;
76
+
77
+ api.getAssetItem(assetId).then((data : any) => {
78
+ this.setState({
79
+ error: false,
80
+ assetName: data.name
81
+ });
82
+ })
83
+ .catch((e : Error) => {
84
+ this.setState({
85
+ error: true,
86
+ assetName: `Cound not find asset: ${assetId}`
87
+ });
88
+ });
89
+ }
90
+
70
91
  public setFilter(e) {
71
92
 
72
93
  const {accepts} = this.props;
@@ -1,14 +1,14 @@
1
1
  import * as React from 'react';
2
2
  import { useDrag } from 'react-dnd';
3
- import { ASSET_DND_TYPES } from '../../constants/dnd';
4
-
5
- const DRAGGER_NAME : string = 'Asset';
3
+ import mergeRefs from 'react-merge-refs';
6
4
 
7
5
  interface IDataTableDnDWrapper {
8
6
  children : any;
9
7
  dndType : string;
10
8
  dndName : string;
11
9
  row : any;
10
+ rowRef : any;
11
+ rowProps : any;
12
12
  }
13
13
 
14
14
  const DataTableDndWrapper : React.FC<IDataTableDnDWrapper> = (props : IDataTableDnDWrapper) => {
@@ -25,9 +25,9 @@ const DataTableDndWrapper : React.FC<IDataTableDnDWrapper> = (props : IDataTable
25
25
  });
26
26
 
27
27
  return (
28
- <div ref = {drag}>
28
+ <tr {...props.rowProps} ref={mergeRefs([drag, props.rowRef])}>
29
29
  {props.children}
30
- </div>
30
+ </tr>
31
31
  );
32
32
  };
33
33
 
@@ -348,42 +348,48 @@ const DataTable : React.FC<IDataTableProps> = (props : IDataTableProps) => {
348
348
 
349
349
  prepareRow(row);
350
350
 
351
- const rowContent = <>
352
- <tr
353
- {...row.getRowProps()}
354
- ref = {activeRef}
355
- className = {`ip-table-row ${selectedClass}`}
356
- onClick = {(e) => {
357
- const onClick = () => {
358
- if (typeof props.onRowClick === 'function') {
359
- props.onRowClick(row);
360
- }
361
- };
362
-
363
- if (!doubleClickEnabled) {
364
- onClick();
365
- }
366
-
367
- if (e.detail === 1 && doubleClickEnabled) {
368
- doubleClickTimeout = window.setTimeout(onClick, 200);
369
- }
370
- }}
371
- onDoubleClick = {(e) => {
372
- clearTimeout(doubleClickTimeout);
373
- if (doubleClickEnabled) {
374
- props.onRowDoubleClick(row);
375
- }
376
- }}
351
+ const rowProps = row.getRowProps();
352
+ rowProps.className = `ip-table-row ${selectedClass}`;
353
+ rowProps.onClick = (e) => {
354
+ const onClick = () => {
355
+ if (typeof props.onRowClick === 'function') {
356
+ props.onRowClick(row);
357
+ }
358
+ };
359
+
360
+ if (!doubleClickEnabled) {
361
+ onClick();
362
+ }
363
+
364
+ if (e.detail === 1 && doubleClickEnabled) {
365
+ doubleClickTimeout = window.setTimeout(onClick, 200);
366
+ }
367
+ };
368
+ rowProps.onDoubleClick = (e) => {
369
+ clearTimeout(doubleClickTimeout);
370
+ if (doubleClickEnabled) {
371
+ props.onRowDoubleClick(row);
372
+ }
373
+ };
374
+
375
+ const rowContent = row.cells.map((cell) => (
376
+ <td
377
+ {...cell.getCellProps()}
378
+ className = {`ip-table-col ${(cell.column.overflowVisible) ? 'overflow-visible' : ''}`.trim()}
377
379
  >
378
- {row.cells.map((cell) => (
379
- <td
380
- {...cell.getCellProps()}
381
- className = {`ip-table-col ${(cell.column.overflowVisible) ? 'overflow-visible' : ''}`.trim()}
382
- >
383
- {cell.render('Cell')}
384
- </td>
385
- ))}
386
- </tr>
380
+ {cell.render('Cell')}
381
+ </td>
382
+ ));
383
+
384
+ return <React.Fragment key = {`row-${i}`}>
385
+
386
+ {(props.dnd) && <DataTableDnDWrapper rowProps = {rowProps} rowRef = {activeRef} key = {`row-${i}`} row = {row} dndType = {props.dndType} dndName = {props.dndName}>
387
+ {rowContent}
388
+ </DataTableDnDWrapper>}
389
+
390
+ {(!props.dnd) && <tr key = {`row-${i}`} ref = {activeRef} {...rowProps}>
391
+ {rowContent}
392
+ </tr>}
387
393
 
388
394
  {(row.isExpanded) &&
389
395
  (
@@ -400,18 +406,7 @@ const DataTable : React.FC<IDataTableProps> = (props : IDataTableProps) => {
400
406
  </tr>
401
407
  )
402
408
  }
403
- </>;
404
-
405
- if (props.dnd) {
406
- return <DataTableDnDWrapper key = {`row-${i}`} row = {row} dndType = {props.dndType} dndName = {props.dndName}>
407
- {rowContent}
408
- </DataTableDnDWrapper>;
409
- } else {
410
-
411
- return <React.Fragment key = {`row-${i}`}>
412
- {rowContent}
413
- </React.Fragment>;
414
- }
409
+ </React.Fragment>;
415
410
  })}
416
411
  </tbody>
417
412
  </table>
@@ -0,0 +1,97 @@
1
+ import * as React from 'react';
2
+ import AnsiUp from 'ansi_up';
3
+ import { fitToContainer } from '../../Util';
4
+ import { previewer as copy} from '../../constants/copy';
5
+ import { IImposiumAPI } from '../../services/API';
6
+
7
+ interface ILogViewerProps {
8
+ jobId : string;
9
+ onError?(e : string) : void;
10
+ api : IImposiumAPI;
11
+ }
12
+
13
+ interface ILogViewerState {
14
+ loading : boolean;
15
+ log : string;
16
+ }
17
+
18
+ class LogViewer extends React.PureComponent<ILogViewerProps, ILogViewerState> {
19
+
20
+ private videoNode : any;
21
+ private ansi_up : any;
22
+
23
+ constructor(props) {
24
+
25
+ super(props);
26
+
27
+ this.state = {
28
+ loading : true,
29
+ log: ''
30
+ };
31
+
32
+ this.ansi_up = new AnsiUp();
33
+ this.ansi_up.use_classes = true;
34
+ }
35
+
36
+ private getJobLogs() {
37
+
38
+ const { api, onError, jobId } = this.props;
39
+
40
+ api.getJobLogUrl(this.props.jobId).then((resLogUrl) => {
41
+
42
+ const jobUrl = resLogUrl.signed_url;
43
+
44
+ api.getJobLog(jobUrl).then((log) => {
45
+
46
+ this.setState({
47
+ loading: false,
48
+ log
49
+ });
50
+
51
+ }).catch((e) => {
52
+ if (onError) {
53
+ onError(copy.logDownloadError.replace('[jobId]', jobId));
54
+ }
55
+ this.setState({
56
+ loading: false,
57
+ log: ''
58
+ });
59
+ });
60
+
61
+ }).catch((e) => {
62
+ if (onError) {
63
+ onError(copy.logURLError.replace('[jobId]', this.props.jobId));
64
+ }
65
+ this.setState({
66
+ loading: false,
67
+ log: ''
68
+ });
69
+ });
70
+ }
71
+
72
+ public componentDidMount() {
73
+
74
+ if (this.props.jobId) {
75
+ this.getJobLogs();
76
+ }
77
+ }
78
+
79
+ public componentDidUpdate(prevProps) {
80
+
81
+ if (prevProps.jobId !== this.props.jobId && this.props.jobId) {
82
+ this.getJobLogs();
83
+ }
84
+ }
85
+ public render() {
86
+
87
+ const logHTML = this.ansi_up.ansi_to_html(this.state.log);
88
+
89
+ return (
90
+ <div className = 'log-viewer'>
91
+ <div className = 'log-html' dangerouslySetInnerHTML={{__html: logHTML}}></div>
92
+ </div>
93
+ );
94
+ }
95
+ }
96
+
97
+ export default LogViewer;