Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from "react";
import { useState } from "react";

import { Meta } from "@storybook/react";

import { RepositoriesResultFormat as RepositoriesResultFormatComponent } from "../../view/variant-analysis/RepositoriesResultFormat";
import { ResultFormat } from "../../variant-analysis/shared/variant-analysis-result-format";

export default {
title: "Variant Analysis/Repositories Result Format",
component: RepositoriesResultFormatComponent,
argTypes: {
value: {
control: {
disable: true,
},
},
},
} as Meta<typeof RepositoriesResultFormatComponent>;

export const RepositoriesResultFormat = () => {
const [value, setValue] = useState(ResultFormat.Alerts);

return (
<RepositoriesResultFormatComponent value={value} onChange={setValue} />
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum ResultFormat {
Alerts = "Alerts",
RawResults = "Raw results",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from "react";
import { useCallback } from "react";
import { styled } from "styled-components";
import { VSCodeDropdown, VSCodeOption } from "@vscode/webview-ui-toolkit/react";
import { Codicon } from "../common";
import { ResultFormat } from "../../variant-analysis/shared/variant-analysis-result-format";

const Dropdown = styled(VSCodeDropdown)`
width: 100%;
`;

type Props = {
value: ResultFormat;
onChange: (value: ResultFormat) => void;

className?: string;
};

export const RepositoriesResultFormat = ({
value,
onChange,
className,
}: Props) => {
const handleInput = useCallback(
(e: InputEvent) => {
const target = e.target as HTMLSelectElement;

onChange(target.value as ResultFormat);
},
[onChange],
);

return (
<Dropdown value={value} onInput={handleInput} className={className}>
<Codicon name="table" label="Result format..." slot="indicator" />
<VSCodeOption value={ResultFormat.Alerts}>Alerts</VSCodeOption>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use the enum values here too since they have the same text as we want.

Suggested change
<VSCodeOption value={ResultFormat.Alerts}>Alerts</VSCodeOption>
<VSCodeOption value={ResultFormat.Alerts}>{ResultFormat.Alerts}</VSCodeOption>

BTW, I don't remember using string enum values with spaces in them 🤔 I've looked in our repo and it doesn't look like we're following any kind of convention though (some are capital case, some lower case, some camel case, some pascal case, and in some rare occasions we have spaces 😓 ).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! And yeah, it looks like we're pretty inconsistent with enums 🙈

<VSCodeOption value={ResultFormat.RawResults}>Raw results</VSCodeOption>
</Dropdown>
);
};