-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby-admin): plugin search (#25903)
* Copy plugin search from www into admin * Move to Combobox search * Cleanup * TypeScript cleanup * add algolia types * Fix syntax
- Loading branch information
1 parent
85b7058
commit a5a206f
Showing
5 changed files
with
199 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* @jsx jsx */ | ||
import { jsx } from "strict-ui" | ||
import { Spinner } from "theme-ui" | ||
import { | ||
InstantSearch, | ||
Configure, | ||
RefinementList, | ||
ToggleRefinement, | ||
connectAutoComplete, | ||
} from "react-instantsearch-dom" | ||
import { | ||
Combobox, | ||
ComboboxInput, | ||
ComboboxPopover, | ||
ComboboxList, | ||
ComboboxOption, | ||
} from "gatsby-interface" | ||
import { useMutation } from "urql" | ||
|
||
const SearchCombobox: React.FC<{ | ||
onSelect: (value: string) => void | ||
}> = connectAutoComplete(({ hits, currentRefinement, refine, onSelect }) => ( | ||
<Combobox onSelect={onSelect}> | ||
<ComboboxInput | ||
sx={{ width: `20em` }} | ||
aria-labelledby="plugin-search-label" | ||
onChange={(e): void => refine(e.target.value)} | ||
value={currentRefinement} | ||
/> | ||
<ComboboxPopover> | ||
<ComboboxList aria-labelledby="plugin-search-label"> | ||
{hits.map(hit => ( | ||
<ComboboxOption | ||
key={hit.objectID} | ||
selected={false} | ||
value={hit.name} | ||
></ComboboxOption> | ||
))} | ||
</ComboboxList> | ||
</ComboboxPopover> | ||
</Combobox> | ||
)) | ||
|
||
// the search bar holds the Search component in the InstantSearch widget | ||
const PluginSearchInput: React.FC<{}> = () => { | ||
const [{ fetching }, installGatbyPlugin] = useMutation(` | ||
mutation installGatsbyPlugin($name: String!) { | ||
createNpmPackage(npmPackage: { | ||
name: $name, | ||
dependencyType: "production" | ||
}) { | ||
id | ||
name | ||
} | ||
createGatsbyPlugin(gatsbyPlugin: { | ||
name: $name | ||
}) { | ||
id | ||
name | ||
} | ||
} | ||
`) | ||
|
||
return ( | ||
<div> | ||
<InstantSearch | ||
apiKey="ae43b69014c017e05950a1cd4273f404" | ||
appId="OFCNCOG2CU" | ||
indexName="npm-search" | ||
> | ||
<div style={{ display: `none` }}> | ||
<Configure analyticsTags={[`gatsby-plugins`]} /> | ||
<RefinementList | ||
attribute="keywords" | ||
transformItems={(items: Array<any>): Array<any> => | ||
items.map(({ count, ...item }) => { | ||
return { | ||
...item, | ||
count: count || 0, | ||
} | ||
}) | ||
} | ||
defaultRefinement={[`gatsby-component`, `gatsby-plugin`]} | ||
/> | ||
<ToggleRefinement | ||
attribute="deprecated" | ||
value={false} | ||
label="No deprecated plugins" | ||
defaultRefinement={true} | ||
/> | ||
</div> | ||
{fetching ? ( | ||
<Spinner /> | ||
) : ( | ||
<SearchCombobox | ||
onSelect={(value): void => { | ||
installGatbyPlugin({ name: value }) | ||
}} | ||
/> | ||
)} | ||
</InstantSearch> | ||
</div> | ||
) | ||
} | ||
|
||
export default PluginSearchInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.