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:
1 parent
1a4c1d8a68
commit
a6d1b7a3a4
4 files changed
+37
-38
No files matched your search
+14
-8
@@ -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;
|
||||
+20
-25
@@ -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),
|
||||
}),
|
||||
});
|
||||
Reference in new issue
Block a user