Merge pull request #2778 from github/robertbrignull/MethodRow_stories

Provide stories for all states of MethodRow
This commit is contained in:
Robert
2023-09-04 15:42:59 +01:00
committed by GitHub
2 changed files with 89 additions and 49 deletions

View File

@@ -3,7 +3,10 @@ import * as React from "react";
import { Meta, StoryFn } from "@storybook/react";
import { MethodRow as MethodRowComponent } from "../../view/model-editor/MethodRow";
import { CallClassification } from "../../model-editor/method";
import { CallClassification, Method } from "../../model-editor/method";
import { ModeledMethod } from "../../model-editor/modeled-method";
import { VSCodeDataGrid } from "@vscode/webview-ui-toolkit/react";
import { GRID_TEMPLATE_COLUMNS } from "../../view/model-editor/ModeledMethodDataGrid";
export default {
title: "CodeQL Model Editor/Method Row",
@@ -11,55 +14,90 @@ export default {
} as Meta<typeof MethodRowComponent>;
const Template: StoryFn<typeof MethodRowComponent> = (args) => (
<MethodRowComponent {...args} />
<VSCodeDataGrid gridTemplateColumns={GRID_TEMPLATE_COLUMNS}>
<MethodRowComponent {...args} />
</VSCodeDataGrid>
);
export const MethodRow = Template.bind({});
MethodRow.args = {
method: {
library: "sql2o-1.6.0.jar",
signature: "org.sql2o.Sql2o#open()",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "open",
methodParameters: "()",
supported: true,
supportedType: "summary",
usages: [
{
label: "open(...)",
url: {
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
startLine: 14,
startColumn: 24,
endLine: 14,
endColumn: 35,
},
classification: CallClassification.Source,
const method: Method = {
library: "sql2o-1.6.0.jar",
signature: "org.sql2o.Sql2o#open()",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "open",
methodParameters: "()",
supported: false,
supportedType: "summary",
usages: [
{
label: "open(...)",
url: {
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
startLine: 14,
startColumn: 24,
endLine: 14,
endColumn: 35,
},
{
label: "open(...)",
url: {
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
startLine: 25,
startColumn: 24,
endLine: 25,
endColumn: 35,
},
classification: CallClassification.Source,
classification: CallClassification.Source,
},
{
label: "open(...)",
url: {
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
startLine: 25,
startColumn: 24,
endLine: 25,
endColumn: 35,
},
],
},
modeledMethod: {
type: "summary",
input: "Argument[this]",
output: "ReturnValue",
kind: "taint",
provenance: "manual",
signature: "org.sql2o.Sql2o#open()",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "open",
methodParameters: "()",
},
classification: CallClassification.Source,
},
],
};
const modeledMethod: ModeledMethod = {
type: "summary",
input: "Argument[this]",
output: "ReturnValue",
kind: "taint",
provenance: "manual",
signature: "org.sql2o.Sql2o#open()",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "open",
methodParameters: "()",
};
export const Unmodeled = Template.bind({});
Unmodeled.args = {
method,
modeledMethod: undefined,
};
export const Source = Template.bind({});
Source.args = {
method,
modeledMethod: { ...modeledMethod, type: "source" },
};
export const Sink = Template.bind({});
Sink.args = {
method,
modeledMethod: { ...modeledMethod, type: "sink" },
};
export const Summary = Template.bind({});
Summary.args = {
method,
modeledMethod: { ...modeledMethod, type: "summary" },
};
export const Neutral = Template.bind({});
Neutral.args = {
method,
modeledMethod: { ...modeledMethod, type: "neutral" },
};
export const AlreadyModeled = Template.bind({});
AlreadyModeled.args = {
method: { ...method, supported: true },
modeledMethod: undefined,
};

View File

@@ -12,6 +12,8 @@ import { Mode } from "../../model-editor/shared/mode";
import { sortMethods } from "../../model-editor/shared/sorting";
import { InProgressMethods } from "../../model-editor/shared/in-progress-methods";
export const GRID_TEMPLATE_COLUMNS = "0.5fr 0.125fr 0.125fr 0.125fr 0.125fr";
type Props = {
packageName: string;
methods: Method[];
@@ -36,7 +38,7 @@ export const ModeledMethodDataGrid = ({
const sortedMethods = useMemo(() => sortMethods(methods), [methods]);
return (
<VSCodeDataGrid gridTemplateColumns="0.5fr 0.125fr 0.125fr 0.125fr 0.125fr">
<VSCodeDataGrid gridTemplateColumns={GRID_TEMPLATE_COLUMNS}>
<VSCodeDataGridRow rowType="header">
<VSCodeDataGridCell cellType="columnheader" gridColumn={1}>
API or method