mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix more type errors
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
1a4c1d8a68
commit
a6d1b7a3a4
@ -4,23 +4,29 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { FileFilter } from "electron";
|
||||
import type { PathPickOpts } from "../../../../../../../renderer/components/path-picker";
|
||||
import openPathPickingDialogInjectable from "../../../../../../path-picking-dialog/renderer/pick-paths.injectable";
|
||||
|
||||
const getFilePathsInjectable = getInjectable({
|
||||
id: "get-file-paths",
|
||||
export interface RequestFilePathOptions extends Pick<PathPickOpts, "onCancel" | "onPick"> {
|
||||
filter: FileFilter;
|
||||
}
|
||||
|
||||
instantiate: (di) => {
|
||||
export type RequestFilePaths = (options: RequestFilePathOptions) => Promise<void>;
|
||||
|
||||
const requestFilePathsInjectable = getInjectable({
|
||||
id: "request-file-paths",
|
||||
|
||||
instantiate: (di): RequestFilePaths => {
|
||||
const openPathPickingDialog = di.inject(openPathPickingDialogInjectable);
|
||||
|
||||
return async (fileFilter: FileFilter) => await openPathPickingDialog({
|
||||
return async ({ filter, ...opts }) => await openPathPickingDialog({
|
||||
properties: ["openFile", "showHiddenFiles"],
|
||||
message: "Select file",
|
||||
buttonLabel: "Use file",
|
||||
filters: [fileFilter, { name: "Any", extensions: ["*"] }],
|
||||
filters: [filter, { name: "Any", extensions: ["*"] }],
|
||||
...opts,
|
||||
});
|
||||
},
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default getFilePathsInjectable;
|
||||
export default requestFilePathsInjectable;
|
||||
|
||||
@ -7,8 +7,8 @@ import { Input } from "../../../../../../../renderer/components/input";
|
||||
import { Icon } from "../../../../../../../renderer/components/icon";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import React from "react";
|
||||
import getFilePathsInjectable from "./get-file-paths.injectable";
|
||||
import type { FileFilter } from "electron";
|
||||
import type { RequestFilePaths } from "./get-file-paths.injectable";
|
||||
import requestFilePathsInjectable from "./get-file-paths.injectable";
|
||||
import isPathInjectable from "../../../../../../../renderer/components/input/validators/is-path.injectable";
|
||||
|
||||
interface HelmFileInputProps {
|
||||
@ -20,7 +20,7 @@ interface HelmFileInputProps {
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
getFilePaths: (fileFilter: FileFilter) => Promise<{ canceled: boolean; filePaths: string[] }>;
|
||||
requestFilePaths: RequestFilePaths;
|
||||
isPath: InputValidator<true>;
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ const NonInjectedHelmFileInput = ({
|
||||
value,
|
||||
setValue,
|
||||
fileExtensions,
|
||||
getFilePaths,
|
||||
requestFilePaths,
|
||||
isPath,
|
||||
"data-testid": testId,
|
||||
}: Dependencies & HelmFileInputProps) => (
|
||||
@ -44,31 +44,26 @@ const NonInjectedHelmFileInput = ({
|
||||
/>
|
||||
<Icon
|
||||
material="folder"
|
||||
|
||||
onClick={async () => {
|
||||
const { canceled, filePaths } = await getFilePaths({
|
||||
onClick={() => void requestFilePaths({
|
||||
filter: {
|
||||
name: placeholder,
|
||||
extensions: fileExtensions,
|
||||
});
|
||||
|
||||
if (!canceled && filePaths.length) {
|
||||
setValue(filePaths[0]);
|
||||
}
|
||||
}}
|
||||
|
||||
},
|
||||
onPick: (filePaths) => {
|
||||
if (filePaths.length) {
|
||||
setValue(filePaths[0]);
|
||||
}
|
||||
},
|
||||
})}
|
||||
tooltip="Browse"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
export const HelmFileInput = withInjectables<Dependencies, HelmFileInputProps>(
|
||||
NonInjectedHelmFileInput,
|
||||
|
||||
{
|
||||
getProps: (di, props) => ({
|
||||
getFilePaths: di.inject(getFilePathsInjectable),
|
||||
isPath: di.inject(isPathInjectable),
|
||||
...props,
|
||||
}),
|
||||
},
|
||||
);
|
||||
export const HelmFileInput = withInjectables<Dependencies, HelmFileInputProps>(NonInjectedHelmFileInput, {
|
||||
getProps: (di, props) => ({
|
||||
...props,
|
||||
requestFilePaths: di.inject(requestFilePathsInjectable),
|
||||
isPath: di.inject(isPathInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
@ -41,7 +41,7 @@ const setupKubernetesClusterCatalogAddMenuListenerInjectable = getInjectable({
|
||||
title: "Sync kubeconfig folder(s)",
|
||||
defaultAction: true,
|
||||
onClick: () => openPathPickingDialog({
|
||||
label: "Sync folder(s)",
|
||||
message: "Sync folder(s)",
|
||||
buttonLabel: "Sync",
|
||||
properties: ["showHiddenFiles", "multiSelections", "openDirectory"],
|
||||
onPick: addSyncEntries,
|
||||
@ -51,7 +51,7 @@ const setupKubernetesClusterCatalogAddMenuListenerInjectable = getInjectable({
|
||||
icon: "note_add",
|
||||
title: "Sync kubeconfig file(s)",
|
||||
onClick: () => openPathPickingDialog({
|
||||
label: "Sync file(s)",
|
||||
message: "Sync file(s)",
|
||||
buttonLabel: "Sync",
|
||||
properties: ["showHiddenFiles", "multiSelections", "openFile"],
|
||||
onPick: addSyncEntries,
|
||||
@ -65,7 +65,7 @@ const setupKubernetesClusterCatalogAddMenuListenerInjectable = getInjectable({
|
||||
title: "Sync kubeconfig(s)",
|
||||
defaultAction: true,
|
||||
onClick: () => openPathPickingDialog({
|
||||
label: "Sync file(s)",
|
||||
message: "Sync file(s)",
|
||||
buttonLabel: "Sync",
|
||||
properties: ["showHiddenFiles", "multiSelections", "openFile", "openDirectory"],
|
||||
onPick: addSyncEntries,
|
||||
|
||||
@ -22,7 +22,6 @@ import apiManagerInjectable from "../common/k8s-api/api-manager/manager.injectab
|
||||
import { computed, runInAction } from "mobx";
|
||||
import requestAnimationFrameInjectable from "./components/animate/request-animation-frame.injectable";
|
||||
import getRandomIdInjectable from "../common/utils/get-random-id.injectable";
|
||||
import getFilePathsInjectable from "../features/helm-charts/child-features/preferences/renderer/adding-of-custom-helm-repository/helm-file-input/get-file-paths.injectable";
|
||||
import requestPublicHelmRepositoriesInjectable from "../features/helm-charts/child-features/preferences/renderer/adding-of-public-helm-repository/public-helm-repositories/request-public-helm-repositories.injectable";
|
||||
import platformInjectable from "../common/vars/platform.injectable";
|
||||
import startTopbarStateSyncInjectable from "./components/layout/top-bar/start-state-sync.injectable";
|
||||
@ -132,7 +131,6 @@ export const getDiForUnitTesting = (
|
||||
|
||||
overrideFunctionalInjectables(di, [
|
||||
broadcastMessageInjectable,
|
||||
getFilePathsInjectable,
|
||||
requestPublicHelmRepositoriesInjectable,
|
||||
]);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user