Skip to content

Commit

Permalink
chore: remove obsolete references to seed node
Browse files Browse the repository at this point in the history
  • Loading branch information
JChrist committed Jan 16, 2025
1 parent 54612ea commit 0cbd78e
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 199 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ video
*.iml
target/
macos-sdk-11.3/
META-INF/jrad/
**/META-INF/jrad/**
artifacts/
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pluginUntilBuild=

# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
platformType = IC
# cannot use 2024.3.1 (or 2024.3.1.1) https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1838
platformVersion = 2024.3
#platformVersion = LATEST-EAP-SNAPSHOT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.intellij.openapi.project.Project;
import git4idea.GitUtil;
import git4idea.repo.GitRepository;
import network.radicle.jetbrains.radiclejetbrainsplugin.config.RadicleProjectSettingsHandler;
import network.radicle.jetbrains.radiclejetbrainsplugin.services.RadicleCliService;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -74,9 +73,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
}

public void openInBrowser(Project project, GitRepository repo, String fileToOpen, BrowserLauncher browserLauncher) {
var radicleSettingsHandler = new RadicleProjectSettingsHandler(project);
var nodeUrl = radicleSettingsHandler.loadSettings().getSeedNode().url
.replace("http://", "").replace("https://", "");
var cli = project.getService(RadicleCliService.class);
var nodeUrl = cli.getWebUrl();
if (Strings.isNullOrEmpty(nodeUrl)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package network.radicle.jetbrains.radiclejetbrainsplugin.config;

import network.radicle.jetbrains.radiclejetbrainsplugin.models.SeedNode;

public class RadicleProjectSettings {
private String radHome;

Check warning on line 4 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/config/RadicleProjectSettings.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `radHome` may be 'final'
private String path;

Check warning on line 5 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/config/RadicleProjectSettings.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `path` may be 'final'
private SeedNode seedNode;

public RadicleProjectSettings(String radHome, String path, SeedNode seedNode) {
public RadicleProjectSettings(String radHome, String path) {
this.radHome = radHome;
this.path = path;
this.seedNode = seedNode;
}

public String getRadHome() {
Expand All @@ -21,16 +17,11 @@ public String getPath() {
return path;
}

public SeedNode getSeedNode() {
return seedNode;
}

@Override
public String toString() {
return "RadicleProjectSettings{" +
"radHome='" + radHome + '\'' +
"path='" + path + '\'' +
"seedNode='" + seedNode + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@
import com.intellij.ide.passwordSafe.PasswordSafe;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.project.Project;
import network.radicle.jetbrains.radiclejetbrainsplugin.models.SeedNode;

public class RadicleProjectSettingsHandler {
public static final String RAD_SETTINGS_PREFIX = RadicleProjectSettingsHandler.class.getPackageName();
public static final String RAD_HOME_KEY = RAD_SETTINGS_PREFIX + ".radHome";
public static final String PATH_KEY = RAD_SETTINGS_PREFIX + ".path";
public static final String RAD_SEED_KEY = RAD_SETTINGS_PREFIX + ".radSeedKey";
public static final String DEFAULT_SEED_NODES = "http://localhost:8080";
private final Project project;

public RadicleProjectSettingsHandler(Project project) {
this.project = project;
saveDefaultSeedNodes();
}

public Project getProject() {
Expand All @@ -39,16 +35,7 @@ public String getPassword(String key) {
}

public boolean isSettingsEmpty() {
return Strings.isNullOrEmpty(getPath()) || Strings.isNullOrEmpty(getRadHome()) ||
Strings.isNullOrEmpty(getSeedNode().url);
}

private SeedNode getSeedNode() {
var seed = getApplicationProperties().getValue(RAD_SEED_KEY);
if (Strings.isNullOrEmpty(seed)) {
return new SeedNode("");
}
return new SeedNode(seed);
return Strings.isNullOrEmpty(getPath()) || Strings.isNullOrEmpty(getRadHome());
}

public void saveRadHome(String radHome) {
Expand All @@ -59,23 +46,12 @@ public void savePath(String path) {
getApplicationProperties().setValue(PATH_KEY, path);
}

public void saveSeedNode(String seedNode) {
getApplicationProperties().setValue(RAD_SEED_KEY, Strings.nullToEmpty(seedNode));
}

public void savePassphrase(String key, String passphrase) {
storeCredentials(key, passphrase);
}

private void saveDefaultSeedNodes() {
var loadedSeedNode = getSeedNode();
if (Strings.isNullOrEmpty(loadedSeedNode.url)) {
saveSeedNode(DEFAULT_SEED_NODES);
}
}

public RadicleProjectSettings loadSettings() {
return new RadicleProjectSettings(getRadHome(), getPath(), getSeedNode());
return new RadicleProjectSettings(getRadHome(), getPath());
}

private PropertiesComponent getApplicationProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="7" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="e3588" layout-manager="GridLayoutManager" row-count="6" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
Expand Down Expand Up @@ -36,20 +36,6 @@
</constraints>
<properties/>
</component>
<component id="ec9a0" class="javax.swing.JLabel" binding="seedNodeLabel">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="HTTP daemon URL:"/>
</properties>
</component>
<component id="6b56c" class="javax.swing.JComboBox" binding="seedNodeSelect">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="f6f5b" class="javax.swing.JLabel" binding="projectNameLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package network.radicle.jetbrains.radiclejetbrainsplugin.dialog;

import com.google.common.base.Strings;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.project.Project;
Expand All @@ -12,7 +13,6 @@
import network.radicle.jetbrains.radiclejetbrainsplugin.RadicleBundle;
import network.radicle.jetbrains.radiclejetbrainsplugin.actions.rad.RadAction;
import network.radicle.jetbrains.radiclejetbrainsplugin.actions.rad.RadInit;
import network.radicle.jetbrains.radiclejetbrainsplugin.config.RadicleProjectSettingsHandler;
import network.radicle.jetbrains.radiclejetbrainsplugin.toolwindow.RadicleToolWindow;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -37,26 +37,22 @@ public class PublishDialog extends DialogWrapper {
private JTextField branchField;
private JTextField nameField;
private JBTextArea descriptionField;
private JComboBox<String> seedNodeSelect;
private JComboBox<GitRepository> projectSelect;
private JLabel projectNameLabel;
private JLabel branchLabel;
private JLabel nameLabel;
private JLabel descrLabel;
private JLabel seedNodeLabel;
private JComboBox<Visibility> visibilitySelect;
private JLabel visibilityLabel;
private final List<GitRepository> repos;
private final Project project;

Check warning on line 48 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/dialog/PublishDialog.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field can be local

Field can be converted to a local variable
private final RadicleProjectSettingsHandler radicleProjectSettingsHandler;
private boolean isSelectedRepoInitialized;
public CountDownLatch isUiLoaded = new CountDownLatch(1);

public PublishDialog(List<GitRepository> repos, Project project) {
super(true);
this.repos = repos;
this.project = project;
this.radicleProjectSettingsHandler = new RadicleProjectSettingsHandler(project);
init();
}

Expand Down Expand Up @@ -99,8 +95,6 @@ protected void init() {
super.init();
setOKActionEnabled(false);
setTitle(RadicleBundle.message("shareProject"));
var settings = radicleProjectSettingsHandler.loadSettings();
var seedNode = settings.getSeedNode();
var textFieldListener = new TextFieldListener();
nameField.getDocument().addDocumentListener(textFieldListener);
branchField.getDocument().addDocumentListener(textFieldListener);
Expand All @@ -115,7 +109,7 @@ protected void init() {
for (var vi : Visibility.values()) {
visibilitySelect.addItem(vi);
}
seedNodeSelect.addItem(seedNode.url);
//seedNodeSelect.addItem(seedNode.url);
for (var repo : repos) {
projectSelect.addItem(repo);
}
Expand All @@ -136,46 +130,15 @@ private void updateLayout() {
branchLabel.setVisible(showInitFields);
descrLabel.setVisible(showInitFields);
nameLabel.setVisible(showInitFields);
visibilityLabel.setVisible(showInitFields);
visibilitySelect.setVisible(showInitFields);

if (isInitialized || (!nameField.getText().isEmpty() && !branchField.getText().isEmpty() &&
!descriptionField.getText().isEmpty() && seedNodeSelect.getSelectedItem() != null)) {
setOKActionEnabled(true);
} else {
setOKActionEnabled(false);
}
var ok = isInitialized || (!nameField.getText().isEmpty() && !branchField.getText().isEmpty() && !descriptionField.getText().isEmpty());
setOKActionEnabled(ok);
}, ModalityState.any());
});
}

public static class ComboBoxCellRenderer extends DefaultListCellRenderer {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof GitRepository) {
var repo = (GitRepository) value;
setText(repo.getRoot().getName());
}
if (value instanceof Visibility) {
var val = ((Visibility) value).label;
setText(val);
}
return this;
}
}

public class TextFieldListener extends DocumentAdapter {
@Override
protected void textChanged(@NotNull DocumentEvent e) {
if (nameField.getText().isEmpty() || branchField.getText().isEmpty() ||
descriptionField.getText().isEmpty() || seedNodeSelect.getSelectedItem() == null) {
setOKActionEnabled(false);
} else {
setOKActionEnabled(true);
}
}
}

public JTextField getBranchField() {
return branchField;
}
Expand All @@ -188,18 +151,10 @@ public JTextArea getDescriptionField() {
return descriptionField;
}

public JComboBox<String> getSeedNodeSelect() {
return seedNodeSelect;
}

public JComboBox<Visibility> getVisibilitySelect() {
return visibilitySelect;
}

public JLabel getSeedNodeLabel() {
return seedNodeLabel;
}

public JComboBox<GitRepository> getProjectSelect() {
return projectSelect;
}
Expand All @@ -208,6 +163,29 @@ public JLabel getProjectNameLabel() {
return projectNameLabel;
}

public class TextFieldListener extends DocumentAdapter {
@Override
protected void textChanged(@NotNull DocumentEvent e) {
var err = Strings.isNullOrEmpty(nameField.getText()) || Strings.isNullOrEmpty(branchField.getText()) ||
Strings.isNullOrEmpty(descriptionField.getText());
setOKActionEnabled(!err);
}
}

public static class ComboBoxCellRenderer extends DefaultListCellRenderer {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof GitRepository repo) {
setText(repo.getRoot().getName());
}
if (value instanceof Visibility val) {
setText(val.label);
}
return this;
}
}

public enum Visibility {
PUBLIC("--public", "Public"),
PRIVATE("--private", "Private");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class RadIssue {
public GitRepository repo;
public Project project;
public String projectId;
public SeedNode seedNode;

public RadIssue() {
// for json
Expand All @@ -61,7 +60,6 @@ public RadIssue(RadIssue other) {
this.repo = other.repo;
this.project = other.project;
this.projectId = other.projectId;
this.seedNode = other.seedNode;
}

public RadDiscussion findDiscussion(String commentId) {
Expand All @@ -70,7 +68,7 @@ public RadDiscussion findDiscussion(String commentId) {

@JsonIgnore
public String getDescription() {
return discussion == null || discussion.isEmpty() ? "" : discussion.get(0).body;
return discussion == null || discussion.isEmpty() ? "" : discussion.getFirst().body;
}

@JsonFormat(shape = JsonFormat.Shape.OBJECT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
public class RadPatch {
private static final Logger logger = LoggerFactory.getLogger(RadPatch.class);

public SeedNode seedNode;
public GitRepository repo;
public Project project;
public RadProject radProject;
Expand Down Expand Up @@ -69,7 +68,6 @@ public RadPatch(
}

public RadPatch(RadPatch other) {
this.seedNode = other.seedNode;
this.repo = other.repo;
this.project = other.project;
this.radProject = other.radProject;
Expand Down

This file was deleted.

Loading

0 comments on commit 0cbd78e

Please sign in to comment.