Skip to content

Commit

Permalink
Format file with biome
Browse files Browse the repository at this point in the history
  • Loading branch information
PintoGideon committed Feb 7, 2024
1 parent 6473ff2 commit 5090052
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/components/AddNode/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface GuidedConfigState {
export interface chooseConfigProps {
user?: IUserState;
handleFileUpload: (files: any[]) => void;
showAlert?: boolean;
}

export interface EditorState {
Expand Down
45 changes: 27 additions & 18 deletions src/components/CreateFeed/ChooseConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Flex,
FlexItem,
} from "@patternfly/react-core";
import { Steps, notification } from "antd";
import { Steps, notification, Alert } from "antd";
import TrashIcon from "@patternfly/react-icons/dist/esm/icons/trash-icon";
import UploadIcon from "@patternfly/react-icons/dist/esm/icons/upload-icon";
import SettingsIcon from "@patternfly/react-icons/dist/esm/icons/cogs-icon";
Expand All @@ -37,7 +37,11 @@ import { AddNodeContext } from "../AddNode/context";
import { Types as AddNodeTypes } from "../AddNode/types";
import { useTypedSelector } from "../../store/hooks";

const ChooseConfig = ({ handleFileUpload, user }: chooseConfigProps) => {
const ChooseConfig = ({
handleFileUpload,
user,
showAlert,
}: chooseConfigProps) => {
const { state, dispatch } = useContext(CreateFeedContext);
const { dispatch: nodeDispatch } = useContext(AddNodeContext);
const { state: addNodeState } = useContext(AddNodeContext);
Expand All @@ -54,11 +58,11 @@ const ChooseConfig = ({ handleFileUpload, user }: chooseConfigProps) => {
const handleClick = useCallback(
(event: React.MouseEvent, selectedPluginId = "") => {
const selectedCard =
selectedPluginId == "" ? event.currentTarget.id : selectedPluginId;
selectedPluginId === "" ? event.currentTarget.id : selectedPluginId;
setSelectedCard(selectedCard);
if (selectedCard == "swift_storage" || selectedCard == "fs_plugin") {
if (selectedCard === "swift_storage" || selectedCard === "fs_plugin") {
setRightDrawerExpand(true);
} else if (selectedCard == "local_select") {
} else if (selectedCard === "local_select") {
setShowDragAndDrop(true);
}
},
Expand Down Expand Up @@ -171,7 +175,7 @@ const ChooseConfig = ({ handleFileUpload, user }: chooseConfigProps) => {

const resetPlugin = () => {
notification.info({
message: `Plugin unselected`,
message: "Plugin unselected",
description: `${pluginMeta?.data.name} unselected`,
duration: 1,
});
Expand Down Expand Up @@ -222,7 +226,7 @@ const ChooseConfig = ({ handleFileUpload, user }: chooseConfigProps) => {
};

const panelContent =
selectedCard == "swift_storage" ? (
selectedCard === "swift_storage" ? (
<DrawerPanelContent
widths={{ default: "width_50" }}
className="drawer_panelContent"
Expand All @@ -232,7 +236,7 @@ const ChooseConfig = ({ handleFileUpload, user }: chooseConfigProps) => {
padding: "1em",
}}
>
<span tabIndex={isRightDrawerExpand ? 0 : -1}></span>
<span tabIndex={isRightDrawerExpand ? 0 : -1} />
<DrawerActions>
<Button
onClick={resetChRisFiles}
Expand All @@ -252,13 +256,11 @@ const ChooseConfig = ({ handleFileUpload, user }: chooseConfigProps) => {
padding: "1em",
}}
>
{user && user.username && (
<ChrisFileSelect username={user.username} />
)}
<Grid style={navigationButtonStyle}></Grid>
{user?.username && <ChrisFileSelect username={user.username} />}
<Grid style={navigationButtonStyle} />
</DrawerPanelBody>
</DrawerPanelContent>
) : selectedCard == "fs_plugin" ? (
) : selectedCard === "fs_plugin" ? (
<DrawerPanelContent
widths={{ default: "width_50" }}
className="drawer_panelContent"
Expand All @@ -268,7 +270,7 @@ const ChooseConfig = ({ handleFileUpload, user }: chooseConfigProps) => {
padding: "1em",
}}
>
<span tabIndex={isRightDrawerExpand ? 0 : -1}></span>
<span tabIndex={isRightDrawerExpand ? 0 : -1} />
<DrawerActions>
<Button
onClick={resetPlugin}
Expand Down Expand Up @@ -301,10 +303,10 @@ const ChooseConfig = ({ handleFileUpload, user }: chooseConfigProps) => {
{steps[currentStep].content}
</Grid>
<Grid style={navigationButtonStyle}>
{currentStep == 0 && (
{currentStep === 0 && (
<Button
onClick={() => nextStep()}
isDisabled={pluginMeta == undefined}
isDisabled={pluginMeta === undefined}
>
Next
</Button>
Expand Down Expand Up @@ -334,7 +336,7 @@ const ChooseConfig = ({ handleFileUpload, user }: chooseConfigProps) => {
}, [handleKeyDown]);

useEffect(() => {
if (localFiles.length == 0) {
if (localFiles.length === 0) {
setShowDragAndDrop(false);
}
}, [localFiles.length]);
Expand Down Expand Up @@ -379,7 +381,7 @@ const ChooseConfig = ({ handleFileUpload, user }: chooseConfigProps) => {
</Tooltip>
),
}}
></CardHeader>
/>
<CardTitle>
<SettingsIcon />
<br />
Expand Down Expand Up @@ -495,6 +497,13 @@ const ChooseConfig = ({ handleFileUpload, user }: chooseConfigProps) => {
</Grid>
</GridItem>
</Grid>
{showAlert && (
<Alert
type="warning"
closable
description="Please select a data source to create a feed"
/>
)}
</div>
</Flex>
</DrawerContent>
Expand Down
21 changes: 13 additions & 8 deletions src/components/CreateFeed/CreateFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default function CreateFeed() {
useContext(PipelineContext);

const user = useTypedSelector((state) => state.user);
const params = useTypedSelector((state) => state.plugin.parameters);
const { pluginMeta, selectedPluginFromMeta, dropdownInput, requiredInput } =
addNodeState;
const { wizardOpen, data, selectedConfig } = state;
Expand Down Expand Up @@ -74,7 +73,7 @@ export default function CreateFeed() {
status: "Creating Feed",
},
});
const username = user && user.username;
const username = user?.username;

const feed = await createFeed(
state.data,
Expand Down Expand Up @@ -168,11 +167,13 @@ export default function CreateFeed() {
[handleDispatch],
);

const allRequiredFieldsNotEmpty: boolean = selectedConfig.includes(
"fs_plugin",
)
? params?.required.length == Object.keys(requiredInput).length
: true;
const allRequiredFieldsNotEmpty: boolean =
selectedConfig.includes("fs_plugin") &&
Object.keys(requiredInput).length > 0
? true
: false;

const filesChoosen = data.chrisFiles.length > 0 || data.localFiles.length > 0;

const closeWizard = () => {
dispatch({
Expand Down Expand Up @@ -235,13 +236,17 @@ export default function CreateFeed() {
id={2}
name="Analysis Data Selection"
footer={{
isNextDisabled: allRequiredFieldsNotEmpty ? false : true,
isNextDisabled:
filesChoosen || allRequiredFieldsNotEmpty ? false : true,
}}
>
{withSelectionAlert(
<ChooseConfig
user={user}
handleFileUpload={handleChoseFilesClick}
showAlert={
filesChoosen || allRequiredFieldsNotEmpty ? false : true
}
/>,
)}
</WizardStep>
Expand Down
9 changes: 6 additions & 3 deletions tests/createFeed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from "path";
const SOME_FILE = path.join(__dirname, "..", "package-lock.json");

test("Can create a feed", async ({ page }) => {
test.slow();
await page.goto("feeds?type=private");

const animal = faker.animal.type();
Expand All @@ -17,14 +18,16 @@ test("Can create a feed", async ({ page }) => {
await page.getByPlaceholder("Use this field to describe").click();
await page.getByPlaceholder("Use this field to describe").fill(feedNote);
await page.getByRole("button", { name: "Next" }).click();
await page.getByText("Upload New Data").click();

// Check if the next button is disabled.
const nextButton = page.getByRole("button", { name: "Next" });
await expect(nextButton).toBeDisabled();
await page.getByText("Upload New Data").click();
const fileChooserPromise = page.waitForEvent("filechooser");
await page.getByText("Drag 'n' drop some files here").click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(SOME_FILE);

await page.getByRole("button", { name: "Next" }).click();
await nextButton.click();
await page.getByRole("button", { name: "Next", exact: true }).click();
await page.getByRole("button", { name: "Create Analysis" }).click();

Expand Down

0 comments on commit 5090052

Please sign in to comment.