pollination-react-io 1.77.4 → 1.78.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.
@@ -36,4 +36,5 @@ export declare const useRuns: (client: APIClient) => {
36
36
  };
37
37
  getSummaryColor: (status: any) => any;
38
38
  getDuration: (item?: Run) => duration.Duration;
39
+ getTrigger: (item: Run) => boolean;
39
40
  };
@@ -40841,6 +40841,13 @@ var useRuns = function (client) {
40841
40841
  return dayjs_min.duration(dayjs_min().utc()
40842
40842
  .diff(dayjs_min(status.started_at).utc())); // if cloudjob -> utc(true)
40843
40843
  };
40844
+ var getTrigger = function (item) {
40845
+ var _a;
40846
+ if (!((_a = item === null || item === void 0 ? void 0 : item.status) === null || _a === void 0 ? void 0 : _a.finished_at))
40847
+ return;
40848
+ var days = dayjs_min().diff(item.status.finished_at, 'days');
40849
+ return days >= 14;
40850
+ };
40844
40851
  var listRuns = useCallback(function (projectOwner, projectName, jobId, page, perPage, statusFilter) {
40845
40852
  if (!client || !client.runs)
40846
40853
  return;
@@ -40887,6 +40894,7 @@ var useRuns = function (client) {
40887
40894
  statusMap: statusMap,
40888
40895
  getSummaryColor: getSummaryColor,
40889
40896
  getDuration: getDuration,
40897
+ getTrigger: getTrigger
40890
40898
  };
40891
40899
  };
40892
40900
 
@@ -54852,6 +54860,19 @@ var FileUnknownFilled = function FileUnknownFilled(props, ref) {
54852
54860
  FileUnknownFilled.displayName = 'FileUnknownFilled';
54853
54861
  var FileUnknownFilled$1 = /*#__PURE__*/React.forwardRef(FileUnknownFilled);
54854
54862
 
54863
+ // This icon file is generated automatically.
54864
+ var FileZipFilled$2 = { "icon": { "tag": "svg", "attrs": { "viewBox": "64 64 896 896", "focusable": "false" }, "children": [{ "tag": "path", "attrs": { "d": "M854.6 288.7c6 6 9.4 14.1 9.4 22.6V928c0 17.7-14.3 32-32 32H192c-17.7 0-32-14.3-32-32V96c0-17.7 14.3-32 32-32h424.7c8.5 0 16.7 3.4 22.7 9.4l215.2 215.3zM790.2 326L602 137.8V326h188.2zM296 136v64h64v-64h-64zm64 64v64h64v-64h-64zm-64 64v64h64v-64h-64zm64 64v64h64v-64h-64zm-64 64v64h64v-64h-64zm64 64v64h64v-64h-64zm-64 64v64h64v-64h-64zm0 64v160h128V584H296zm48 48h32v64h-32v-64z" } }] }, "name": "file-zip", "theme": "filled" };
54865
+ var FileZipFilledSvg = FileZipFilled$2;
54866
+
54867
+ var FileZipFilled = function FileZipFilled(props, ref) {
54868
+ return /*#__PURE__*/React.createElement(AntdIcon, _objectSpread2$1(_objectSpread2$1({}, props), {}, {
54869
+ ref: ref,
54870
+ icon: FileZipFilledSvg
54871
+ }));
54872
+ };
54873
+ FileZipFilled.displayName = 'FileZipFilled';
54874
+ var FileZipFilled$1 = /*#__PURE__*/React.forwardRef(FileZipFilled);
54875
+
54855
54876
  // This icon file is generated automatically.
54856
54877
  var FolderFilled$2 = { "icon": { "tag": "svg", "attrs": { "viewBox": "64 64 896 896", "focusable": "false" }, "children": [{ "tag": "path", "attrs": { "d": "M880 298.4H521L403.7 186.2a8.15 8.15 0 00-5.5-2.2H144c-17.7 0-32 14.3-32 32v592c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V330.4c0-17.7-14.3-32-32-32z" } }] }, "name": "folder", "theme": "filled" };
54857
54878
  var FolderFilledSvg = FolderFilled$2;
@@ -55943,6 +55964,8 @@ var getFileIcon = function (size, type) {
55943
55964
  case 'svg':
55944
55965
  case 'hdr':
55945
55966
  return React__default.createElement(FileImageFilled$1, { style: { fontSize: size, color: '#862E9C' } });
55967
+ case 'zip':
55968
+ return React__default.createElement(FileZipFilled$1, { style: { fontSize: size, color: '#f2b24d' } });
55946
55969
  default:
55947
55970
  return React__default.createElement(FileUnknownFilled$1, { style: { fontSize: size } });
55948
55971
  }
@@ -55953,6 +55976,11 @@ var CADtypeEnum;
55953
55976
  CADtypeEnum[CADtypeEnum["HBJSON"] = 0] = "HBJSON";
55954
55977
  CADtypeEnum[CADtypeEnum["VSF"] = 1] = "VSF";
55955
55978
  })(CADtypeEnum || (CADtypeEnum = {}));
55979
+ /**
55980
+ * Download a file
55981
+ * @param blob Blob to convert
55982
+ * @param fileName File name to download
55983
+ */
55956
55984
  var download = function (blob, fileName) {
55957
55985
  var file = new File([blob], fileName);
55958
55986
  var a = document.createElement('a');
@@ -55965,38 +55993,80 @@ var download = function (blob, fileName) {
55965
55993
  a.click();
55966
55994
  };
55967
55995
  var FileCard = function (_a) {
55968
- var _b, _c;
55969
- var projectOwner = _a.projectOwner, projectName = _a.projectName, client = _a.client, run = _a.run, label = _a.label, path = _a.path, file = _a.file, description = _a.description, onClicked = _a.onClicked, _d = _a.isCloud, isCloud = _d === void 0 ? true : _d;
55996
+ var _b;
55997
+ var projectOwner = _a.projectOwner, projectName = _a.projectName, client = _a.client, run = _a.run, label = _a.label, path = _a.path, file = _a.file, description = _a.description, onClicked = _a.onClicked, _c = _a.isCloud, isCloud = _c === void 0 ? true : _c;
55970
55998
  var host = getHost();
55971
55999
  var fromFileToBase64 = usePollinationPanel().fromFileToBase64;
55972
- var _e = useVSFToHTML(), loading = _e.loading, html = _e.html, fetchHTML = _e.fetchHTML;
55973
- var _f = useState(false), open = _f[0], setOpen = _f[1];
55974
- var _g = useState(false), infoOver = _g[0], setInfoOver = _g[1];
55975
- var _h = useState(false), downloadOver = _h[0], setDownloadOver = _h[1];
55976
- var _j = useState(false), htmlOver = _j[0], setHtmlOver = _j[1];
55977
- var _k = useState(true), isLoading = _k[0], setIsLoading = _k[1];
55978
- var _l = useState(false), isInactive = _l[0], setIsInactive = _l[1];
56000
+ var _d = useVSFToHTML(), loading = _d.loading, html = _d.html, fetchHTML = _d.fetchHTML;
56001
+ var downloadArtifact = useArtifacts(projectOwner, projectName, client).downloadArtifact;
56002
+ var _e = useState(false), open = _e[0], setOpen = _e[1];
56003
+ // Hover effects
56004
+ var _f = useState(false), infoOver = _f[0], setInfoOver = _f[1];
56005
+ var _g = useState(false), downloadOver = _g[0], setDownloadOver = _g[1];
56006
+ var _h = useState(false), htmlOver = _h[0], setHtmlOver = _h[1];
56007
+ var _j = useState(true), isLoading = _j[0], setIsLoading = _j[1];
56008
+ var _k = useState(false), isInactive = _k[0], setIsInactive = _k[1];
55979
56009
  // Data to use for CAD injections
55980
- var _m = useState(), CADdata = _m[0], setCADdata = _m[1];
56010
+ var _l = useState(), CADdata = _l[0], setCADdata = _l[1];
55981
56011
  // File to send to parent
55982
- var _o = useState(), currFile = _o[0], setCurrFile = _o[1];
55983
- // /**
55984
- // * Check if run id is a valid UUID or file path (Local sim)
55985
- // * @param str run id
55986
- // * @returns true or false
55987
- // */
55988
- // const checkIfValidUUID = (str: string): boolean => {
55989
- // const regexExp = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi
55990
- // return regexExp.test(str)
55991
- // }
55992
- // const isCloud = useMemo(() => checkIfValidUUID(runId), [runId])
55993
- var downloadArtifact = useArtifacts(projectOwner, projectName, client).downloadArtifact;
55994
- var setCADintegration = useCallback(function (file) {
56012
+ var _m = useState(), currFile = _m[0], setCurrFile = _m[1];
56013
+ // HTML integration
56014
+ var _o = useState(false), hasHtml = _o[0], setHasHtml = _o[1];
56015
+ /**
56016
+ * Get file name to use
56017
+ */
56018
+ var filename = useMemo(function () {
56019
+ if (!path)
56020
+ return;
56021
+ return path.split('/').reverse()[0];
56022
+ }, [path]);
56023
+ /**
56024
+ * Get file from a ZIP file.
56025
+ * 1 zip = 1 file for now
56026
+ */
56027
+ var getFileFromZip = useCallback(function (file) {
55995
56028
  if (!file)
55996
56029
  return;
56030
+ var archive = new jszip_min();
56031
+ archive.loadAsync(file)
56032
+ .then(function (zip) { return __awaiter$1(void 0, void 0, void 0, function () {
56033
+ var entries, listOfPromises, promiseOfList;
56034
+ return __generator$1(this, function (_a) {
56035
+ entries = Object.keys(zip.files).map(function (name) { return zip.files[name]; });
56036
+ listOfPromises = entries.map(function (entry) {
56037
+ return entry
56038
+ .async('blob')
56039
+ .then(function (blob) { return [entry.name, blob]; });
56040
+ });
56041
+ promiseOfList = Promise.all(listOfPromises);
56042
+ promiseOfList.then(function (list) {
56043
+ list.forEach(function (_a) {
56044
+ var name = _a[0], f = _a[1];
56045
+ // 1 zip = 1 file
56046
+ // I assume text/plain
56047
+ var blob = f.slice(0, f.size, 'text/plain');
56048
+ setCurrFile(blob);
56049
+ if (name.endsWith('vsf')) {
56050
+ setHasHtml(true);
56051
+ fetchHTML(blob);
56052
+ setCADintegration(blob, name);
56053
+ }
56054
+ });
56055
+ });
56056
+ return [2 /*return*/];
56057
+ });
56058
+ }); });
56059
+ }, [file]);
56060
+ /**
56061
+ * Get CAD data to use with the panel
56062
+ */
56063
+ var setCADintegration = useCallback(function (file, name) {
56064
+ if (name === void 0) { name = undefined; }
56065
+ if (!file || !filename)
56066
+ return;
55997
56067
  if (host === 'web')
55998
56068
  return;
55999
- if (path.endsWith('hbjson')
56069
+ if (filename.endsWith('hbjson')
56000
56070
  && host === 'rhino') {
56001
56071
  var reader_1 = new FileReader();
56002
56072
  reader_1.readAsText(file);
@@ -56009,7 +56079,7 @@ var FileCard = function (_a) {
56009
56079
  });
56010
56080
  };
56011
56081
  }
56012
- else if (path.endsWith('vsf')
56082
+ else if ((filename.endsWith('vsf') || (name === null || name === void 0 ? void 0 : name.endsWith('vsf')))
56013
56083
  && (host === 'rhino' || host === 'revit')) {
56014
56084
  var reader_2 = new FileReader();
56015
56085
  reader_2.readAsText(file);
@@ -56022,7 +56092,7 @@ var FileCard = function (_a) {
56022
56092
  });
56023
56093
  };
56024
56094
  }
56025
- }, [file]);
56095
+ }, [file, filename]);
56026
56096
  /**
56027
56097
  * Fetch file from cloud
56028
56098
  */
@@ -56035,14 +56105,23 @@ var FileCard = function (_a) {
56035
56105
  setCurrFile(undefined);
56036
56106
  setCADintegration(undefined);
56037
56107
  setIsLoading(false);
56108
+ setHasHtml(false);
56038
56109
  return;
56039
56110
  }
56040
56111
  res.blob()
56041
56112
  .then(function (blob) {
56042
56113
  setCurrFile(blob);
56114
+ // All zip files
56115
+ if (blob.type === 'application/zip') {
56116
+ getFileFromZip(blob);
56117
+ }
56043
56118
  if (path === null || path === void 0 ? void 0 : path.endsWith('vsf')) {
56119
+ setHasHtml(true);
56044
56120
  fetchHTML(blob);
56045
56121
  }
56122
+ else {
56123
+ setHasHtml(false);
56124
+ }
56046
56125
  setCADintegration(blob);
56047
56126
  setIsLoading(false);
56048
56127
  setIsInactive(false);
@@ -56054,11 +56133,6 @@ var FileCard = function (_a) {
56054
56133
  setIsInactive(true);
56055
56134
  });
56056
56135
  };
56057
- var filename = useMemo(function () {
56058
- if (!path)
56059
- return;
56060
- return path.split('/').reverse()[0];
56061
- }, [path]);
56062
56136
  /**
56063
56137
  * Read local file as base64 - Panel only
56064
56138
  */
@@ -56124,12 +56198,11 @@ var FileCard = function (_a) {
56124
56198
  React__default.createElement("div", { style: { float: 'left', margin: '0 8px 0 0' } }, !isLoading ? React__default.createElement("div", { title: !isInactive
56125
56199
  ? 'Open the viewer'
56126
56200
  : 'File is missing. Check run workspace' },
56127
- React__default.createElement("span", { style: { margin: '0 8px 0 0' } }, path && getFileIcon(18, ((_c = (_b = path.split('/')
56128
- .reverse()[0]) === null || _b === void 0 ? void 0 : _b.split('.')) === null || _c === void 0 ? void 0 : _c.pop()) || '')),
56201
+ React__default.createElement("span", { style: { margin: '0 8px 0 0' } }, path && filename && getFileIcon(18, ((_b = filename === null || filename === void 0 ? void 0 : filename.split('.')) === null || _b === void 0 ? void 0 : _b.pop()) || '')),
56129
56202
  label)
56130
56203
  : React__default.createElement(LoadingIcon, { size: 14 })),
56131
56204
  !isLoading && React__default.createElement("div", { style: { textAlign: 'right' } },
56132
- (filename && filename.endsWith('vsf')) && (loading ? React__default.createElement(LoadingIcon, { size: 14 }) :
56205
+ (filename && hasHtml) && (loading ? React__default.createElement(LoadingIcon, { size: 14 }) :
56133
56206
  (React__default.createElement("button", { style: { all: 'unset', margin: '0 0 0 8px' }, title: 'Download HTML', onMouseOver: function () { return setHtmlOver(true); }, onMouseLeave: function () { return setHtmlOver(false); }, onClick: function (event) {
56134
56207
  if (!html)
56135
56208
  return;
@@ -56199,11 +56272,13 @@ styleInject(css_248z$2);
56199
56272
 
56200
56273
  var RunContent = function (_a) {
56201
56274
  var inputData = _a.inputData, projectOwner = _a.projectOwner, projectName = _a.projectName, run = _a.run, client = _a.client, title = _a.title, style = _a.style, getFileCard = _a.getFileCard, getFolderCard = _a.getFolderCard, _b = _a.isCloud, isCloud = _b === void 0 ? true : _b;
56275
+ var getTrigger = useRuns(client).getTrigger;
56202
56276
  var _c = useState([]), currData = _c[0], setCurrData = _c[1];
56203
56277
  var fileExplorer = usePollinationPanel().fileExplorer;
56204
56278
  var _d = useState([]), currParams = _d[0], setCurrParams = _d[1];
56205
56279
  var _e = useState([]), currFiles = _e[0], setCurrFiles = _e[1];
56206
56280
  var _f = useState([]), currFolders = _f[0], setCurrFolders = _f[1];
56281
+ var trigger = useMemo(function () { return isCloud ? getTrigger(run) : false; }, [run, isCloud]);
56207
56282
  useEffect(function () { return setCurrData(inputData); }, [inputData]);
56208
56283
  useEffect(function () {
56209
56284
  if (!currData || currData.length == 0)
@@ -56212,15 +56287,28 @@ var RunContent = function (_a) {
56212
56287
  var files = [];
56213
56288
  var folders = [];
56214
56289
  currData.forEach(function (i) {
56290
+ var _a, _b, _c, _d;
56215
56291
  switch (i.type) {
56216
56292
  case 'StepFileInput':
56293
+ files.push({ run: run, label: i.name,
56294
+ path: (_a = i.source) === null || _a === void 0 ? void 0 : _a.path, description: i.description });
56295
+ break;
56217
56296
  case 'StepFileOutput':
56297
+ var filePath = trigger
56298
+ ? "outputs/".concat(i.name, "/").concat(run.id, ".zip")
56299
+ : (_b = i.source) === null || _b === void 0 ? void 0 : _b.path;
56218
56300
  files.push({ run: run, label: i.name,
56219
- path: i.source.path, description: i.description });
56301
+ path: filePath, description: i.description });
56220
56302
  break;
56221
56303
  case 'StepFolderInput':
56304
+ folders.push({ label: i.name, path: (_c = i.source) === null || _c === void 0 ? void 0 : _c.path,
56305
+ description: i.description });
56306
+ break;
56222
56307
  case 'StepFolderOutput':
56223
- folders.push({ label: i.name, path: i.source.path,
56308
+ var folderPath = trigger
56309
+ ? "outputs/".concat(i.name)
56310
+ : (_d = i.source) === null || _d === void 0 ? void 0 : _d.path;
56311
+ folders.push({ label: i.name, path: folderPath,
56224
56312
  description: i.description });
56225
56313
  break;
56226
56314
  default: