pollination-react-io 1.26.1 → 1.27.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.
@@ -0,0 +1,2 @@
1
+ import type { EffectCallback, DependencyList } from "react";
2
+ export declare const useDebounce: (delay: number) => (effect: EffectCallback, deps?: DependencyList) => void;
@@ -40596,23 +40596,44 @@ var getFileIcon$1 = function (type, disabled) {
40596
40596
  }
40597
40597
  };
40598
40598
 
40599
+ // https://dev.to/rajeshroyal/how-to-make-a-custom-debounce-hook-in-react-js-4gcc
40600
+ var useDebounce = function (delay) { return function (effect, deps) {
40601
+ return useEffect(function () {
40602
+ var handler = setTimeout(effect, delay);
40603
+ return function () { return clearTimeout(handler); };
40604
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40605
+ }, __spreadArray(__spreadArray([], deps, true), [delay], false));
40606
+ }; };
40607
+
40608
+ var longDebounce$3 = useDebounce(500);
40609
+ var shortDebounce$3 = useDebounce(200);
40599
40610
  var SelectCloudArtifacts = function (_a) {
40600
40611
  var _b, _c;
40601
40612
  var projectOwner = _a.projectOwner, projectName = _a.projectName, jobId = _a.jobId, value = _a.value, hidden = _a.hidden, _d = _a.fileNameMatch, fileNameMatch = _d === void 0 ? '.*' : _d, onChange = _a.onChange, client = _a.client;
40602
40613
  var comboBoxRef = useRef(null);
40603
- var listArtifacts = useArtifacts(projectOwner, projectName, client).listArtifacts;
40604
40614
  var valueRef = useRef();
40615
+ var listArtifacts = useArtifacts(projectOwner, projectName, client).listArtifacts;
40605
40616
  var _e = useState(), selArtifact = _e[0], setSelArtifact = _e[1];
40606
40617
  var _f = useState(false), loading = _f[0], setLoading = _f[1];
40607
40618
  var _g = useState({ folders: [], files: [] }), artifacts = _g[0], setArtifacts = _g[1];
40608
- var _h = useState(value ?
40619
+ var _h = useState((value === null || value === void 0 ? void 0 : value.key) ?
40609
40620
  [value.key.split('/').slice(0, -1).join('/')]
40610
40621
  :
40611
40622
  []), path = _h[0], setPath = _h[1];
40612
40623
  var handleClear = useCallback(function () {
40613
40624
  setPath([]);
40614
40625
  }, []);
40626
+ // resetting query
40615
40627
  useEffect(function () {
40628
+ // deselect item
40629
+ if (comboBoxRef.current) {
40630
+ comboBoxRef.current.selectItem(null);
40631
+ }
40632
+ setArtifacts({ folders: [], files: [] });
40633
+ }, [projectOwner, projectName]);
40634
+ longDebounce$3(function () {
40635
+ if (!client || !client.projects)
40636
+ return;
40616
40637
  setLoading(true);
40617
40638
  listArtifacts(path, jobId)
40618
40639
  .then(function (facts) {
@@ -40630,8 +40651,7 @@ var SelectCloudArtifacts = function (_a) {
40630
40651
  return newPath;
40631
40652
  });
40632
40653
  }, [selArtifact]);
40633
- useEffect(function () {
40634
- // nonmemoized value from react-hook-form or other parent causes infinite rerendering
40654
+ shortDebounce$3(function () {
40635
40655
  if (lodash_isequal(valueRef.current, selArtifact) ||
40636
40656
  (!valueRef.current && !selArtifact)) {
40637
40657
  return;
@@ -40642,11 +40662,8 @@ var SelectCloudArtifacts = function (_a) {
40642
40662
  comboBoxRef.current.selectItem(selArtifact);
40643
40663
  valueRef.current = selArtifact;
40644
40664
  // don't call onChange for undefined values
40645
- onChange && selArtifact && onChange(selArtifact);
40665
+ onChange && onChange(selArtifact);
40646
40666
  }, [onChange, selArtifact]);
40647
- useEffect(function () {
40648
- setSelArtifact(value);
40649
- }, [value]);
40650
40667
  var stateReducer = useCallback(function (state, actionAndChanges) {
40651
40668
  var type = actionAndChanges.type, changes = actionAndChanges.changes;
40652
40669
  switch (type) {
@@ -40790,9 +40807,8 @@ var ComboFileSelector = function (_a) {
40790
40807
  var projectOwner = _a.projectOwner, projectName = _a.projectName, value = _a.value, _b = _a.hidden, hidden = _b === void 0 ? false : _b, _c = _a.disabled, disabled = _c === void 0 ? false : _c, defaultOption = _a.defaultOption, optionsConfig = _a.optionsConfig, _d = _a.mode, mode = _d === void 0 ? 'cloud' : _d, onChange = _a.onChange, client = _a.client, inputProps = _a.inputProps;
40791
40808
  var host = getHost();
40792
40809
  var _e = useState(function () {
40793
- if (typeof defaultOption !== 'undefined') {
40794
- return defaultOption;
40795
- }
40810
+ if (defaultOption == null)
40811
+ return;
40796
40812
  if (host !== 'web') {
40797
40813
  if (mode !== 'cloud') {
40798
40814
  // plugin, local
@@ -40814,6 +40830,10 @@ var ComboFileSelector = function (_a) {
40814
40830
  var handleLocalArtifactSelect = useCallback(function (path) {
40815
40831
  onChange({ pollination_local_path: path });
40816
40832
  }, [onChange]);
40833
+ // reset onChange if option
40834
+ useEffect(function () {
40835
+ onChange();
40836
+ }, [option]);
40817
40837
  return (React__default.createElement("div", { "data-testid": "ComboFileSelector", style: {
40818
40838
  display: 'flex',
40819
40839
  flexDirection: 'column',
@@ -40821,7 +40841,7 @@ var ComboFileSelector = function (_a) {
40821
40841
  } },
40822
40842
  !hidden &&
40823
40843
  React__default.createElement(ButtonGroup, null,
40824
- (typeof optionsConfig['get_file'] === 'undefined' || optionsConfig['get_file']) &&
40844
+ mode === 'cloud' && (typeof optionsConfig['get_file'] === 'undefined' || optionsConfig['get_file']) &&
40825
40845
  React__default.createElement("button", { type: 'button', disabled: disabled, onClick: function () { return setOption('get_file'); }, style: {
40826
40846
  display: 'flex',
40827
40847
  boxShadow: !disabled && option === 'get_file' ?
@@ -41717,6 +41737,8 @@ TabPanel.tabsRole = 'TabPanel';
41717
41737
  TabPanel.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};
41718
41738
  TabPanel.defaultProps = defaultProps;
41719
41739
 
41740
+ var longDebounce$2 = useDebounce(500);
41741
+ var shortDebounce$2 = useDebounce(200);
41720
41742
  var SelectProject = function (_a) {
41721
41743
  var _b, _c;
41722
41744
  var authUser = _a.authUser, client = _a.client, projectOwner = _a.projectOwner, value = _a.value, onChange = _a.onChange;
@@ -41725,16 +41747,17 @@ var SelectProject = function (_a) {
41725
41747
  var _d = useState(), selProject = _d[0], setSelProject = _d[1];
41726
41748
  var _e = useState(false), loading = _e[0], setLoading = _e[1];
41727
41749
  var _f = useState([]), projects = _f[0], setProjects = _f[1];
41750
+ var _g = useState(1), pageNumber = _g[0], setPageNumber = _g[1];
41728
41751
  var totalProjectsRef = useRef({
41729
41752
  loaded: 0,
41730
41753
  total: undefined
41731
41754
  });
41732
- var _g = useState(0), total = _g[0], setTotal = _g[1];
41733
- var _h = useState({
41755
+ var _h = useState(0), total = _h[0], setTotal = _h[1];
41756
+ var projectApiRef = useRef({
41734
41757
  owner: (_b = [projectOwner]) !== null && _b !== void 0 ? _b : (authUser && [authUser.username]),
41735
- page: 1,
41758
+ page: pageNumber,
41736
41759
  perPage: 10,
41737
- }), queryConfig = _h[0], setQueryConfig = _h[1];
41760
+ });
41738
41761
  // resetting query
41739
41762
  useEffect(function () {
41740
41763
  // reset total loaded
@@ -41742,38 +41765,57 @@ var SelectProject = function (_a) {
41742
41765
  loaded: 0,
41743
41766
  total: undefined
41744
41767
  };
41745
- // deselect items
41768
+ // deselect item
41746
41769
  if (comboBoxRef.current) {
41747
- comboBoxRef.current.selectItem(value);
41770
+ comboBoxRef.current.selectItem(null);
41748
41771
  }
41749
41772
  setProjects([]);
41750
- setQueryConfig(function (q) { return (__assign(__assign({}, q), { owner: [projectOwner], page: 1 })); });
41751
- }, [projectOwner, value]);
41752
- var fetchProjects = useCallback(function (queryConfig) {
41773
+ setPageNumber(1);
41774
+ }, [projectOwner]);
41775
+ useEffect(function () {
41776
+ // select item
41777
+ if (comboBoxRef.current) {
41778
+ comboBoxRef.current.selectItem(value);
41779
+ }
41780
+ }, [value]);
41781
+ longDebounce$2(function () {
41782
+ var _a;
41783
+ projectApiRef.current = {
41784
+ owner: (_a = [projectOwner]) !== null && _a !== void 0 ? _a : (authUser && [authUser.username]),
41785
+ page: pageNumber,
41786
+ perPage: 10,
41787
+ };
41788
+ var queryConfig = projectApiRef.current;
41753
41789
  if (!authUser || !client || !client.projects)
41754
41790
  return;
41755
41791
  if (!queryConfig.owner)
41756
41792
  return;
41757
- var _a = totalProjectsRef.current, total = _a.total, loaded = _a.loaded;
41793
+ var _b = totalProjectsRef.current, total = _b.total, loaded = _b.loaded;
41758
41794
  if (total && loaded >= total)
41759
41795
  return;
41796
+ var fetchData = function () { return __awaiter$1(void 0, void 0, void 0, function () {
41797
+ var data;
41798
+ return __generator$1(this, function (_a) {
41799
+ switch (_a.label) {
41800
+ case 0: return [4 /*yield*/, client.projects.listProjects(queryConfig)];
41801
+ case 1:
41802
+ data = (_a.sent()).data;
41803
+ setProjects(function (state) { return state
41804
+ ? __spreadArray(__spreadArray([], state, true), data.resources, true) : __spreadArray([], data.resources, true); });
41805
+ setTotal(data.total_count);
41806
+ totalProjectsRef.current.loaded += data.resources.length;
41807
+ totalProjectsRef.current.total = data.total_count;
41808
+ return [2 /*return*/];
41809
+ }
41810
+ });
41811
+ }); };
41812
+ // call the function
41760
41813
  setLoading(true);
41761
- client.projects.listProjects(queryConfig)
41762
- .then(function (_a) {
41763
- var data = _a.data;
41764
- setProjects(function (state) { return state ? __spreadArray(__spreadArray([], state, true), data.resources, true) : __spreadArray([], data.resources, true); });
41765
- setTotal(data.total_count);
41766
- totalProjectsRef.current.loaded += data.resources.length;
41767
- totalProjectsRef.current.total = data.total_count;
41768
- })
41769
- .finally(function () {
41770
- setLoading(false);
41771
- });
41772
- }, [authUser, client]);
41773
- useEffect(function () {
41774
- fetchProjects(queryConfig);
41775
- }, [fetchProjects, queryConfig]);
41776
- useEffect(function () {
41814
+ fetchData()
41815
+ .catch(console.error)
41816
+ .finally(function () { return setLoading(false); });
41817
+ }, [authUser, client, projectOwner, pageNumber]);
41818
+ shortDebounce$2(function () {
41777
41819
  // nonmemoized value from react-hook-form or other parent causes infinite rerendering
41778
41820
  if (lodash_isequal(valueRef.current, selProject)) {
41779
41821
  return;
@@ -41784,28 +41826,27 @@ var SelectProject = function (_a) {
41784
41826
  comboBoxRef.current.selectItem(selProject);
41785
41827
  valueRef.current = selProject;
41786
41828
  // don't call onChange for undefined values
41787
- onChange && selProject && onChange(selProject);
41829
+ onChange && onChange(selProject);
41788
41830
  }, [selProject, onChange]);
41789
- useEffect(function () {
41790
- setSelProject(value);
41791
- }, [value]);
41792
41831
  var onScrollReachEnd = useCallback(function () {
41793
41832
  // already loaded all runs
41794
41833
  var _a = totalProjectsRef.current, total = _a.total, loaded = _a.loaded;
41795
41834
  if (total && loaded >= total)
41796
41835
  return;
41797
- setQueryConfig(function (q) { return (__assign(__assign({}, q), { page: q.page ? q.page + 1 : 1 })); });
41836
+ setPageNumber(projectApiRef.current.page + 1);
41798
41837
  }, []);
41799
- return (React__default.createElement(ComboBox, { ref: comboBoxRef, items: projects !== null && projects !== void 0 ? projects : [], setSelected: setSelProject, onClear: function () { return setSelProject(undefined); }, inputProps: {
41838
+ return (React__default.createElement(ComboBox, { ref: comboBoxRef, items: projects !== null && projects !== void 0 ? projects : [], setSelected: setSelProject, inputProps: {
41800
41839
  placeholder: 'Select a project...',
41801
- }, loading: loading, disabled: !authUser || !queryConfig.owner, footer: (React__default.createElement("div", { key: "footer", style: {
41840
+ }, loading: loading, disabled: !authUser || !projectOwner, footer: (React__default.createElement("div", { key: "footer", style: {
41802
41841
  width: '100%',
41803
41842
  display: 'flex',
41804
41843
  justifyContent: 'center',
41805
41844
  color: 'var(--grey4)',
41806
- } }, "Showing ".concat((_c = projects === null || projects === void 0 ? void 0 : projects.length) !== null && _c !== void 0 ? _c : 0, " of ").concat(total, " projects"))), onScrollReachEnd: onScrollReachEnd }));
41845
+ } }, "Showing ".concat((_c = projects.length) !== null && _c !== void 0 ? _c : 0, " of ").concat(total, " projects"))), onScrollReachEnd: onScrollReachEnd }));
41807
41846
  };
41808
41847
 
41848
+ var longDebounce$1 = useDebounce(500);
41849
+ var shortDebounce$1 = useDebounce(200);
41809
41850
  var SelectAccount = function (_a) {
41810
41851
  var _b;
41811
41852
  var authUser = _a.authUser, client = _a.client, value = _a.value, onChange = _a.onChange;
@@ -41814,28 +41855,42 @@ var SelectAccount = function (_a) {
41814
41855
  var _c = useState(value), selAccount = _c[0], setSelAccount = _c[1];
41815
41856
  var _d = useState(function () { return authUser ? [authUser] : []; }), accounts = _d[0], setAccounts = _d[1];
41816
41857
  var _e = useState(false), loading = _e[0], setLoading = _e[1];
41858
+ var _f = useState(1), pageNumber = _f[0], setPageNumber = _f[1];
41817
41859
  var totalAccountsRef = useRef({
41818
41860
  loaded: 0,
41819
41861
  total: undefined
41820
41862
  });
41821
- var _f = useState(0), total = _f[0], setTotal = _f[1];
41822
- var _g = useState({
41823
- page: 1,
41863
+ var _g = useState(0), total = _g[0], setTotal = _g[1];
41864
+ var accountsApiRef = useRef({
41865
+ page: pageNumber,
41824
41866
  perPage: 25,
41825
- }), queryConfig = _g[0], setQueryConfig = _g[1];
41826
- // resetting query
41867
+ });
41827
41868
  useEffect(function () {
41828
- if (authUser == null)
41829
- return;
41830
41869
  // reset total loaded
41831
41870
  totalAccountsRef.current = {
41832
41871
  loaded: 0,
41833
41872
  total: undefined
41834
41873
  };
41835
- setAccounts([authUser]);
41836
- setQueryConfig(function (q) { return (__assign(__assign({}, q), { member: [authUser === null || authUser === void 0 ? void 0 : authUser.username], page: 1 })); });
41837
- }, [authUser, onChange, value]);
41838
- var fetchOrganizations = useCallback(function (queryConfig) {
41874
+ // deselect items
41875
+ if (comboBoxRef.current) {
41876
+ comboBoxRef.current.selectItem(null);
41877
+ }
41878
+ setAccounts([]);
41879
+ setPageNumber(1);
41880
+ }, [authUser]);
41881
+ useEffect(function () {
41882
+ // select item
41883
+ if (comboBoxRef.current) {
41884
+ comboBoxRef.current.selectItem(value);
41885
+ }
41886
+ }, [value]);
41887
+ longDebounce$1(function () {
41888
+ accountsApiRef.current = {
41889
+ member: [authUser === null || authUser === void 0 ? void 0 : authUser.username],
41890
+ page: pageNumber,
41891
+ perPage: 25
41892
+ };
41893
+ var queryConfig = accountsApiRef.current;
41839
41894
  if (!authUser || !client || !client.orgs)
41840
41895
  return;
41841
41896
  if (!queryConfig.member)
@@ -41844,42 +41899,44 @@ var SelectAccount = function (_a) {
41844
41899
  // we've already loaded all accounts
41845
41900
  if (total && loaded >= total)
41846
41901
  return;
41902
+ var fetchData = function () { return __awaiter$1(void 0, void 0, void 0, function () {
41903
+ var data;
41904
+ return __generator$1(this, function (_a) {
41905
+ switch (_a.label) {
41906
+ case 0: return [4 /*yield*/, client.orgs.listOrgs(queryConfig)];
41907
+ case 1:
41908
+ data = (_a.sent()).data;
41909
+ setAccounts(function (state) { return state
41910
+ ? __spreadArray(__spreadArray([authUser], state, true), data.resources, true) : __spreadArray([authUser], data.resources, true); });
41911
+ setTotal(data.total_count);
41912
+ totalAccountsRef.current.loaded += data.resources.length;
41913
+ totalAccountsRef.current.total = data.total_count;
41914
+ return [2 /*return*/];
41915
+ }
41916
+ });
41917
+ }); };
41918
+ // call the function
41847
41919
  setLoading(true);
41848
- client.orgs.listOrgs(__assign(__assign({}, queryConfig), { member: [authUser.username] }))
41849
- .then(function (_a) {
41850
- var data = _a.data;
41851
- setAccounts(function (state) { return state ? __spreadArray(__spreadArray([], state, true), data.resources, true) : __spreadArray([], data.resources, true); });
41852
- setTotal(data.total_count);
41853
- totalAccountsRef.current.loaded += data.resources.length;
41854
- totalAccountsRef.current.total = data.total_count;
41855
- })
41856
- .finally(function () {
41857
- setLoading(false);
41858
- });
41859
- }, [authUser, client]);
41860
- useEffect(function () {
41861
- fetchOrganizations(queryConfig);
41862
- }, [fetchOrganizations, queryConfig]);
41863
- useEffect(function () {
41920
+ fetchData()
41921
+ .catch(console.error)
41922
+ .finally(function () { return setLoading(false); });
41923
+ }, [authUser, client, pageNumber, selAccount]);
41924
+ shortDebounce$1(function () {
41925
+ // nonmemoized value from react-hook-form or other parent causes infinite rerendering
41864
41926
  if (lodash_isequal(valueRef.current, selAccount)) {
41865
41927
  return;
41866
41928
  }
41867
- if (selAccount == null)
41868
- return;
41869
41929
  comboBoxRef.current.selectItem(selAccount);
41870
41930
  valueRef.current = selAccount;
41871
- // comboBoxRef.current.setInputValue( selAccount.name )
41931
+ // don't call onChange for undefined values
41872
41932
  onChange && onChange(selAccount);
41873
- }, [onChange, selAccount]);
41874
- useEffect(function () {
41875
- setSelAccount(value);
41876
- }, [value]);
41933
+ }, [selAccount, onChange]);
41877
41934
  var onScrollReachEnd = useCallback(function () {
41878
41935
  // already loaded all runs
41879
41936
  var _a = totalAccountsRef.current, total = _a.total, loaded = _a.loaded;
41880
41937
  if (total && loaded >= total)
41881
41938
  return;
41882
- setQueryConfig(function (q) { return (__assign(__assign({}, q), { page: q.page ? q.page + 1 : 1 })); });
41939
+ setPageNumber(accountsApiRef.current.page + 1);
41883
41940
  }, []);
41884
41941
  return (React__default.createElement(ComboBox, { ref: comboBoxRef,
41885
41942
  // @ts-ignore
@@ -41910,6 +41967,8 @@ var SelectAccount = function (_a) {
41910
41967
  } }, "Showing ".concat((_b = accounts === null || accounts === void 0 ? void 0 : accounts.length) !== null && _b !== void 0 ? _b : 0, " of ").concat(total + 1, " accounts."))), onScrollReachEnd: onScrollReachEnd }));
41911
41968
  };
41912
41969
 
41970
+ var longDebounce = useDebounce(500);
41971
+ var shortDebounce = useDebounce(200);
41913
41972
  var SelectRecipe = function (_a) {
41914
41973
  var _b, _c;
41915
41974
  var authUser = _a.authUser, client = _a.client, projectName = _a.projectName, projectOwner = _a.projectOwner, value = _a.value, onChange = _a.onChange;
@@ -41918,17 +41977,18 @@ var SelectRecipe = function (_a) {
41918
41977
  var _d = useState(), selRecipe = _d[0], setSelRecipe = _d[1];
41919
41978
  var _e = useState(false), loading = _e[0], setLoading = _e[1];
41920
41979
  var _f = useState(), recipes = _f[0], setRecipes = _f[1];
41980
+ var _g = useState(1), pageNumber = _g[0], setPageNumber = _g[1];
41921
41981
  var totalRecipesRef = useRef({
41922
41982
  loaded: 0,
41923
41983
  total: undefined
41924
41984
  });
41925
- var _g = useState(0), total = _g[0], setTotal = _g[1];
41926
- var _h = useState({
41985
+ var _h = useState(0), total = _h[0], setTotal = _h[1];
41986
+ var projectApiRef = useRef({
41927
41987
  owner: projectOwner !== null && projectOwner !== void 0 ? projectOwner : (authUser && authUser.username),
41928
41988
  name: projectName,
41929
- page: 1,
41989
+ page: pageNumber,
41930
41990
  perPage: 10,
41931
- }), queryConfig = _h[0], setQueryConfig = _h[1];
41991
+ });
41932
41992
  // resetting query
41933
41993
  useEffect(function () {
41934
41994
  // reset total loaded
@@ -41938,58 +41998,71 @@ var SelectRecipe = function (_a) {
41938
41998
  };
41939
41999
  // deselect items
41940
42000
  if (comboBoxRef.current) {
41941
- comboBoxRef.current.selectItem(value);
42001
+ comboBoxRef.current.selectItem(null);
41942
42002
  }
41943
42003
  setRecipes([]);
41944
- setQueryConfig(function (q) { return (__assign(__assign({}, q), { owner: projectOwner, name: projectName, page: 1 })); });
41945
- }, [projectOwner, projectName, value]);
41946
- var fetchRecipes = useCallback(function (queryConfig) {
42004
+ setPageNumber(1);
42005
+ }, [projectOwner, projectName]);
42006
+ useEffect(function () {
42007
+ // select item
42008
+ if (comboBoxRef.current) {
42009
+ comboBoxRef.current.selectItem(value);
42010
+ }
42011
+ }, [value]);
42012
+ longDebounce(function () {
42013
+ projectApiRef.current = {
42014
+ owner: projectOwner !== null && projectOwner !== void 0 ? projectOwner : (authUser && authUser.username),
42015
+ name: projectName,
42016
+ page: pageNumber,
42017
+ perPage: 10,
42018
+ };
42019
+ var queryConfig = projectApiRef.current;
41947
42020
  if (!authUser || !client || !client.projects)
41948
42021
  return;
41949
42022
  if (!queryConfig.owner || !queryConfig.name)
41950
42023
  return;
41951
- // we've already loaded all recipes
41952
42024
  var _a = totalRecipesRef.current, total = _a.total, loaded = _a.loaded;
41953
42025
  if (total && loaded >= total)
41954
42026
  return;
42027
+ var fetchData = function () { return __awaiter$1(void 0, void 0, void 0, function () {
42028
+ var data;
42029
+ return __generator$1(this, function (_a) {
42030
+ switch (_a.label) {
42031
+ case 0: return [4 /*yield*/, client.projects.getProjectRecipes(queryConfig)];
42032
+ case 1:
42033
+ data = (_a.sent()).data;
42034
+ setRecipes(function (state) { return state ? __spreadArray(__spreadArray([], state, true), data.resources, true) : __spreadArray([], data.resources, true); });
42035
+ setTotal(data.total_count);
42036
+ totalRecipesRef.current.loaded += data.resources.length;
42037
+ totalRecipesRef.current.total = data.total_count;
42038
+ return [2 /*return*/];
42039
+ }
42040
+ });
42041
+ }); };
42042
+ // call the function
41955
42043
  setLoading(true);
41956
- client.projects.getProjectRecipes(queryConfig)
41957
- .then(function (_a) {
41958
- var data = _a.data;
41959
- setRecipes(function (state) { return state ? __spreadArray(__spreadArray([], state, true), data.resources, true) : __spreadArray([], data.resources, true); });
41960
- setTotal(data.total_count);
41961
- totalRecipesRef.current.loaded += data.resources.length;
41962
- totalRecipesRef.current.total = data.total_count;
41963
- })
41964
- .finally(function () {
41965
- setLoading(false);
41966
- });
41967
- }, [authUser, client]);
41968
- useEffect(function () {
41969
- fetchRecipes(queryConfig);
41970
- }, [fetchRecipes, queryConfig]);
41971
- useEffect(function () {
42044
+ fetchData()
42045
+ .catch(console.error)
42046
+ .finally(function () { return setLoading(false); });
42047
+ }, [authUser, client, projectOwner, projectName, pageNumber]);
42048
+ shortDebounce(function () {
41972
42049
  // nonmemoized value from react-hook-form or other parent causes infinite rerendering
41973
42050
  if (lodash_isequal(valueRef.current, selRecipe)) {
41974
42051
  return;
41975
42052
  }
41976
- if (selRecipe == null)
41977
- return;
42053
+ // if (selRecipe == null) return
41978
42054
  if (selRecipe && selRecipe.metadata && selRecipe.metadata.name) {
41979
42055
  comboBoxRef.current.setInputValue(selRecipe.metadata.name);
41980
42056
  }
41981
42057
  comboBoxRef.current.selectItem(selRecipe);
41982
42058
  valueRef.current = selRecipe;
41983
- onChange && selRecipe && onChange(selRecipe);
42059
+ onChange && onChange(selRecipe);
41984
42060
  }, [selRecipe, onChange]);
41985
- useEffect(function () {
41986
- setSelRecipe(value);
41987
- }, [value]);
41988
42061
  var onScrollReachEnd = useCallback(function () {
41989
42062
  var _a = totalRecipesRef.current, total = _a.total, loaded = _a.loaded;
41990
42063
  if (total && loaded >= total)
41991
42064
  return;
41992
- setQueryConfig(function (q) { return (__assign(__assign({}, q), { page: q.page ? q.page + 1 : 1 })); });
42065
+ setPageNumber(projectApiRef.current.page + 1);
41993
42066
  }, []);
41994
42067
  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: {
41995
42068
  display: 'flex',
@@ -41998,7 +42071,7 @@ var SelectRecipe = function (_a) {
41998
42071
  }, id: "".concat(item.metadata.name, "-").concat(item.metadata.tag) },
41999
42072
  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: {
42000
42073
  placeholder: 'Select a recipe...',
42001
- }, loading: loading, disabled: !authUser || !queryConfig.name || !queryConfig.owner, footer: (React__default.createElement("div", { key: "footer", style: {
42074
+ }, loading: loading, disabled: !authUser || !projectName, footer: (React__default.createElement("div", { key: "footer", style: {
42002
42075
  width: '100%',
42003
42076
  display: 'flex',
42004
42077
  justifyContent: 'center',
@@ -44031,7 +44104,7 @@ var RecipeInputsForm = function (_a) {
44031
44104
  var _f = useForm({
44032
44105
  resolver: Oe(schema),
44033
44106
  mode: 'all',
44034
- }), control = _f.control, register = _f.register, handleSubmit = _f.handleSubmit, reset = _f.reset, resetField = _f.resetField, _g = _f.formState, errors = _g.errors, isValid = _g.isValid, isSubmitSuccessful = _g.isSubmitSuccessful;
44107
+ }), control = _f.control, register = _f.register, handleSubmit = _f.handleSubmit, reset = _f.reset, resetField = _f.resetField, formState = _f.formState, _g = _f.formState, errors = _g.errors, isValid = _g.isValid, isSubmitSuccessful = _g.isSubmitSuccessful;
44035
44108
  var _onSubmit = function (_data) {
44036
44109
  var data = __assign({}, _data);
44037
44110
  // strip study name
@@ -44053,19 +44126,22 @@ var RecipeInputsForm = function (_a) {
44053
44126
  setLoading(true);
44054
44127
  onSubmit(studyName, data, 'description', localConfig)
44055
44128
  .finally(function () {
44056
- // @ts-ignore
44057
- var defaults = recipe.inputs.map(function (input) {
44058
- var _a;
44059
- var _b;
44060
- return (_a = {}, _a[input.name] = (_b = input.default) !== null && _b !== void 0 ? _b : '', _a);
44061
- });
44062
- defaults.push({ 'study-name': '' });
44063
- // console.log(defaults)
44064
- reset();
44065
44129
  setLoading(false);
44066
44130
  });
44067
44131
  }
44068
44132
  };
44133
+ useEffect(function () {
44134
+ reset({
44135
+ 'study-name': ''
44136
+ }, { keepValues: false });
44137
+ }, [recipe]);
44138
+ useEffect(function () {
44139
+ if (formState.isSubmitSuccessful) {
44140
+ reset({
44141
+ 'study-name': ''
44142
+ }, { keepValues: false });
44143
+ }
44144
+ }, [formState, reset]);
44069
44145
  var groups = recipe.inputs.reduce(function (p, c) {
44070
44146
  if (c.required) {
44071
44147
  p[0].push(c);