Refactor installed plugin props passing

Summary:
Left this out from diff at the bottom of the stack to
keep it a bit smaller.

Reviewed By: jknoxville

Differential Revision: D18272165

fbshipit-source-id: a2b0826e268b737341e2ef1c0f96dde32491237f
This commit is contained in:
Pascal Hartig
2019-11-05 05:27:38 -08:00
committed by Facebook Github Bot
parent d2dfb924fd
commit 9bb0dad5d6

View File

@@ -126,8 +126,7 @@ const PluginInstaller = function props(props: Props) {
query,
setQuery,
props.searchIndexFactory,
// TODO(T56693735): Refactor this to directly take props.
async () => props.installedPlugins,
props.installedPlugins,
props.refreshInstalledPlugins,
);
const restartApp = useCallback(() => {
@@ -294,28 +293,17 @@ function useNPMSearch(
query: string,
setQuery: (query: string) => void,
searchClientFactory: () => algoliasearch.Index,
getInstalledPlugins: () => Promise<Map<string, PluginDefinition>>,
installedPlugins: Map<string, PluginDefinition>,
refreshInstalledPlugins: () => void,
): TableRows_immutable {
const index = useMemo(searchClientFactory, []);
const [installedPlugins, setInstalledPlugins] = useState(
new Map<string, PluginDefinition>(),
);
const getAndSetInstalledPlugins = () =>
reportPlatformFailures(
getInstalledPlugins(),
`${TAG}:getInstalledPlugins`,
).then(setInstalledPlugins);
useEffect(() => {
reportUsage(`${TAG}:open`);
getAndSetInstalledPlugins();
}, []);
const onInstall = useCallback(async () => {
refreshInstalledPlugins();
getAndSetInstalledPlugins();
setRestartRequired(true);
}, []);