mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix changes to InputValidator to resolve accidental breaking changes (#5403)
* Fix changes to InputValidator to resolve accidental breaking changes Signed-off-by: Sebastian Malton <sebastian@malton.name> * Show changes working by removing no longer required empty props objects Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix async validation errors not being displayed - And fix validation errors sometimes being displayed multiple times Signed-off-by: Sebastian Malton <sebastian@malton.name> * Simplify builders for validators - Replace the boolean type params on `function inputValidator` with a new builder `function inputValidatorWithRequiredProps` to make the code easier to read Signed-off-by: Sebastian Malton <sebastian@malton.name> * Introduce unionizing functions for input validators Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove RequiredProps type param Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
3d64425df2
commit
5420780ae0
6 files changed
+244
-98
No files matched your search
@@ -14,7 +14,6 @@ import { readFileNotify } from "../read-file-notify/read-file-notify";
|
||||
import type { InstallRequest } from "../attempt-install/install-request";
|
||||
import type { ExtensionInfo } from "../attempt-install-by-info.injectable";
|
||||
import type { ExtensionInstallationStateStore } from "../../../../extensions/extension-installation-state-store/extension-installation-state-store";
|
||||
import { AsyncInputValidationError } from "../../input/input_validators";
|
||||
|
||||
export type InstallFromInput = (input: string) => Promise<void>;
|
||||
|
||||
@@ -34,7 +33,7 @@ export const installFromInput = ({
|
||||
|
||||
try {
|
||||
// fixme: improve error messages for non-tar-file URLs
|
||||
if (InputValidators.isUrl.validate(input, {})) {
|
||||
if (InputValidators.isUrl.validate(input)) {
|
||||
// install via url
|
||||
disposer = extensionInstallationStateStore.startPreInstall();
|
||||
const { promise } = downloadFile({ url: input, timeout: 10 * 60 * 1000 });
|
||||
@@ -44,23 +43,19 @@ export const installFromInput = ({
|
||||
}
|
||||
|
||||
try {
|
||||
await InputValidators.isPath.validate(input, {});
|
||||
await InputValidators.isPath.validate(input);
|
||||
|
||||
// install from system path
|
||||
const fileName = path.basename(input);
|
||||
|
||||
return await attemptInstall({ fileName, dataP: readFileNotify(input) });
|
||||
} catch (error) {
|
||||
if (error instanceof AsyncInputValidationError) {
|
||||
const extNameCaptures = InputValidators.isExtensionNameInstallRegex.captures(input);
|
||||
const extNameCaptures = InputValidators.isExtensionNameInstallRegex.captures(input);
|
||||
|
||||
if (extNameCaptures) {
|
||||
const { name, version } = extNameCaptures;
|
||||
if (extNameCaptures) {
|
||||
const { name, version } = extNameCaptures;
|
||||
|
||||
return await attemptInstallByInfo({ name, version });
|
||||
}
|
||||
} else {
|
||||
throw error;
|
||||
return await attemptInstallByInfo({ name, version });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,9 @@ import { Input, InputValidators } from "../input";
|
||||
import { SubTitle } from "../layout/sub-title";
|
||||
import { TooltipPosition } from "../tooltip";
|
||||
import type { ExtensionInstallationStateStore } from "../../../extensions/extension-installation-state-store/extension-installation-state-store";
|
||||
import extensionInstallationStateStoreInjectable
|
||||
from "../../../extensions/extension-installation-state-store/extension-installation-state-store.injectable";
|
||||
import extensionInstallationStateStoreInjectable from "../../../extensions/extension-installation-state-store/extension-installation-state-store.injectable";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import { inputValidator } from "../input/input_validators";
|
||||
import { unionInputValidatorsAsync } from "../input/input_validators";
|
||||
|
||||
export interface InstallProps {
|
||||
installPath: string;
|
||||
@@ -30,18 +29,14 @@ interface Dependencies {
|
||||
extensionInstallationStateStore: ExtensionInstallationStateStore;
|
||||
}
|
||||
|
||||
const installInputValidators = [
|
||||
const installInputValidator = unionInputValidatorsAsync(
|
||||
{
|
||||
message: "Invalid URL, absolute path, or extension name",
|
||||
},
|
||||
InputValidators.isUrl,
|
||||
InputValidators.isPath,
|
||||
InputValidators.isExtensionNameInstall,
|
||||
];
|
||||
|
||||
const installInputValidator = inputValidator({
|
||||
message: "Invalid URL, absolute path, or extension name",
|
||||
validate: (value: string, props) => (
|
||||
installInputValidators.some(({ validate }) => validate(value, props))
|
||||
),
|
||||
});
|
||||
InputValidators.isPath,
|
||||
);
|
||||
|
||||
const NonInjectedInstall: React.FC<Dependencies & InstallProps> = ({
|
||||
installPath,
|
||||
|
||||
Reference in new issue
Block a user