Skip to content

Commit

Permalink
chore(robot): merge with latest change
Browse files Browse the repository at this point in the history
  • Loading branch information
LatentDream committed Apr 25, 2024
2 parents 8cd66e9 + 5ad968d commit d049f1f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 49 deletions.
21 changes: 4 additions & 17 deletions src/renderer/hooks/useTestImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const useDiscoverAndImportTests = () => {
return openFilePicker;
};

export async function useDiscoverElements() {
export const useDiscoverElements = () => {
const handleUserDepInstall = useCallback(async (depName: string) => {
const promise = () => window.api.poetryInstallDepUserGroup(depName);
toast.promise(promise, {
Expand All @@ -157,9 +157,7 @@ export async function useDiscoverElements() {
});
}, []);

async function getTests(
path: string,
): Promise<Result<TestSequenceElement[], Error>> {
async function getTests(path: string) {
let res: Result<TestDiscoverContainer, Error>;
let type: DiscoverableTestTypes;
if (path.endsWith(".robot")) {
Expand Down Expand Up @@ -197,16 +195,5 @@ export async function useDiscoverElements() {
return ok(newElems);
}

const openFilePicker = (): Promise<Result<TestSequenceElement[], Error>> => {
return window.api.openTestPicker().then((result) => {
if (!result) return err(Error("No file selected."));
const { filePath } = result;
return getTests(filePath);
});
// Return a function that takes the file path as an argument
// return async (filePath: string) => {
// const result = await getTests(filePath);
// return result;
};
return openFilePicker;
}
return getTests;
};
2 changes: 1 addition & 1 deletion src/renderer/hooks/useTestSequencerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function createNewTest(test: NewTest): Test {
completionTime: undefined,
error: null,
isSavedToCloud: false,
exportToCloud: test.exportToCloud || true,
exportToCloud: test.exportToCloud === undefined ? true : test.exportToCloud,
createdAt: new Date().toISOString(),
minValue: test.minValue,
maxValue: test.maxValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,33 @@ export const ChangeLinkedTestModal = ({
[],
);
const [selectedTestName, setSelectedPath] = useState<string>("");
const { openErrorModal } = useSequencerModalStore();

const { setIsDepManagerModalOpen } = useAppStore(
useShallow((state) => ({
setIsDepManagerModalOpen: state.setIsDepManagerModalOpen,
})),
);

const openFilePickerPromise = useDiscoverElements();
const discoverElement = useDiscoverElements();

const handleDiscoverElements = () => {
openFilePickerPromise
.then((useDiscover) => {
return useDiscover();
})
.then((potentialElementsResult) => {
potentialElementsResult.match(
(elements) => {
setAvailableTests(elements);
toast.info("Tests discovered successfully");
},
(error) => {
toast("Error while attempting to discover tests", {
action: {
label: "More details",
onClick: () => {
openErrorModal(error.message);
},
},
});
},
);
})
.catch((error) => {
// User cancelled the file picker
console.log(error);
});
const handleDiscoverElements = async (filePath: string) => {
const result = await discoverElement(filePath);
if (result.isOk()) {
setAvailableTests(result.value);
if (result.value.length > 0) {
setSelectedPath(result.value[0].path);
}
} else {
toast.error(`Failed to discover tests: ${result.error}`);
console.error(result.error);
}
};

const handleFilePicker = async () => {
const res = await window.api.openTestPicker();
if (!res) return;
if (res.filePath) {
await handleDiscoverElements(res.filePath);
}
};

const handleSubmitIndividualTest = () => {
Expand Down Expand Up @@ -105,6 +95,7 @@ export const ChangeLinkedTestModal = ({
});
};


return (
<Dialog open={isModalOpen} onOpenChange={setModalOpen}>
<DialogContent>
Expand Down Expand Up @@ -137,7 +128,7 @@ export const ChangeLinkedTestModal = ({
<Button
className="w-32"
variant={"outline"}
onClick={handleDiscoverElements}
onClick={handleFilePicker}
data-testid="discover-btn"
>
Discover
Expand Down

0 comments on commit d049f1f

Please sign in to comment.