Skip to content

Commit d6f41e6

Browse files
committed
- Added toolbar action to edit .graphqlconfig file for the selected schema (#164)
- Updated schema node to appear as bold when editing its config file
1 parent d1fc282 commit d6f41e6

File tree

7 files changed

+55
-22
lines changed

7 files changed

+55
-22
lines changed

src/main/com/intellij/lang/jsgraphql/ide/project/schemastatus/GraphQLConfigSchemaNode.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class GraphQLConfigSchemaNode extends SimpleNode {
3939
private final GraphQLConfigManager configManager;
4040
private final GraphQLResolvedConfigData configData;
4141
private final VirtualFile configBaseDir;
42+
private final VirtualFile configFile;
4243

4344
private final List<GraphQLConfigEndpoint> endpoints;
4445
private final GraphQLFile configurationEntryFile;
@@ -50,6 +51,7 @@ protected GraphQLConfigSchemaNode(Project project, GraphQLConfigManager configMa
5051
this.configManager = configManager;
5152
this.configData = configData;
5253
this.configBaseDir = configBaseDir;
54+
this.configFile = configManager.getClosestConfigFile(configBaseDir);
5355
if (configData.name != null && !configData.name.isEmpty()) {
5456
myName = configData.name;
5557
} else {
@@ -76,6 +78,9 @@ protected GraphQLConfigSchemaNode(Project project, GraphQLConfigManager configMa
7678
*/
7779
public boolean representsFile(VirtualFile virtualFile) {
7880
if (virtualFile != null) {
81+
if(virtualFile.equals(configFile)) {
82+
return true;
83+
}
7984
final GraphQLNamedScope schemaScope = configManager.getSchemaScope(configurationEntryFile.getVirtualFile());
8085
if (schemaScope != null) {
8186
if (schemaScope.getPackageSet().includesVirtualFile(virtualFile)) {
@@ -86,6 +91,10 @@ public boolean representsFile(VirtualFile virtualFile) {
8691
return false;
8792
}
8893

94+
public VirtualFile getConfigFile() {
95+
return configFile;
96+
}
97+
8998
@Override
9099
protected void update(PresentationData presentation) {
91100
super.update(presentation);
@@ -96,13 +105,13 @@ protected void update(PresentationData presentation) {
96105
@Override
97106
public SimpleNode[] getChildren() {
98107
final List<SimpleNode> children = Lists.newArrayList(
99-
new GraphQLSchemaContentNode(myProject, this, schemaWithErrors),
100-
new GraphQLSchemaErrorsListNode(myProject, schemaWithErrors)
108+
new GraphQLSchemaContentNode( this, schemaWithErrors),
109+
new GraphQLSchemaErrorsListNode(this, schemaWithErrors)
101110
);
102111
if (projectsConfigData != null && !projectsConfigData.isEmpty()) {
103112
children.add(new GraphQLConfigProjectsNode(this));
104113
}
105-
children.add(new GraphQLSchemaEndpointsListNode(myProject, endpoints));
114+
children.add(new GraphQLSchemaEndpointsListNode(this, endpoints));
106115
return children.toArray(SimpleNode.NO_CHILDREN);
107116
}
108117

src/main/com/intellij/lang/jsgraphql/ide/project/schemastatus/GraphQLDefaultSchemaNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ protected GraphQLDefaultSchemaNode(Project project) {
3939
@Override
4040
public SimpleNode[] getChildren() {
4141
final List<SimpleNode> children = Lists.newArrayList(
42-
new GraphQLSchemaContentNode(myProject, this, schemaWithErrors),
43-
new GraphQLSchemaErrorsListNode(myProject, schemaWithErrors),
44-
new GraphQLSchemaEndpointsListNode(myProject, null)
42+
new GraphQLSchemaContentNode(this, schemaWithErrors),
43+
new GraphQLSchemaErrorsListNode(this, schemaWithErrors),
44+
new GraphQLSchemaEndpointsListNode(this, null)
4545
);
4646
return children.toArray(SimpleNode.NO_CHILDREN);
4747
}

src/main/com/intellij/lang/jsgraphql/ide/project/schemastatus/GraphQLSchemaContentNode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.intellij.ide.util.gotoByName.SimpleChooseByNameModel;
1515
import com.intellij.lang.jsgraphql.schema.GraphQLSchemaWithErrors;
1616
import com.intellij.openapi.application.ModalityState;
17-
import com.intellij.openapi.project.Project;
1817
import com.intellij.psi.PsiElement;
1918
import com.intellij.ui.ColoredListCellRenderer;
2019
import com.intellij.ui.SimpleTextAttributes;
@@ -39,8 +38,8 @@ public class GraphQLSchemaContentNode extends SimpleNode {
3938

4039
private final GraphQLSchemaWithErrors schemaWithErrors;
4140

42-
public GraphQLSchemaContentNode(Project project, SimpleNode parent, GraphQLSchemaWithErrors schemaWithErrors) {
43-
super(project, parent);
41+
public GraphQLSchemaContentNode(SimpleNode parent, GraphQLSchemaWithErrors schemaWithErrors) {
42+
super(parent);
4443
this.schemaWithErrors = schemaWithErrors;
4544

4645
final List<String> parts = Lists.newArrayList();

src/main/com/intellij/lang/jsgraphql/ide/project/schemastatus/GraphQLSchemaEndpointsListNode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public class GraphQLSchemaEndpointsListNode extends SimpleNode {
4242

4343
private final List<GraphQLConfigEndpoint> endpoints;
4444

45-
public GraphQLSchemaEndpointsListNode(Project project, List<GraphQLConfigEndpoint> endpoints) {
46-
super(project);
45+
public GraphQLSchemaEndpointsListNode(SimpleNode parent, List<GraphQLConfigEndpoint> endpoints) {
46+
super(parent);
4747
this.endpoints = endpoints;
4848
myName = "Endpoints";
4949
setIcon(AllIcons.Nodes.WebFolder);
@@ -54,7 +54,7 @@ public SimpleNode[] getChildren() {
5454
if (endpoints == null) {
5555
return new SimpleNode[]{new DefaultEndpointNode(myProject)};
5656
} else {
57-
return endpoints.stream().map(endpoint -> new ConfigurableEndpointNode(myProject, endpoint)).toArray(SimpleNode[]::new);
57+
return endpoints.stream().map(endpoint -> new ConfigurableEndpointNode(this, endpoint)).toArray(SimpleNode[]::new);
5858
}
5959
}
6060

@@ -67,8 +67,8 @@ private static class ConfigurableEndpointNode extends SimpleNode {
6767

6868
private GraphQLConfigEndpoint endpoint;
6969

70-
public ConfigurableEndpointNode(Project project, GraphQLConfigEndpoint endpoint) {
71-
super(project);
70+
public ConfigurableEndpointNode(SimpleNode parent, GraphQLConfigEndpoint endpoint) {
71+
super(parent);
7272
this.endpoint = endpoint;
7373
myName = endpoint.name;
7474
getTemplatePresentation().setTooltip("Endpoints allow you to perform GraphQL introspection, queries and mutations");

src/main/com/intellij/lang/jsgraphql/ide/project/schemastatus/GraphQLSchemaErrorNode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package com.intellij.lang.jsgraphql.ide.project.schemastatus;
99

1010
import com.intellij.icons.AllIcons;
11-
import com.intellij.openapi.project.Project;
1211
import com.intellij.ui.treeStructure.SimpleNode;
1312
import com.intellij.ui.treeStructure.SimpleTree;
1413
import graphql.GraphQLError;
@@ -24,8 +23,8 @@ public class GraphQLSchemaErrorNode extends SimpleNode {
2423

2524
private final GraphQLError error;
2625

27-
public GraphQLSchemaErrorNode(Project project, GraphQLError error) {
28-
super(project);
26+
public GraphQLSchemaErrorNode(SimpleNode parent, GraphQLError error) {
27+
super(parent);
2928
this.error = error;
3029
myName = error.getMessage();
3130
setIcon(AllIcons.Ide.Error);

src/main/com/intellij/lang/jsgraphql/ide/project/schemastatus/GraphQLSchemaErrorsListNode.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.google.common.collect.Lists;
1111
import com.intellij.icons.AllIcons;
1212
import com.intellij.lang.jsgraphql.schema.GraphQLSchemaWithErrors;
13-
import com.intellij.openapi.project.Project;
1413
import com.intellij.ui.treeStructure.SimpleNode;
1514
import graphql.GraphQLError;
1615

@@ -23,8 +22,8 @@ public class GraphQLSchemaErrorsListNode extends SimpleNode {
2322

2423
private final GraphQLSchemaWithErrors schemaWithErrors;
2524

26-
public GraphQLSchemaErrorsListNode(Project project, GraphQLSchemaWithErrors schemaWithErrors) {
27-
super(project);
25+
public GraphQLSchemaErrorsListNode(SimpleNode parent, GraphQLSchemaWithErrors schemaWithErrors) {
26+
super(parent);
2827
this.schemaWithErrors = schemaWithErrors;
2928
myName = "Schema errors";
3029
setIcon(AllIcons.Nodes.TreeClosed);
@@ -34,10 +33,10 @@ public GraphQLSchemaErrorsListNode(Project project, GraphQLSchemaWithErrors sche
3433
public SimpleNode[] getChildren() {
3534
final List<SimpleNode> children = Lists.newArrayList();
3635
for (GraphQLError error : schemaWithErrors.getErrors()) {
37-
children.add(new GraphQLSchemaErrorNode(myProject, error));
36+
children.add(new GraphQLSchemaErrorNode(this, error));
3837
}
3938
if (children.isEmpty()) {
40-
SimpleNode noErrors = new SimpleNode() {
39+
SimpleNode noErrors = new SimpleNode(this) {
4140
@Override
4241
public SimpleNode[] getChildren() {
4342
return NO_CHILDREN;

src/main/com/intellij/lang/jsgraphql/ide/project/schemastatus/GraphQLSchemasPanel.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.intellij.lang.jsgraphql.schema.GraphQLSchemaChangeListener;
1515
import com.intellij.openapi.actionSystem.*;
1616
import com.intellij.openapi.application.ApplicationManager;
17+
import com.intellij.openapi.fileEditor.FileEditorManager;
1718
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
1819
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
1920
import com.intellij.openapi.project.DumbServiceImpl;
@@ -22,6 +23,7 @@
2223
import com.intellij.ui.IdeBorderFactory;
2324
import com.intellij.ui.SideBorder;
2425
import com.intellij.ui.components.JBScrollPane;
26+
import com.intellij.ui.treeStructure.SimpleNode;
2527
import com.intellij.ui.treeStructure.SimpleTree;
2628
import com.intellij.ui.treeStructure.SimpleTreeBuilder;
2729
import com.intellij.ui.treeStructure.SimpleTreeStructure;
@@ -155,6 +157,31 @@ public void actionPerformed(AnActionEvent e) {
155157
}
156158
}
157159
});
160+
leftActionGroup.add(new AnAction("Edit selected schema configuration", "Opens the .graphqlconfig file for the selected schema", AllIcons.General.Settings) {
161+
@Override
162+
public void actionPerformed(AnActionEvent e) {
163+
GraphQLConfigSchemaNode selectedSchemaNode = getSelectedSchemaNode();
164+
if (selectedSchemaNode != null && selectedSchemaNode.getConfigFile() != null) {
165+
FileEditorManager.getInstance(myProject).openFile(selectedSchemaNode.getConfigFile(), true);
166+
}
167+
}
168+
169+
@Override
170+
public void update(AnActionEvent e) {
171+
e.getPresentation().setEnabled(getSelectedSchemaNode() != null);
172+
}
173+
174+
private GraphQLConfigSchemaNode getSelectedSchemaNode() {
175+
SimpleNode node = myTree.getSelectedNode();
176+
while (node != null) {
177+
if (node instanceof GraphQLConfigSchemaNode) {
178+
return (GraphQLConfigSchemaNode) node;
179+
}
180+
node = node.getParent();
181+
}
182+
return null;
183+
}
184+
});
158185
leftActionGroup.add(new AnAction("Restart schema discovery", "Performs GraphQL schema discovery across the project", AllIcons.Actions.Refresh) {
159186
@Override
160187
public void actionPerformed(AnActionEvent e) {

0 commit comments

Comments
 (0)