|
| 1 | +importtype{FC}from"react"; |
| 2 | +import{API}from"api/api"; |
| 3 | +importtype{Organization}from"api/typesGenerated"; |
| 4 | +import{ |
| 5 | +Filter, |
| 6 | +MenuSkeleton, |
| 7 | +SearchFieldSkeleton, |
| 8 | +typeuseFilter, |
| 9 | +}from"components/Filter/filter"; |
| 10 | +import{useFilterMenu}from"components/Filter/menu"; |
| 11 | +import{ |
| 12 | +SelectFilter, |
| 13 | +typeSelectFilterOption, |
| 14 | +}from"components/Filter/SelectFilter"; |
| 15 | +import{UserAvatar}from"components/UserAvatar/UserAvatar"; |
| 16 | + |
| 17 | +interfaceTemplatesFilterProps{ |
| 18 | +filter:ReturnType<typeofuseFilter>; |
| 19 | +} |
| 20 | + |
| 21 | +exportconstTemplatesFilter:FC<TemplatesFilterProps>=({ filter})=>{ |
| 22 | +constorganizationMenu=useFilterMenu({ |
| 23 | +onChange:(option)=> |
| 24 | +filter.update({ ...filter.values,organization:option?.value}), |
| 25 | +value:filter.values.organization, |
| 26 | +id:"organization", |
| 27 | +getSelectedOption:async()=>{ |
| 28 | +if(!filter.values.organization){ |
| 29 | +returnnull; |
| 30 | +} |
| 31 | + |
| 32 | +constorg=awaitAPI.getOrganization(filter.values.organization); |
| 33 | +returnorgOption(org); |
| 34 | +}, |
| 35 | +getOptions:async()=>{ |
| 36 | +constorgs=awaitAPI.getMyOrganizations(); |
| 37 | +returnorgs.map(orgOption); |
| 38 | +}, |
| 39 | +}); |
| 40 | + |
| 41 | +return( |
| 42 | +<Filter |
| 43 | +presets={[ |
| 44 | +{query:"",name:"All templates"}, |
| 45 | +{query:"deprecated:true",name:"Deprecated templates"}, |
| 46 | +]} |
| 47 | +// TODO: Add docs for this |
| 48 | +// learnMoreLink={docs("/templates#template-filtering")} |
| 49 | +isLoading={false} |
| 50 | +filter={filter} |
| 51 | +options={ |
| 52 | +<> |
| 53 | +<SelectFilter |
| 54 | +placeholder="All organizations" |
| 55 | +label="Select an organization" |
| 56 | +options={organizationMenu.searchOptions} |
| 57 | +selectedOption={organizationMenu.selectedOption??undefined} |
| 58 | +onSelect={organizationMenu.selectOption} |
| 59 | +/> |
| 60 | +</> |
| 61 | +} |
| 62 | +skeleton={ |
| 63 | +<> |
| 64 | +<SearchFieldSkeleton/> |
| 65 | +<MenuSkeleton/> |
| 66 | +</> |
| 67 | +} |
| 68 | +/> |
| 69 | +); |
| 70 | +}; |
| 71 | + |
| 72 | +constorgOption=(org:Organization):SelectFilterOption=>({ |
| 73 | +label:org.display_name||org.name, |
| 74 | +value:org.name, |
| 75 | +startIcon:( |
| 76 | +<UserAvatar |
| 77 | +key={org.id} |
| 78 | +size="xs" |
| 79 | +username={org.display_name} |
| 80 | +avatarURL={org.icon} |
| 81 | +/> |
| 82 | +), |
| 83 | +}); |