SearchForm.jsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. "use client";
  2. import React from "react";
  3. import { SEARCH_SCOPE } from "@/lib/frontend/search/urlState";
  4. import SearchQueryBox from "@/components/search/form/SearchQueryBox";
  5. import SearchScopeSelect from "@/components/search/form/SearchScopeSelect";
  6. import SearchLimitSelect from "@/components/search/form/SearchLimitSelect";
  7. import SearchSingleBranchCombobox from "@/components/search/form/SearchSingleBranchCombobox";
  8. import SearchMultiBranchPicker from "@/components/search/form/SearchMultiBranchPicker";
  9. export default function SearchForm({
  10. branch,
  11. qDraft,
  12. onQDraftChange,
  13. onSubmit,
  14. currentQuery,
  15. isSubmitting,
  16. isAdminDev,
  17. scope,
  18. onScopeChange,
  19. onSingleBranchChange,
  20. availableBranches,
  21. branchesStatus,
  22. selectedBranches,
  23. onToggleBranch,
  24. onClearAllBranches,
  25. limit,
  26. onLimitChange,
  27. }) {
  28. const canSearch = typeof qDraft === "string" && qDraft.trim().length > 0;
  29. return (
  30. <div className="space-y-4">
  31. <form
  32. onSubmit={(e) => {
  33. e.preventDefault();
  34. if (!canSearch) return;
  35. onSubmit();
  36. }}
  37. className="space-y-3"
  38. >
  39. <SearchQueryBox
  40. qDraft={qDraft}
  41. onQDraftChange={onQDraftChange}
  42. onSubmit={onSubmit}
  43. currentQuery={currentQuery}
  44. isSubmitting={isSubmitting}
  45. canSearch={canSearch}
  46. />
  47. <div className="flex flex-wrap items-center gap-2">
  48. {isAdminDev ? (
  49. <SearchScopeSelect
  50. branch={branch}
  51. scope={scope}
  52. onScopeChange={onScopeChange}
  53. isSubmitting={isSubmitting}
  54. />
  55. ) : null}
  56. {isAdminDev && scope === SEARCH_SCOPE.SINGLE ? (
  57. <SearchSingleBranchCombobox
  58. branch={branch}
  59. branchesStatus={branchesStatus}
  60. availableBranches={availableBranches}
  61. onSingleBranchChange={onSingleBranchChange}
  62. isSubmitting={isSubmitting}
  63. />
  64. ) : null}
  65. <SearchLimitSelect
  66. limit={limit}
  67. onLimitChange={onLimitChange}
  68. isSubmitting={isSubmitting}
  69. />
  70. </div>
  71. </form>
  72. {isAdminDev && scope === SEARCH_SCOPE.MULTI ? (
  73. <SearchMultiBranchPicker
  74. branchesStatus={branchesStatus}
  75. availableBranches={availableBranches}
  76. selectedBranches={selectedBranches}
  77. onToggleBranch={onToggleBranch}
  78. onClearAllBranches={onClearAllBranches}
  79. isSubmitting={isSubmitting}
  80. />
  81. ) : null}
  82. </div>
  83. );
  84. }