Files
flipper/desktop/plugins/navigation/hooks/requiredParameters.tsx
Michel Weststrate 273b895e30 Support auto completion on discovered bookmarks and filling out params
Summary:
This diff adds support for finding appPatterns (not sure how the feature is called) in the device, and auto completing on it.

Also improved the styling of bookmark sections.

This diff also adds support of showing a dialog in which params an be filled out if needed.

The behavior around optional arguments seems buggy, as in, no dialog will show up, but since I didn't want to change the logic around this unilaterally, left it as-is for now.

Updated the dialog to Ant so that the renderReactRoot utility could be used safely

Reviewed By: cekkaewnumchai

Differential Revision: D24889855

fbshipit-source-id: 6af264abec2e9e5b921ef7da6deb1d0021615e9e
2020-11-12 04:17:29 -08:00

35 lines
901 B
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {useMemo, useState} from 'react';
import {validateParameter} from '../util/uri';
export const useRequiredParameterFormValidator = (
requiredParameters: Array<string>,
) => {
const [values, setValuesArray] = useState<Array<string>>(
requiredParameters.map(() => ''),
);
const isValid = useMemo(() => {
if (requiredParameters.length != values.length) {
setValuesArray(requiredParameters.map(() => ''));
}
if (
values.every((value, idx) =>
validateParameter(value, requiredParameters[idx]),
)
) {
return true;
} else {
return false;
}
}, [requiredParameters, values]);
return {isValid, values, setValuesArray};
};