pollination-react-io 1.77.3 → 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.
package/build/index.js CHANGED
@@ -40868,6 +40868,13 @@ var useRuns = function (client) {
40868
40868
  return dayjs_min.duration(dayjs_min().utc()
40869
40869
  .diff(dayjs_min(status.started_at).utc())); // if cloudjob -> utc(true)
40870
40870
  };
40871
+ var getTrigger = function (item) {
40872
+ var _a;
40873
+ if (!((_a = item === null || item === void 0 ? void 0 : item.status) === null || _a === void 0 ? void 0 : _a.finished_at))
40874
+ return;
40875
+ var days = dayjs_min().diff(item.status.finished_at, 'days');
40876
+ return days >= 14;
40877
+ };
40871
40878
  var listRuns = React.useCallback(function (projectOwner, projectName, jobId, page, perPage, statusFilter) {
40872
40879
  if (!client || !client.runs)
40873
40880
  return;
@@ -40914,6 +40921,7 @@ var useRuns = function (client) {
40914
40921
  statusMap: statusMap,
40915
40922
  getSummaryColor: getSummaryColor,
40916
40923
  getDuration: getDuration,
40924
+ getTrigger: getTrigger
40917
40925
  };
40918
40926
  };
40919
40927
 
@@ -54879,6 +54887,19 @@ var FileUnknownFilled = function FileUnknownFilled(props, ref) {
54879
54887
  FileUnknownFilled.displayName = 'FileUnknownFilled';
54880
54888
  var FileUnknownFilled$1 = /*#__PURE__*/React__namespace.forwardRef(FileUnknownFilled);
54881
54889
 
54890
+ // This icon file is generated automatically.
54891
+ 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" };
54892
+ var FileZipFilledSvg = FileZipFilled$2;
54893
+
54894
+ var FileZipFilled = function FileZipFilled(props, ref) {
54895
+ return /*#__PURE__*/React__namespace.createElement(AntdIcon, _objectSpread2$1(_objectSpread2$1({}, props), {}, {
54896
+ ref: ref,
54897
+ icon: FileZipFilledSvg
54898
+ }));
54899
+ };
54900
+ FileZipFilled.displayName = 'FileZipFilled';
54901
+ var FileZipFilled$1 = /*#__PURE__*/React__namespace.forwardRef(FileZipFilled);
54902
+
54882
54903
  // This icon file is generated automatically.
54883
54904
  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" };
54884
54905
  var FolderFilledSvg = FolderFilled$2;
@@ -55970,6 +55991,8 @@ var getFileIcon = function (size, type) {
55970
55991
  case 'svg':
55971
55992
  case 'hdr':
55972
55993
  return React__default["default"].createElement(FileImageFilled$1, { style: { fontSize: size, color: '#862E9C' } });
55994
+ case 'zip':
55995
+ return React__default["default"].createElement(FileZipFilled$1, { style: { fontSize: size, color: '#f2b24d' } });
55973
55996
  default:
55974
55997
  return React__default["default"].createElement(FileUnknownFilled$1, { style: { fontSize: size } });
55975
55998
  }
@@ -55980,6 +56003,11 @@ var CADtypeEnum;
55980
56003
  CADtypeEnum[CADtypeEnum["HBJSON"] = 0] = "HBJSON";
55981
56004
  CADtypeEnum[CADtypeEnum["VSF"] = 1] = "VSF";
55982
56005
  })(CADtypeEnum || (CADtypeEnum = {}));
56006
+ /**
56007
+ * Download a file
56008
+ * @param blob Blob to convert
56009
+ * @param fileName File name to download
56010
+ */
55983
56011
  var download = function (blob, fileName) {
55984
56012
  var file = new File([blob], fileName);
55985
56013
  var a = document.createElement('a');
@@ -55992,38 +56020,80 @@ var download = function (blob, fileName) {
55992
56020
  a.click();
55993
56021
  };
55994
56022
  var FileCard = function (_a) {
55995
- var _b, _c;
55996
- 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;
56023
+ var _b;
56024
+ 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;
55997
56025
  var host = getHost();
55998
56026
  var fromFileToBase64 = usePollinationPanel().fromFileToBase64;
55999
- var _e = useVSFToHTML(), loading = _e.loading, html = _e.html, fetchHTML = _e.fetchHTML;
56000
- var _f = React.useState(false), open = _f[0], setOpen = _f[1];
56001
- var _g = React.useState(false), infoOver = _g[0], setInfoOver = _g[1];
56002
- var _h = React.useState(false), downloadOver = _h[0], setDownloadOver = _h[1];
56003
- var _j = React.useState(false), htmlOver = _j[0], setHtmlOver = _j[1];
56004
- var _k = React.useState(true), isLoading = _k[0], setIsLoading = _k[1];
56005
- var _l = React.useState(false), isInactive = _l[0], setIsInactive = _l[1];
56027
+ var _d = useVSFToHTML(), loading = _d.loading, html = _d.html, fetchHTML = _d.fetchHTML;
56028
+ var downloadArtifact = useArtifacts(projectOwner, projectName, client).downloadArtifact;
56029
+ var _e = React.useState(false), open = _e[0], setOpen = _e[1];
56030
+ // Hover effects
56031
+ var _f = React.useState(false), infoOver = _f[0], setInfoOver = _f[1];
56032
+ var _g = React.useState(false), downloadOver = _g[0], setDownloadOver = _g[1];
56033
+ var _h = React.useState(false), htmlOver = _h[0], setHtmlOver = _h[1];
56034
+ var _j = React.useState(true), isLoading = _j[0], setIsLoading = _j[1];
56035
+ var _k = React.useState(false), isInactive = _k[0], setIsInactive = _k[1];
56006
56036
  // Data to use for CAD injections
56007
- var _m = React.useState(), CADdata = _m[0], setCADdata = _m[1];
56037
+ var _l = React.useState(), CADdata = _l[0], setCADdata = _l[1];
56008
56038
  // File to send to parent
56009
- var _o = React.useState(), currFile = _o[0], setCurrFile = _o[1];
56010
- // /**
56011
- // * Check if run id is a valid UUID or file path (Local sim)
56012
- // * @param str run id
56013
- // * @returns true or false
56014
- // */
56015
- // const checkIfValidUUID = (str: string): boolean => {
56016
- // 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
56017
- // return regexExp.test(str)
56018
- // }
56019
- // const isCloud = useMemo(() => checkIfValidUUID(runId), [runId])
56020
- var downloadArtifact = useArtifacts(projectOwner, projectName, client).downloadArtifact;
56021
- var setCADintegration = React.useCallback(function (file) {
56039
+ var _m = React.useState(), currFile = _m[0], setCurrFile = _m[1];
56040
+ // HTML integration
56041
+ var _o = React.useState(false), hasHtml = _o[0], setHasHtml = _o[1];
56042
+ /**
56043
+ * Get file name to use
56044
+ */
56045
+ var filename = React.useMemo(function () {
56046
+ if (!path)
56047
+ return;
56048
+ return path.split('/').reverse()[0];
56049
+ }, [path]);
56050
+ /**
56051
+ * Get file from a ZIP file.
56052
+ * 1 zip = 1 file for now
56053
+ */
56054
+ var getFileFromZip = React.useCallback(function (file) {
56022
56055
  if (!file)
56023
56056
  return;
56057
+ var archive = new jszip_min();
56058
+ archive.loadAsync(file)
56059
+ .then(function (zip) { return __awaiter$1(void 0, void 0, void 0, function () {
56060
+ var entries, listOfPromises, promiseOfList;
56061
+ return __generator$1(this, function (_a) {
56062
+ entries = Object.keys(zip.files).map(function (name) { return zip.files[name]; });
56063
+ listOfPromises = entries.map(function (entry) {
56064
+ return entry
56065
+ .async('blob')
56066
+ .then(function (blob) { return [entry.name, blob]; });
56067
+ });
56068
+ promiseOfList = Promise.all(listOfPromises);
56069
+ promiseOfList.then(function (list) {
56070
+ list.forEach(function (_a) {
56071
+ var name = _a[0], f = _a[1];
56072
+ // 1 zip = 1 file
56073
+ // I assume text/plain
56074
+ var blob = f.slice(0, f.size, 'text/plain');
56075
+ setCurrFile(blob);
56076
+ if (name.endsWith('vsf')) {
56077
+ setHasHtml(true);
56078
+ fetchHTML(blob);
56079
+ setCADintegration(blob, name);
56080
+ }
56081
+ });
56082
+ });
56083
+ return [2 /*return*/];
56084
+ });
56085
+ }); });
56086
+ }, [file]);
56087
+ /**
56088
+ * Get CAD data to use with the panel
56089
+ */
56090
+ var setCADintegration = React.useCallback(function (file, name) {
56091
+ if (name === void 0) { name = undefined; }
56092
+ if (!file || !filename)
56093
+ return;
56024
56094
  if (host === 'web')
56025
56095
  return;
56026
- if (path.endsWith('hbjson')
56096
+ if (filename.endsWith('hbjson')
56027
56097
  && host === 'rhino') {
56028
56098
  var reader_1 = new FileReader();
56029
56099
  reader_1.readAsText(file);
@@ -56036,7 +56106,7 @@ var FileCard = function (_a) {
56036
56106
  });
56037
56107
  };
56038
56108
  }
56039
- else if (path.endsWith('vsf')
56109
+ else if ((filename.endsWith('vsf') || (name === null || name === void 0 ? void 0 : name.endsWith('vsf')))
56040
56110
  && (host === 'rhino' || host === 'revit')) {
56041
56111
  var reader_2 = new FileReader();
56042
56112
  reader_2.readAsText(file);
@@ -56049,7 +56119,7 @@ var FileCard = function (_a) {
56049
56119
  });
56050
56120
  };
56051
56121
  }
56052
- }, [file]);
56122
+ }, [file, filename]);
56053
56123
  /**
56054
56124
  * Fetch file from cloud
56055
56125
  */
@@ -56062,14 +56132,23 @@ var FileCard = function (_a) {
56062
56132
  setCurrFile(undefined);
56063
56133
  setCADintegration(undefined);
56064
56134
  setIsLoading(false);
56135
+ setHasHtml(false);
56065
56136
  return;
56066
56137
  }
56067
56138
  res.blob()
56068
56139
  .then(function (blob) {
56069
56140
  setCurrFile(blob);
56141
+ // All zip files
56142
+ if (blob.type === 'application/zip') {
56143
+ getFileFromZip(blob);
56144
+ }
56070
56145
  if (path === null || path === void 0 ? void 0 : path.endsWith('vsf')) {
56146
+ setHasHtml(true);
56071
56147
  fetchHTML(blob);
56072
56148
  }
56149
+ else {
56150
+ setHasHtml(false);
56151
+ }
56073
56152
  setCADintegration(blob);
56074
56153
  setIsLoading(false);
56075
56154
  setIsInactive(false);
@@ -56081,11 +56160,6 @@ var FileCard = function (_a) {
56081
56160
  setIsInactive(true);
56082
56161
  });
56083
56162
  };
56084
- var filename = React.useMemo(function () {
56085
- if (!path)
56086
- return;
56087
- return path.split('/').reverse()[0];
56088
- }, [path]);
56089
56163
  /**
56090
56164
  * Read local file as base64 - Panel only
56091
56165
  */
@@ -56151,15 +56225,15 @@ var FileCard = function (_a) {
56151
56225
  React__default["default"].createElement("div", { style: { float: 'left', margin: '0 8px 0 0' } }, !isLoading ? React__default["default"].createElement("div", { title: !isInactive
56152
56226
  ? 'Open the viewer'
56153
56227
  : 'File is missing. Check run workspace' },
56154
- React__default["default"].createElement("span", { style: { margin: '0 8px 0 0' } }, path && getFileIcon(18, ((_c = (_b = path.split('/')
56155
- .reverse()[0]) === null || _b === void 0 ? void 0 : _b.split('.')) === null || _c === void 0 ? void 0 : _c.pop()) || '')),
56228
+ React__default["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()) || '')),
56156
56229
  label)
56157
56230
  : React__default["default"].createElement(LoadingIcon, { size: 14 })),
56158
56231
  !isLoading && React__default["default"].createElement("div", { style: { textAlign: 'right' } },
56159
- (filename && filename.endsWith('vsf')) && (loading ? React__default["default"].createElement(LoadingIcon, { size: 14 }) :
56232
+ (filename && hasHtml) && (loading ? React__default["default"].createElement(LoadingIcon, { size: 14 }) :
56160
56233
  (React__default["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) {
56161
56234
  if (!html)
56162
56235
  return;
56236
+ setHtmlOver(false);
56163
56237
  event.stopPropagation();
56164
56238
  download(html, "".concat(label, ".html"));
56165
56239
  } },
@@ -56225,11 +56299,13 @@ styleInject(css_248z$2);
56225
56299
 
56226
56300
  var RunContent = function (_a) {
56227
56301
  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;
56302
+ var getTrigger = useRuns(client).getTrigger;
56228
56303
  var _c = React.useState([]), currData = _c[0], setCurrData = _c[1];
56229
56304
  var fileExplorer = usePollinationPanel().fileExplorer;
56230
56305
  var _d = React.useState([]), currParams = _d[0], setCurrParams = _d[1];
56231
56306
  var _e = React.useState([]), currFiles = _e[0], setCurrFiles = _e[1];
56232
56307
  var _f = React.useState([]), currFolders = _f[0], setCurrFolders = _f[1];
56308
+ var trigger = React.useMemo(function () { return isCloud ? getTrigger(run) : false; }, [run, isCloud]);
56233
56309
  React.useEffect(function () { return setCurrData(inputData); }, [inputData]);
56234
56310
  React.useEffect(function () {
56235
56311
  if (!currData || currData.length == 0)
@@ -56238,15 +56314,28 @@ var RunContent = function (_a) {
56238
56314
  var files = [];
56239
56315
  var folders = [];
56240
56316
  currData.forEach(function (i) {
56317
+ var _a, _b, _c, _d;
56241
56318
  switch (i.type) {
56242
56319
  case 'StepFileInput':
56320
+ files.push({ run: run, label: i.name,
56321
+ path: (_a = i.source) === null || _a === void 0 ? void 0 : _a.path, description: i.description });
56322
+ break;
56243
56323
  case 'StepFileOutput':
56324
+ var filePath = trigger
56325
+ ? "outputs/".concat(i.name, "/").concat(run.id, ".zip")
56326
+ : (_b = i.source) === null || _b === void 0 ? void 0 : _b.path;
56244
56327
  files.push({ run: run, label: i.name,
56245
- path: i.source.path, description: i.description });
56328
+ path: filePath, description: i.description });
56246
56329
  break;
56247
56330
  case 'StepFolderInput':
56331
+ folders.push({ label: i.name, path: (_c = i.source) === null || _c === void 0 ? void 0 : _c.path,
56332
+ description: i.description });
56333
+ break;
56248
56334
  case 'StepFolderOutput':
56249
- folders.push({ label: i.name, path: i.source.path,
56335
+ var folderPath = trigger
56336
+ ? "outputs/".concat(i.name)
56337
+ : (_d = i.source) === null || _d === void 0 ? void 0 : _d.path;
56338
+ folders.push({ label: i.name, path: folderPath,
56250
56339
  description: i.description });
56251
56340
  break;
56252
56341
  default: