pollination-react-io 1.64.1 → 1.66.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.
@@ -1,4 +1,4 @@
1
- import type { Project, RecipeInterface, UserPrivate } from '@pollination-solutions/pollination-sdk';
1
+ import type { Project, ProjectRecipeFilter, UserPrivate } from '@pollination-solutions/pollination-sdk';
2
2
  import { CSSProperties } from 'react';
3
3
  import { APIClient, ProjectJobInfo } from '../hooks';
4
4
  import { Account } from '../SelectAccount/SelectAccount.types';
@@ -6,7 +6,7 @@ export declare type CreateStudyProps = {
6
6
  style?: CSSProperties;
7
7
  defaultAccount?: Account;
8
8
  defaultProject?: Project;
9
- defaultRecipe?: RecipeInterface;
9
+ defaultRecipe?: ProjectRecipeFilter;
10
10
  onSuccess?: (projectJobInfo: ProjectJobInfo, isCloud: boolean) => any;
11
11
  authUser?: UserPrivate;
12
12
  client?: APIClient;
@@ -1,10 +1,10 @@
1
- import { RecipeInterface, UserPrivate } from '@pollination-solutions/pollination-sdk';
1
+ import { ProjectRecipeFilter, UserPrivate } from '@pollination-solutions/pollination-sdk';
2
2
  import { APIClient } from '../hooks';
3
3
  export interface SelectRecipeProps {
4
4
  authUser?: UserPrivate;
5
5
  client?: APIClient;
6
6
  projectName?: string;
7
7
  projectOwner?: string;
8
- value?: RecipeInterface;
9
- onChange?: (recipe: RecipeInterface) => void;
8
+ value?: ProjectRecipeFilter;
9
+ onChange?: (recipe: ProjectRecipeFilter) => void;
10
10
  }
@@ -1,5 +1,5 @@
1
1
  import { APIClient } from './useAPIClient';
2
- import { RecipeInterface } from '@pollination-solutions/pollination-sdk';
2
+ import { ProjectRecipeFilter, RecipeInterface } from '@pollination-solutions/pollination-sdk';
3
3
  declare global {
4
4
  interface Window {
5
5
  sketchup?: any;
@@ -10,6 +10,7 @@ interface JobArgs {
10
10
  name: string;
11
11
  recipe: RecipeInterface;
12
12
  description?: string;
13
+ recipeFilter?: ProjectRecipeFilter;
13
14
  }
14
15
  export interface ProjectJobInfo {
15
16
  accountName: string;
@@ -18,6 +19,7 @@ export interface ProjectJobInfo {
18
19
  projectDescription?: string;
19
20
  jobName?: string;
20
21
  jobDescription?: string;
22
+ platform?: string;
21
23
  }
22
24
  export interface LocalConfig {
23
25
  localCPUCount: number;
@@ -29,6 +31,6 @@ export interface LocalConfig {
29
31
  export declare const useCreateStudy: (accountName: string, projectName: string, client: APIClient) => {
30
32
  host: string;
31
33
  createStudy: ({ name, recipe, description }: JobArgs, data: object, onSuccess?: (projectJobInfo: ProjectJobInfo) => void) => Promise<void>;
32
- createLocalStudy: ({ name, description, recipe }: JobArgs, data: object, { localCPUCount, localRunFolder, isLocalJob, cloudProjectName, cloudProjectOwner }: LocalConfig, onSuccess?: (projectJobInfo: ProjectJobInfo) => void, key?: string) => Promise<any>;
34
+ createLocalStudy: ({ name, description, recipe, recipeFilter }: JobArgs, data: object, { localCPUCount, localRunFolder, isLocalJob, cloudProjectName, cloudProjectOwner }: LocalConfig, onSuccess?: (projectJobInfo: ProjectJobInfo) => void, key?: string) => Promise<any>;
33
35
  };
34
36
  export {};
@@ -13,4 +13,5 @@ export declare const usePollinationPanel: () => {
13
13
  getPaginatedJob: (projectSlug: string, pageSize: number, curPage: number) => ProjectJobInfo[];
14
14
  getJob: (projectSlug: string) => ProjectJobInfo[];
15
15
  deleteJob: (projectSlug: string, path: string) => any;
16
+ getPlatforms: (projectSlug: string) => {};
16
17
  };
@@ -38120,6 +38120,26 @@ var usePollinationPanel = function () {
38120
38120
  return undefined;
38121
38121
  }
38122
38122
  };
38123
+ /**
38124
+ * Count number of simulation by platform
38125
+ * @param projectSlug Project slug
38126
+ * @returns Object with platform count
38127
+ */
38128
+ var getPlatforms = function (projectSlug) {
38129
+ if (!panel)
38130
+ return;
38131
+ var count = {};
38132
+ try {
38133
+ var message = panel.GetJob(projectSlug);
38134
+ var arr = JSON.parse(message.data);
38135
+ arr.forEach(function (i) { count[i.platform] = (count[i.platform] || 0) + 1; });
38136
+ return count;
38137
+ }
38138
+ catch (error) {
38139
+ // Do nothing. It is written at the end
38140
+ return undefined;
38141
+ }
38142
+ };
38123
38143
  /**
38124
38144
  * Delete job with the same input/ouput folder from DB
38125
38145
  * @param projectSlug Project slug
@@ -38150,7 +38170,8 @@ var usePollinationPanel = function () {
38150
38170
  fileExplorer: fileExplorer,
38151
38171
  getPaginatedJob: getPaginatedJob,
38152
38172
  getJob: getJob,
38153
- deleteJob: deleteJob
38173
+ deleteJob: deleteJob,
38174
+ getPlatforms: getPlatforms
38154
38175
  };
38155
38176
  };
38156
38177
 
@@ -38322,13 +38343,14 @@ var useCreateStudy = function (accountName, projectName, client) {
38322
38343
  });
38323
38344
  }, [accountName, client, processEntryCloud, projectName]);
38324
38345
  var createLocalStudy = useCallback(function (_a, data, _b, onSuccess, key) {
38325
- var name = _a.name, description = _a.description, recipe = _a.recipe;
38346
+ var name = _a.name, description = _a.description, recipe = _a.recipe, recipeFilter = _a.recipeFilter;
38326
38347
  var localCPUCount = _b.localCPUCount, localRunFolder = _b.localRunFolder, isLocalJob = _b.isLocalJob, cloudProjectName = _b.cloudProjectName, cloudProjectOwner = _b.cloudProjectOwner;
38327
38348
  if (key === void 0) { key = performance.now().toString(); }
38328
38349
  return __awaiter$1(void 0, void 0, void 0, function () {
38329
38350
  var job, jobInfo, response;
38330
- return __generator$1(this, function (_c) {
38331
- switch (_c.label) {
38351
+ var _c;
38352
+ return __generator$1(this, function (_d) {
38353
+ switch (_d.label) {
38332
38354
  case 0:
38333
38355
  if (!checkDotNet || !client || !uploadArtifact)
38334
38356
  return [2 /*return*/];
@@ -38353,9 +38375,9 @@ var useCreateStudy = function (accountName, projectName, client) {
38353
38375
  // JobInfo mapping
38354
38376
  ];
38355
38377
  case 1:
38356
- job = _c.sent();
38378
+ job = _d.sent();
38357
38379
  jobInfo = {
38358
- RecipeOwner: '',
38380
+ RecipeOwner: (_c = recipeFilter.owner) !== null && _c !== void 0 ? _c : 'ladybug-tools',
38359
38381
  Recipe: recipe,
38360
38382
  Job: job,
38361
38383
  IsLocalJob: isLocalJob,
@@ -42401,7 +42423,7 @@ var SelectRecipe = function (_a) {
42401
42423
  var data;
42402
42424
  return __generator$1(this, function (_a) {
42403
42425
  switch (_a.label) {
42404
- case 0: return [4 /*yield*/, client.projects.getProjectRecipes(queryConfig)];
42426
+ case 0: return [4 /*yield*/, client.projects.getProjectRecipeFilters(queryConfig)];
42405
42427
  case 1:
42406
42428
  data = (_a.sent()).data;
42407
42429
  setRecipes(function (state) { return state ? __spreadArray(__spreadArray([], state, true), data.resources, true) : __spreadArray([], data.resources, true); });
@@ -42424,8 +42446,8 @@ var SelectRecipe = function (_a) {
42424
42446
  return;
42425
42447
  }
42426
42448
  // if (selRecipe == null) return
42427
- if (selRecipe && selRecipe.metadata && selRecipe.metadata.name) {
42428
- comboBoxRef.current.setInputValue(selRecipe.metadata.name);
42449
+ if (selRecipe && selRecipe.name) {
42450
+ comboBoxRef.current.setInputValue(selRecipe.name);
42429
42451
  }
42430
42452
  comboBoxRef.current.selectItem(selRecipe);
42431
42453
  valueRef.current = selRecipe;
@@ -42437,12 +42459,11 @@ var SelectRecipe = function (_a) {
42437
42459
  return;
42438
42460
  setPageNumber(projectApiRef.current.page + 1);
42439
42461
  }, []);
42440
- return (React__default.createElement(ComboBox, { ref: comboBoxRef, items: (_b = recipes === null || recipes === void 0 ? void 0 : recipes.map(function (r, i) { return (__assign(__assign({}, r), { name: "".concat(r.metadata.name, "-").concat(r.metadata.tag), id: "".concat(r.metadata.name, "-").concat(r.metadata.tag) })); })) !== null && _b !== void 0 ? _b : [], renderItem: function (item) { return (React__default.createElement("div", { style: {
42462
+ return (React__default.createElement(ComboBox, { ref: comboBoxRef, items: (_b = recipes === null || recipes === void 0 ? void 0 : recipes.map(function (r, i) { return (__assign(__assign({}, r), { name: "".concat(r.name, "-").concat(r.tag), id: "".concat(r.name, "-").concat(r.tag) })); })) !== null && _b !== void 0 ? _b : [], onClear: function () { return setSelRecipe(undefined); }, renderItem: function (item) { return (React__default.createElement("div", { style: {
42441
42463
  display: 'flex',
42442
42464
  alignItems: 'center',
42443
42465
  gap: 8,
42444
- }, id: "".concat(item.metadata.name, "-").concat(item.metadata.tag) },
42445
- React__default.createElement(Avatar, { src: item.metadata.icon, alt: item.metadata.name, fallback: item.metadata.name, size: 24 }), "".concat(item.metadata.name, "-").concat(item.metadata.tag))); }, setSelected: setSelRecipe, inputProps: {
42466
+ }, id: "".concat(item.name, "-").concat(item.tag) }, item.name)); }, setSelected: setSelRecipe, inputProps: {
42446
42467
  placeholder: 'Select a recipe...',
42447
42468
  }, loading: loading, disabled: !authUser || !projectName, footer: (React__default.createElement("div", { key: "footer", style: {
42448
42469
  width: '100%',
@@ -44668,6 +44689,7 @@ var InputType;
44668
44689
  var RecipeForm = function (_a) {
44669
44690
  var _b, _c;
44670
44691
  var recipe = _a.recipe, projectName = _a.projectName, projectOwner = _a.projectOwner, client = _a.client, onSubmit = _a.onSubmit, _d = _a.style, style = _d === void 0 ? {} : _d;
44692
+ var getJob = usePollinationPanel().getJob;
44671
44693
  /**
44672
44694
  * Input mapping
44673
44695
  */
@@ -44711,7 +44733,8 @@ var RecipeForm = function (_a) {
44711
44733
  var _e = useForm({
44712
44734
  resolver: Oe(schema),
44713
44735
  mode: 'onChange'
44714
- }), control = _e.control, register = _e.register, handleSubmit = _e.handleSubmit, resetField = _e.resetField, _f = _e.formState, errors = _f.errors, isValid = _f.isValid;
44736
+ }), control = _e.control, register = _e.register, handleSubmit = _e.handleSubmit, resetField = _e.resetField, watch = _e.watch, _f = _e.formState, errors = _f.errors, isValid = _f.isValid;
44737
+ var watchStudyName = watch('study-name');
44715
44738
  /**
44716
44739
  * Form actions
44717
44740
  * @param data Output data
@@ -44784,6 +44807,40 @@ var RecipeForm = function (_a) {
44784
44807
  * Local study
44785
44808
  */
44786
44809
  var _g = useState(__assign(__assign({}, _defaultConfig), { cloudProjectName: projectName, cloudProjectOwner: projectOwner })), localConfig = _g[0], setLocalConfig = _g[1];
44810
+ /**
44811
+ * Warning for local study folder
44812
+ */
44813
+ var localStudyWarning = useMemo(function () {
44814
+ if (host === 'web' || !localConfig.isLocalJob
44815
+ || !localConfig.localRunFolder || !watchStudyName)
44816
+ return;
44817
+ var jobs = getJob("".concat(projectOwner, "/").concat(projectName));
44818
+ var studyName = watchStudyName
44819
+ .replace(/[^a-zA-Z0-9]/g, '')
44820
+ .replace(/[ ()]/g, '');
44821
+ var folderCheck = "".concat(localConfig.localRunFolder, "\\").concat(studyName);
44822
+ var status = jobs
44823
+ .filter(function (j) { return j.studyId === folderCheck; }).length !== 0;
44824
+ return status;
44825
+ }, [localConfig, watchStudyName]);
44826
+ useEffect(function () {
44827
+ if (!localStudyWarning)
44828
+ return;
44829
+ n$1("Study with the same name and Local run folder detected. \n If the study will be submitted it will override the previous data. \n You can change the study name or Local run folder to avoid the loss of data.", {
44830
+ duration: 8000,
44831
+ position: 'top-center',
44832
+ icon: '⚠️',
44833
+ style: { fontSize: '14px' },
44834
+ iconTheme: {
44835
+ primary: '#000',
44836
+ secondary: '#fff',
44837
+ },
44838
+ ariaProps: {
44839
+ role: 'alert',
44840
+ 'aria-live': 'assertive',
44841
+ },
44842
+ });
44843
+ }, [localStudyWarning]);
44787
44844
  return React__default.createElement("form", { id: recipe.metadata.name, onSubmit: handleSubmit(_onSubmit, onErrors) },
44788
44845
  React__default.createElement("div", { className: 'cards-container-recipe', style: __assign(__assign({}, style), { padding: '20px' }) },
44789
44846
  React__default.createElement("div", { style: { margin: '0 0 20px 0' } },
@@ -44842,6 +44899,7 @@ var RecipeForm = function (_a) {
44842
44899
  React__default.createElement("div", { style: { margin: '10px 0 0 0' } },
44843
44900
  host !== 'web' &&
44844
44901
  React__default.createElement(ConfigureLocalRun, { onChange: function (localConfig) { return setLocalConfig(localConfig); }, defaultVal: localConfig }),
44902
+ React__default.createElement(Ie, null),
44845
44903
  React__default.createElement(Button, { type: 'submit', style: { width: '100%',
44846
44904
  margin: '10px 0 0 0',
44847
44905
  justifyContent: 'center' }, disabled: isValid !== true, form: recipe.metadata.name }, "Create Study")));
@@ -44858,11 +44916,38 @@ var CreateStudy = function (_a) {
44858
44916
  var _d = useState(0), activeTabIndex = _d[0], setActiveTabIndex = _d[1];
44859
44917
  var _e = useState(defaultAccount), selAccount = _e[0], setSelAccount = _e[1];
44860
44918
  var _f = useState(defaultProject), selProject = _f[0], setSelProject = _f[1];
44861
- var _g = useState(defaultRecipe), selRecipe = _g[0], setSelRecipe = _g[1];
44919
+ var _g = useState(), selRecipe = _g[0], setSelRecipe = _g[1];
44920
+ var _h = useState(defaultRecipe), selRecipeFilter = _h[0], setSelRecipeFilter = _h[1];
44921
+ useEffect(function () {
44922
+ if (!selRecipeFilter) {
44923
+ setSelRecipe(undefined);
44924
+ return;
44925
+ }
44926
+ // Remove tag from name
44927
+ var clearName = selRecipeFilter
44928
+ .name.replace(selRecipeFilter.tag, '')
44929
+ .slice(0, -1);
44930
+ // If * use latest
44931
+ var conditionalTag = selRecipeFilter.tag === '*'
44932
+ ? 'latest'
44933
+ : selRecipeFilter.tag;
44934
+ client.recipes.getRecipeByTag({
44935
+ owner: selRecipeFilter.owner,
44936
+ name: clearName,
44937
+ tag: conditionalTag
44938
+ })
44939
+ .then(function (d) {
44940
+ setSelRecipe(d.data.manifest);
44941
+ }).catch(function (err) {
44942
+ _t.error('Recipe not found. Try a new tag!', { duration: 2000, position: 'top-center', style: { minWidth: '300px', fontSize: '14px' }
44943
+ });
44944
+ setSelRecipe(undefined);
44945
+ });
44946
+ }, [selRecipeFilter]);
44862
44947
  // @ts-ignore
44863
44948
  var projectOwner = selAccount ? ((_b = selAccount.username) !== null && _b !== void 0 ? _b : selAccount.account_name) : undefined;
44864
44949
  var projectSlug = selProject ? selProject.slug.split('/')[1] : undefined;
44865
- var _h = useCreateStudy(projectOwner, projectSlug, client), host = _h.host, createStudy = _h.createStudy, createLocalStudy = _h.createLocalStudy;
44950
+ var _j = useCreateStudy(projectOwner, projectSlug, client), host = _j.host, createStudy = _j.createStudy, createLocalStudy = _j.createLocalStudy;
44866
44951
  useEffect(function () {
44867
44952
  if (!selRecipe)
44868
44953
  return;
@@ -44880,7 +44965,7 @@ var CreateStudy = function (_a) {
44880
44965
  onSuccess(projectJobInfo, true);
44881
44966
  }
44882
44967
  else {
44883
- _t.success('Study submitted!', { duration: 4000, position: 'bottom-left', style: { minWidth: '300px', fontSize: '12px' }
44968
+ _t.success('Study submitted!', { duration: 4000, position: 'bottom-left', style: { minWidth: '300px', fontSize: '14px' }
44884
44969
  });
44885
44970
  setTimeout(function () {
44886
44971
  window.location.href = "".concat(basePath, "/").concat(projectJobInfo.accountName, "/projects/").concat(projectJobInfo.projectName, "/studies/").concat(projectJobInfo.studyId, "?tab=details&perPage=5&status=null&page=1");
@@ -44916,6 +45001,7 @@ var CreateStudy = function (_a) {
44916
45001
  name: name,
44917
45002
  recipe: selRecipe,
44918
45003
  description: description !== null && description !== void 0 ? description : 'Study created from pollination',
45004
+ recipeFilter: selRecipeFilter
44919
45005
  }, jobArgs, localConfig, localConfig.isLocalJob ? _onSuccessLocal : _onSuccessCloud);
44920
45006
  }
44921
45007
  else {
@@ -44954,7 +45040,8 @@ var CreateStudy = function (_a) {
44954
45040
  React__default.createElement(SelectProject, { authUser: authUser, client: client, onChange: setSelProject, projectOwner: projectOwner, value: selProject })),
44955
45041
  React__default.createElement(Label, { label: selRecipe && selRecipe.metadata ?
44956
45042
  selRecipe.metadata.name : 'Recipe' },
44957
- React__default.createElement(SelectRecipe, { authUser: authUser, client: client, projectOwner: projectOwner, projectName: selProject ? selProject.name : undefined, onChange: setSelRecipe, value: selRecipe })))),
45043
+ React__default.createElement(SelectRecipe, { authUser: authUser, client: client, projectOwner: projectOwner, projectName: selProject ? selProject.name : undefined, onChange: setSelRecipeFilter, value: selRecipeFilter }),
45044
+ React__default.createElement(Ie, null)))),
44958
45045
  selRecipe &&
44959
45046
  React__default.createElement(React__default.Fragment, null,
44960
45047
  React__default.createElement(TabPanel, { style: {