Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support update Maven profiles #1331

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -8,16 +8,16 @@ import Output from "./components/Output";
import Sources from "./components/Sources";
import Libraries from "./components/Libraries";
import Exception from "./components/Exception";
import { ClasspathViewException, ProjectInfo } from "../../../handlers/classpath/types";
import { catchException, initializeProjectsData, listVmInstalls, loadClasspath, updateActiveTab } from "./classpathConfigurationViewSlice";
import { ClasspathViewException, ProjectInfo } from "../../../types";
import { catchException, listVmInstalls, loadClasspath, updateActiveTab } from "./classpathConfigurationViewSlice";
import JdkRuntime from "./components/JdkRuntime";
import { ClasspathRequest } from "../../vscode/utils";
import { VSCodePanelTab, VSCodePanelView, VSCodePanels, VSCodeProgressRing } from "@vscode/webview-ui-toolkit/react";
import { ProjectType } from "../../../../utils/webview";
import UnmanagedFolderSources from "./components/UnmanagedFolderSources";
import Hint from "./components/Hint";
import "../style.scss";
import { listProjects, setProjectType } from "../../mainpage/features/commonSlice";
import { setProjectType } from "../../mainpage/features/commonSlice";

const ClasspathConfigurationView = (): JSX.Element => {
const activeTab: string = useSelector((state: any) => state.classpathConfig.ui.activeTab);
Expand Down Expand Up @@ -62,10 +62,7 @@ const ClasspathConfigurationView = (): JSX.Element => {

const onMessage = (event: any) => {
const { data } = event;
if (data.command === "classpath.onDidListProjects") {
dispatch(initializeProjectsData({ projectsNum: data.projectInfo?.length }));
dispatch(listProjects(data.projectInfo));
} else if (data.command === "classpath.onDidListVmInstalls") {
if (data.command === "classpath.onDidListVmInstalls") {
dispatch(listVmInstalls(data.vmInstalls))
} else if (data.command === "classpath.onDidLoadProjectClasspath") {
dispatch(setProjectType({
Expand All @@ -87,7 +84,6 @@ const ClasspathConfigurationView = (): JSX.Element => {
// redux store is empty. When switching between tabs, the
// state will be preserved.
ClasspathRequest.onWillListProjects();
ClasspathRequest.onWillListVmInstalls();
}
return () => {
window.removeEventListener("message", onMessage);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { createSlice, current } from "@reduxjs/toolkit";
import { createSlice } from "@reduxjs/toolkit";
import _ from "lodash";
import { ClasspathEntry } from "../../../handlers/classpath/types";
import { ClasspathEntry } from "../../../types";

export const classpathConfigurationViewSlice = createSlice({
name: "classpathConfig",
Expand All @@ -25,7 +25,7 @@ export const classpathConfigurationViewSlice = createSlice({
updateActiveTab: (state, action) => {
state.ui.activeTab = action.payload;
},
initializeProjectsData: (state, action) => {
initializeClasspathData: (state, action) => {
const projectNum = action.payload.projectsNum;
state.data.activeVmInstallPath = Array(projectNum).fill("");
state.data.sources = Array(projectNum).fill([]);
Expand All @@ -40,13 +40,13 @@ export const classpathConfigurationViewSlice = createSlice({
state.data.output[activeProjectIndex] = action.payload.output;
state.data.activeVmInstallPath[activeProjectIndex] = action.payload.activeVmInstallPath;
// Only update the array when they have different elements.
const currentSources = _.sortBy(current(state.data.sources), ["path", "output"]); // TODO: activeProjectIndex needed?
const currentSources = _.sortBy(state.data.sources[activeProjectIndex], ["path", "output"]);
const newSources = _.sortBy(action.payload.sources, ["path", "output"]);
if (!_.isEqual(currentSources, newSources)) {
state.data.sources[activeProjectIndex] = action.payload.sources;
}

const currentLibs = _.sortBy(current(state.data.libraries), ["path"]);
const currentLibs = _.sortBy(state.data.libraries[activeProjectIndex], ["path"]);
const newLibs = _.sortBy(action.payload.libraries, ["path"]);
if (!_.isEqual(currentLibs, newLibs)) {
state.data.libraries[activeProjectIndex] = action.payload.libraries;
Expand Down Expand Up @@ -97,7 +97,7 @@ function isDifferentStringArray(a1: string[], a2: string[]): boolean {

export const {
updateActiveTab,
initializeProjectsData,
initializeClasspathData,
listVmInstalls,
loadClasspath,
updateSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from "react";
import { useSelector } from "react-redux";
import { encodeCommandUriWithTelemetry, supportedByNavigator } from "../../../../../utils/webview";
import { ClasspathViewException } from "../../../../handlers/classpath/types";
import { ClasspathViewException } from "../../../../types";
import { WEBVIEW_ID } from "../../utils";

const Exception = (): JSX.Element | null => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { VSCodeLink} from "@vscode/webview-ui-toolkit/react";
import React, { useEffect } from "react";
import { ProjectInfo } from "../../../../handlers/classpath/types";
import { ProjectInfo } from "../../../../types";
import { useSelector } from "react-redux";
import { ProjectType } from "../../../../../utils/webview";
import { updateMaxHeight } from "../../utils";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, { Dispatch, useEffect, useState } from "react";
import { ClasspathRequest, CommonRequest } from "../../../vscode/utils";
import { VSCodeDivider, VSCodeDropdown, VSCodeOption, } from "@vscode/webview-ui-toolkit/react";
import { useDispatch, useSelector } from "react-redux";
import { VmInstall } from "../../../../handlers/classpath/types";
import { VmInstall } from "../../../../types";
import { setJdks } from "../classpathConfigurationViewSlice";

const JdkRuntime = (): JSX.Element => {
Expand Down Expand Up @@ -97,6 +97,9 @@ const JdkRuntime = (): JSX.Element => {
// to change its style.
document.querySelector("#jdk-dropdown")?.shadowRoot
?.querySelector(".listbox")?.setAttribute("style", "max-height: initial;");
if (vmInstalls.length === 0) {
ClasspathRequest.onWillListVmInstalls();
}
return () => window.removeEventListener("message", onDidChangeJdk);
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useSelector, useDispatch } from "react-redux";
import { removeReferencedLibrary, addLibraries } from "../classpathConfigurationViewSlice";
import { ClasspathRequest } from "../../../vscode/utils";
import { VSCodeButton, VSCodeDataGrid, VSCodeDataGridCell, VSCodeDataGridRow, VSCodeDivider } from "@vscode/webview-ui-toolkit/react";
import { ClasspathEntry, ClasspathEntryKind } from "../../../../handlers/classpath/types";
import { ClasspathEntry, ClasspathEntryKind } from "../../../../types";

const Libraries = (): JSX.Element => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Dispatch } from "@reduxjs/toolkit";
import { updateSource } from "../classpathConfigurationViewSlice";
import { ClasspathRequest } from "../../../vscode/utils";
import { VSCodeButton, VSCodeDataGrid, VSCodeDataGridCell, VSCodeDataGridRow, VSCodeDivider, VSCodeTextField } from "@vscode/webview-ui-toolkit/react";
import { ClasspathEntry, ClasspathEntryKind } from "../../../../handlers/classpath/types";
import { ClasspathEntry, ClasspathEntryKind } from "../../../../types";

const Sources = (): JSX.Element => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { updateSource } from "../classpathConfigurationViewSlice";
import { ClasspathRequest } from "../../../vscode/utils";
import { ProjectType } from "../../../../../utils/webview";
import { VSCodeButton, VSCodeDataGrid, VSCodeDataGridCell, VSCodeDataGridRow, VSCodeDivider } from "@vscode/webview-ui-toolkit/react";
import { ClasspathEntry } from "../../../../handlers/classpath/types";
import { ClasspathEntry } from "../../../../types";

const UnmanagedFolderSources = (): JSX.Element => {

Expand Down
5 changes: 5 additions & 0 deletions src/project-settings/assets/classpath/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@
}
}

.setting-section-subtitle {
display: flex;
align-items: baseline;
}

.setting-section-text {
width: 100%;
max-width: 420px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import React, { Dispatch } from "react";
import { useDispatch, useSelector } from "react-redux";
import ClasspathConfigurationView from "../../classpath/features/ClasspathConfigurationView";
import { updateActiveTab } from "../../classpath/features/classpathConfigurationViewSlice";
import { initializeClasspathData, updateActiveTab } from "../../classpath/features/classpathConfigurationViewSlice";
import "../style.scss";
import { updateActiveSection } from "./commonSlice";
import { listProjects, updateActiveSection } from "./commonSlice";
import ProjectSelector from "./component/ProjectSelector";
import { VSCodeDivider } from "@vscode/webview-ui-toolkit/react";
import Footer from "./component/Footer";
import SideBar from "./component/SideBar";
import MavenConfigurationView from "../../maven/features/MavenConfigurationView";
import { SectionId } from "../../../types";
import { initializeMavenData } from "../../maven/features/mavenConfigurationViewSlice";

const ProjectSettingView = (): JSX.Element => {
const activeSection: string = useSelector((state: any) => state.commonConfig.ui.activeSection);
Expand All @@ -24,8 +27,10 @@ const ProjectSettingView = (): JSX.Element => {
}, []);

const getSectionContent = () => {
if (activeSection === "classpath") {
if (activeSection === SectionId.Classpath) {
return <ClasspathConfigurationView />;
} else if (activeSection === SectionId.Maven) {
return <MavenConfigurationView />;
}

return null;
Expand All @@ -38,7 +43,7 @@ const ProjectSettingView = (): JSX.Element => {
dispatch(updateActiveSection(routes[0]));
if (routes.length > 1) {
switch (routes[0]) {
case "classpath":
case SectionId.Classpath:
// TODO: sometimes when directly trigger 'Configure Java Runtime', the tab won't
// focus to the JDK part, need to investigate
dispatch(updateActiveTab(routes[1]));
Expand All @@ -47,6 +52,10 @@ const ProjectSettingView = (): JSX.Element => {
break;
}
}
} else if (data.command === "main.onDidListProjects") {
dispatch(initializeClasspathData({ projectsNum: data.projectInfo?.length }));
dispatch(initializeMavenData({ projectsNum: data.projectInfo?.length }));
dispatch(listProjects(data.projectInfo));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import { createSlice } from "@reduxjs/toolkit";
import { ProjectType } from "../../../../utils/webview";
import { ProjectState } from "../../../handlers/classpath/types";
import { ProjectState, SectionId } from "../../../types";
import _ from "lodash";

export const commonSlice = createSlice({
name: "commonConfiguration",
initialState: {
ui: {
activeSection: "classpath",
activeSection: SectionId.Classpath,
activeProjectIndex: 0,
},
data: {
Expand All @@ -31,6 +31,10 @@ export const commonSlice = createSlice({
},
activeProjectChange: (state, action) => {
state.ui.activeProjectIndex = action.payload;
if (state.data.projectType[state.ui.activeProjectIndex] === ProjectType.Maven
&& state.ui.activeSection === SectionId.Maven) {
state.ui.activeSection = SectionId.Classpath;
}
},
setProjectType: (state, action) => {
state.data.projectState[state.ui.activeProjectIndex] = ProjectState.Loaded;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import { VSCodeButton } from "@vscode/webview-ui-toolkit/react";
import { Dispatch } from "@reduxjs/toolkit";
import React, { useEffect } from "react";
import { ClasspathEntry, ProjectInfo } from "../../../../handlers/classpath/types";
import { ClasspathEntry, ProjectInfo } from "../../../../types";
import { useDispatch, useSelector } from "react-redux";
import { ProjectType } from "../../../../../utils/webview";
import { updateLoadingState } from "../../../classpath/features/classpathConfigurationViewSlice";
import { ClasspathRequest } from "../../../vscode/utils";
import { ClasspathRequest, MavenRequest } from "../../../vscode/utils";

const Footer = (): JSX.Element => {

Expand All @@ -18,6 +18,7 @@ const Footer = (): JSX.Element => {
const activeVmInstallPath: string[] = useSelector((state: any) => state.classpathConfig.data.activeVmInstallPath);
const projectType: ProjectType[] = useSelector((state: any) => state.commonConfig.data.projectType);
const libraries: ClasspathEntry[][] = useSelector((state: any) => state.classpathConfig.data.libraries);
const activeProfiles: string[] = useSelector((state: any) => state.mavenConfig.data.activeProfiles);
const loadingState: boolean = useSelector((state: any) => state.classpathConfig.loadingState);

const dispatch: Dispatch<any> = useDispatch();
Expand All @@ -31,6 +32,13 @@ const Footer = (): JSX.Element => {
activeVmInstallPath,
libraries
);

// maven section
for (let i = 0; i < projects.length; i++) {
if (projectType[i] === ProjectType.Maven) {
MavenRequest.onWillUpdateSelectProfiles(projects[i].rootPath, activeProfiles[i]);
}
}
};

const onDidChangeLoadingState = (event: OnDidChangeLoadingStateEvent) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import React, { useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import { ProjectInfo, ProjectState } from "../../../../handlers/classpath/types";
import { ProjectInfo, ProjectState } from "../../../../types";
import { Dispatch } from "@reduxjs/toolkit";
import { ClasspathRequest } from "../../../vscode/utils";
import { VSCodeDropdown, VSCodeOption } from "@vscode/webview-ui-toolkit/react";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import { useSelector, useDispatch } from "react-redux";
import { Dispatch } from "@reduxjs/toolkit";
import { updateActiveSection } from "../commonSlice";
import { CommonRequest } from "../../../vscode/utils";

const CLASSPATH = "classpath";
const FORMATTER = "formatter";
import { ProjectType } from "../../../../../utils/webview";
import { SectionId } from "../../../../types";

const SideBar = (): JSX.Element => {

const activeSection: string = useSelector((state: any) => state.commonConfig.ui.activeSection);
const activeProjectIndex: number = useSelector((state: any) => state.commonConfig.ui.activeProjectIndex);
const projectType: ProjectType = useSelector((state: any) => state.commonConfig.data.projectType[activeProjectIndex]);

const dispatch: Dispatch<any> = useDispatch();

const onClickNavBarItem = (panelId: string) => {
if (panelId === FORMATTER) {
if (panelId === SectionId.Formatter) {
CommonRequest.onWillExecuteCommand("java.formatterSettings");
return;
}
Expand All @@ -27,10 +29,17 @@ const SideBar = (): JSX.Element => {
<div className="app-sidebar">
<div className="app-sidebar-content">
<div className="mt-2">
<div className={`section-link ${activeSection === CLASSPATH ? "section-link-active" : ""} mb-1`} onClick={() => onClickNavBarItem(CLASSPATH)}>
<div className={`section-link ${activeSection === SectionId.Classpath ? "section-link-active" : ""} mb-1`} onClick={() => onClickNavBarItem(SectionId.Classpath)}>
Classpath
</div>
<div className="section-link mb-1" onClick={() => onClickNavBarItem(FORMATTER)}>
{
projectType === ProjectType.Maven && (
<div className={`section-link ${activeSection === SectionId.Maven ? "section-link-active" : ""} mb-1`} onClick={() => onClickNavBarItem(SectionId.Maven)}>
Maven
</div>
)
}
<div className="section-link mb-1" onClick={() => onClickNavBarItem(SectionId.Formatter)}>
Formatter <span className="codicon codicon-link-external"></span>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import React from "react";
import { useSelector } from "react-redux";
import { ProjectType } from "../../../../utils/webview";
import Profile from "./components/Profile";

const MavenConfigurationView = (): JSX.Element | null => {
const activeProjectIndex: number = useSelector((state: any) => state.commonConfig.ui.activeProjectIndex);
const projectTypes: ProjectType = useSelector((state: any) => state.commonConfig.data.projectType);
if (projectTypes.length === 0) {
return null;
}

if (projectTypes[activeProjectIndex] !== ProjectType.Maven) {
return <span>Not a Maven project</span>;
} else {
return <Profile />;
}
}

export default MavenConfigurationView;
Loading