Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#557-table-edit-default-behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
FredLL-Avaiga authored Jul 17, 2024
2 parents 3023990 + cfd0d77 commit 7be7424
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
9 changes: 5 additions & 4 deletions frontend/taipy-gui/src/components/Taipy/FileSelector.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("FileSelector Component", () => {
it("displays the right info for string", async () => {
const { getByText } = render(<FileSelector label="toto" defaultLabel="titi" className="taipy-file-selector" />);
const elt = getByText("toto");
expect(elt.parentElement).toHaveClass("taipy-file-selector");
expect(elt.parentElement?.parentElement).toHaveClass("taipy-file-selector");
});
it("displays the default value", async () => {
const { getByText } = render(<FileSelector defaultLabel="titi" label={undefined as unknown as string} />);
Expand All @@ -44,6 +44,7 @@ describe("FileSelector Component", () => {
const { getByText } = render(<FileSelector label="val" active={false} />);
const elt = getByText("val");
expect(elt).toHaveClass("Mui-disabled");
expect(elt.parentElement?.parentElement?.querySelector("input")).toBeDisabled();
});
it("is enabled by default", async () => {
const { getByText } = render(<FileSelector label="val" />);
Expand All @@ -66,7 +67,7 @@ describe("FileSelector Component", () => {
</TaipyContext.Provider>,
);
const elt = getByText("FileSelector");
const inputElt = elt.parentElement?.querySelector("input");
const inputElt = elt.parentElement?.parentElement?.querySelector("input");
expect(inputElt).toBeInTheDocument();
inputElt && (await userEvent.upload(inputElt, file));
expect(dispatch).toHaveBeenCalledWith({
Expand All @@ -79,7 +80,7 @@ describe("FileSelector Component", () => {
const file = new File(["(⌐□_□)"], "chucknorris2.png", { type: "image/png" });
const { getByRole, getByText } = render(<FileSelector label="FileSelectorDrop" />);
const elt = getByRole("button");
const inputElt = elt.parentElement?.querySelector("input");
const inputElt = elt.parentElement?.parentElement?.querySelector("input");
expect(inputElt).toBeInTheDocument();
waitFor(() => getByText("Drop here to Upload"));
inputElt &&
Expand All @@ -95,7 +96,7 @@ describe("FileSelector Component", () => {
<FileSelector label="FileSelectorDrop" dropMessage="drop here those files" />,
);
const elt = getByRole("button");
const inputElt = elt.parentElement?.querySelector("input");
const inputElt = elt.parentElement?.parentElement?.querySelector("input");
expect(inputElt).toBeInTheDocument();
waitFor(() => getByText("drop here those files"));
inputElt &&
Expand Down
41 changes: 22 additions & 19 deletions frontend/taipy-gui/src/components/Taipy/FileSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,25 @@ const FileSelector = (props: FileSelectorProps) => {
onAction && dispatch(createSendActionNameAction(id, module, onAction));
notify &&
dispatch(
createAlertAction({ atype: "success", message: value, system: false, duration: 3000 }),
createAlertAction({ atype: "success", message: value, system: false, duration: 3000 })
);
},
(reason) => {
setUpload(false);
notify &&
dispatch(
createAlertAction({ atype: "error", message: reason, system: false, duration: 3000 }),
createAlertAction({ atype: "error", message: reason, system: false, duration: 3000 })
);
},
}
);
}
},
[state.id, id, onAction, notify, updateVarName, dispatch, module],
[state.id, id, onAction, notify, updateVarName, dispatch, module]
);

const handleChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => handleFiles(e.target.files, e),
[handleFiles],
[handleFiles]
);

const handleDrop = useCallback(
Expand All @@ -105,7 +105,7 @@ const FileSelector = (props: FileSelectorProps) => {
setDropSx(defaultSx);
handleFiles(e.dataTransfer?.files, e);
},
[handleFiles],
[handleFiles]
);

const handleDragLeave = useCallback(() => {
Expand All @@ -118,12 +118,12 @@ const FileSelector = (props: FileSelectorProps) => {
console.log(evt);
const target = evt.currentTarget as HTMLElement;
setDropSx((sx) =>
sx.minWidth === defaultSx.minWidth && target ? { minWidth: target.clientWidth + "px" } : sx,
sx.minWidth === defaultSx.minWidth && target ? { minWidth: target.clientWidth + "px" } : sx
);
setDropLabel(dropMessage);
handleDragOver(evt);
},
[dropMessage],
[dropMessage]
);

useEffect(() => {
Expand Down Expand Up @@ -153,19 +153,22 @@ const FileSelector = (props: FileSelectorProps) => {
accept={extensions}
multiple={multiple}
onChange={handleChange}
disabled={!active || upload}
/>
<Tooltip title={hover || ""}>
<Button
id={id}
component="span"
aria-label="upload"
variant="outlined"
disabled={!active || upload}
sx={dropSx}
ref={butRef}
>
<UploadFile /> {dropLabel || label || defaultLabel}
</Button>
<span>
<Button
id={id}
component="span"
aria-label="upload"
variant="outlined"
disabled={!active || upload}
sx={dropSx}
ref={butRef}
>
<UploadFile /> {dropLabel || label || defaultLabel}
</Button>
</span>
</Tooltip>
{upload ? <LinearProgress value={progress} /> : null}
</label>
Expand Down

0 comments on commit 7be7424

Please sign in to comment.