Skip to content

Commit e9b459a

Browse files
Merge pull request #2778 from github/robertbrignull/MethodRow_stories
Provide stories for all states of MethodRow
2 parents 09077a0 + 5cf6786 commit e9b459a

File tree

2 files changed

+89
-49
lines changed

2 files changed

+89
-49
lines changed

extensions/ql-vscode/src/stories/model-editor/MethodRow.stories.tsx

Lines changed: 86 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,101 @@ import * as React from "react";
33
import { Meta, StoryFn } from "@storybook/react";
44

55
import { MethodRow as MethodRowComponent } from "../../view/model-editor/MethodRow";
6-
import { CallClassification } from "../../model-editor/method";
6+
import { CallClassification, Method } from "../../model-editor/method";
7+
import { ModeledMethod } from "../../model-editor/modeled-method";
8+
import { VSCodeDataGrid } from "@vscode/webview-ui-toolkit/react";
9+
import { GRID_TEMPLATE_COLUMNS } from "../../view/model-editor/ModeledMethodDataGrid";
710

811
export default {
912
title: "CodeQL Model Editor/Method Row",
1013
component: MethodRowComponent,
1114
} as Meta<typeof MethodRowComponent>;
1215

1316
const Template: StoryFn<typeof MethodRowComponent> = (args) => (
14-
<MethodRowComponent {...args} />
17+
<VSCodeDataGrid gridTemplateColumns={GRID_TEMPLATE_COLUMNS}>
18+
<MethodRowComponent {...args} />
19+
</VSCodeDataGrid>
1520
);
1621

17-
export const MethodRow = Template.bind({});
18-
MethodRow.args = {
19-
method: {
20-
library: "sql2o-1.6.0.jar",
21-
signature: "org.sql2o.Sql2o#open()",
22-
packageName: "org.sql2o",
23-
typeName: "Sql2o",
24-
methodName: "open",
25-
methodParameters: "()",
26-
supported: true,
27-
supportedType: "summary",
28-
usages: [
29-
{
30-
label: "open(...)",
31-
url: {
32-
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
33-
startLine: 14,
34-
startColumn: 24,
35-
endLine: 14,
36-
endColumn: 35,
37-
},
38-
classification: CallClassification.Source,
22+
const method: Method = {
23+
library: "sql2o-1.6.0.jar",
24+
signature: "org.sql2o.Sql2o#open()",
25+
packageName: "org.sql2o",
26+
typeName: "Sql2o",
27+
methodName: "open",
28+
methodParameters: "()",
29+
supported: false,
30+
supportedType: "summary",
31+
usages: [
32+
{
33+
label: "open(...)",
34+
url: {
35+
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
36+
startLine: 14,
37+
startColumn: 24,
38+
endLine: 14,
39+
endColumn: 35,
3940
},
40-
{
41-
label: "open(...)",
42-
url: {
43-
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
44-
startLine: 25,
45-
startColumn: 24,
46-
endLine: 25,
47-
endColumn: 35,
48-
},
49-
classification: CallClassification.Source,
41+
classification: CallClassification.Source,
42+
},
43+
{
44+
label: "open(...)",
45+
url: {
46+
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
47+
startLine: 25,
48+
startColumn: 24,
49+
endLine: 25,
50+
endColumn: 35,
5051
},
51-
],
52-
},
53-
modeledMethod: {
54-
type: "summary",
55-
input: "Argument[this]",
56-
output: "ReturnValue",
57-
kind: "taint",
58-
provenance: "manual",
59-
signature: "org.sql2o.Sql2o#open()",
60-
packageName: "org.sql2o",
61-
typeName: "Sql2o",
62-
methodName: "open",
63-
methodParameters: "()",
64-
},
52+
classification: CallClassification.Source,
53+
},
54+
],
55+
};
56+
const modeledMethod: ModeledMethod = {
57+
type: "summary",
58+
input: "Argument[this]",
59+
output: "ReturnValue",
60+
kind: "taint",
61+
provenance: "manual",
62+
signature: "org.sql2o.Sql2o#open()",
63+
packageName: "org.sql2o",
64+
typeName: "Sql2o",
65+
methodName: "open",
66+
methodParameters: "()",
67+
};
68+
69+
export const Unmodeled = Template.bind({});
70+
Unmodeled.args = {
71+
method,
72+
modeledMethod: undefined,
73+
};
74+
75+
export const Source = Template.bind({});
76+
Source.args = {
77+
method,
78+
modeledMethod: { ...modeledMethod, type: "source" },
79+
};
80+
81+
export const Sink = Template.bind({});
82+
Sink.args = {
83+
method,
84+
modeledMethod: { ...modeledMethod, type: "sink" },
85+
};
86+
87+
export const Summary = Template.bind({});
88+
Summary.args = {
89+
method,
90+
modeledMethod: { ...modeledMethod, type: "summary" },
91+
};
92+
93+
export const Neutral = Template.bind({});
94+
Neutral.args = {
95+
method,
96+
modeledMethod: { ...modeledMethod, type: "neutral" },
97+
};
98+
99+
export const AlreadyModeled = Template.bind({});
100+
AlreadyModeled.args = {
101+
method: { ...method, supported: true },
102+
modeledMethod: undefined,
65103
};

extensions/ql-vscode/src/view/model-editor/ModeledMethodDataGrid.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { Mode } from "../../model-editor/shared/mode";
1212
import { sortMethods } from "../../model-editor/shared/sorting";
1313
import { InProgressMethods } from "../../model-editor/shared/in-progress-methods";
1414

15+
export const GRID_TEMPLATE_COLUMNS = "0.5fr 0.125fr 0.125fr 0.125fr 0.125fr";
16+
1517
type Props = {
1618
packageName: string;
1719
methods: Method[];
@@ -36,7 +38,7 @@ export const ModeledMethodDataGrid = ({
3638
const sortedMethods = useMemo(() => sortMethods(methods), [methods]);
3739

3840
return (
39-
<VSCodeDataGrid gridTemplateColumns="0.5fr 0.125fr 0.125fr 0.125fr 0.125fr">
41+
<VSCodeDataGrid gridTemplateColumns={GRID_TEMPLATE_COLUMNS}>
4042
<VSCodeDataGridRow rowType="header">
4143
<VSCodeDataGridCell cellType="columnheader" gridColumn={1}>
4244
API or method

0 commit comments

Comments
 (0)