mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix pick paths import type error and simplify signature
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
bae2aa0884
commit
a81873fe52
@ -4,18 +4,21 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { FileFilter } from "electron";
|
import type { FileFilter } from "electron";
|
||||||
import { requestOpenFilePickingDialog } from "../../../../../../../renderer/ipc";
|
import openPathPickingDialogInjectable from "../../../../../../path-picking-dialog/renderer/pick-paths.injectable";
|
||||||
|
|
||||||
const getFilePathsInjectable = getInjectable({
|
const getFilePathsInjectable = getInjectable({
|
||||||
id: "get-file-paths",
|
id: "get-file-paths",
|
||||||
|
|
||||||
instantiate: () => async (fileFilter: FileFilter) =>
|
instantiate: (di) => {
|
||||||
await requestOpenFilePickingDialog({
|
const openPathPickingDialog = di.inject(openPathPickingDialogInjectable);
|
||||||
|
|
||||||
|
return async (fileFilter: FileFilter) => await openPathPickingDialog({
|
||||||
properties: ["openFile", "showHiddenFiles"],
|
properties: ["openFile", "showHiddenFiles"],
|
||||||
message: `Select file`,
|
message: "Select file",
|
||||||
buttonLabel: `Use file`,
|
buttonLabel: "Use file",
|
||||||
filters: [fileFilter, { name: "Any", extensions: ["*"] }],
|
filters: [fileFilter, { name: "Any", extensions: ["*"] }],
|
||||||
}),
|
});
|
||||||
|
},
|
||||||
|
|
||||||
causesSideEffects: true,
|
causesSideEffects: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -15,11 +15,8 @@ const openPathPickingDialogInjectable = getInjectable({
|
|||||||
const requestFromChannel = di.inject(requestFromChannelInjectable);
|
const requestFromChannel = di.inject(requestFromChannelInjectable);
|
||||||
|
|
||||||
return async (options) => {
|
return async (options) => {
|
||||||
const { onPick, onCancel, label, ...dialogOptions } = options;
|
const { onPick, onCancel, ...dialogOptions } = options;
|
||||||
const response = await requestFromChannel(openPathPickingDialogChannel, {
|
const response = await requestFromChannel(openPathPickingDialogChannel, dialogOptions);
|
||||||
message: label,
|
|
||||||
...dialogOptions,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.canceled) {
|
if (response.canceled) {
|
||||||
await onCancel?.();
|
await onCancel?.();
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import { cssNames } from "../../utils";
|
|||||||
import { Button } from "../button";
|
import { Button } from "../button";
|
||||||
|
|
||||||
export interface PathPickOpts {
|
export interface PathPickOpts {
|
||||||
label: string;
|
message: string;
|
||||||
onPick?: (paths: string[]) => any;
|
onPick?: (paths: string[]) => any;
|
||||||
onCancel?: () => any;
|
onCancel?: () => any;
|
||||||
defaultPath?: string;
|
defaultPath?: string;
|
||||||
@ -35,7 +35,6 @@ interface Dependencies {
|
|||||||
const NonInjectedPathPicker = observer((props: PathPickerProps & Dependencies) => {
|
const NonInjectedPathPicker = observer((props: PathPickerProps & Dependencies) => {
|
||||||
const {
|
const {
|
||||||
className,
|
className,
|
||||||
label,
|
|
||||||
disabled,
|
disabled,
|
||||||
openPathPickingDialog,
|
openPathPickingDialog,
|
||||||
...pickOpts
|
...pickOpts
|
||||||
@ -44,13 +43,10 @@ const NonInjectedPathPicker = observer((props: PathPickerProps & Dependencies) =
|
|||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
primary
|
primary
|
||||||
label={label}
|
label={pickOpts.message}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
className={cssNames("PathPicker", className)}
|
className={cssNames("PathPicker", className)}
|
||||||
onClick={() => void openPathPickingDialog({
|
onClick={() => void openPathPickingDialog(pickOpts)}
|
||||||
label,
|
|
||||||
...pickOpts,
|
|
||||||
})}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user