Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into paths-std-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagobento committed Jan 12, 2024
2 parents bf4f75c + 411430b commit 7e9794e
Show file tree
Hide file tree
Showing 33 changed files with 246 additions and 133 deletions.
4 changes: 2 additions & 2 deletions .ci/kie-tools-ci-build.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ RUN wget https://archive.apache.org/dist/maven/maven-3/3.8.6/binaries/apache-mav
echo "source /etc/profile.d/maven.sh" >> $HOME/.bashrc

# Golang setup
RUN wget https://go.dev/dl/go1.21.1.linux-amd64.tar.gz -P /tmp && \
sudo tar xzf /tmp/go1.21.1.linux-amd64.tar.gz -C /opt && rm /tmp/go1.21.1.linux-amd64.tar.gz && \
RUN wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz -P /tmp && \
sudo tar xzf /tmp/go1.21.5.linux-amd64.tar.gz -C /opt && rm /tmp/go1.21.5.linux-amd64.tar.gz && \
echo 'export GOPATH=${HOME}/go' | sudo tee /etc/profile.d/go.sh && \
echo 'export PATH=${PATH}:/opt/go/bin:${GOPATH}/bin' | sudo tee -a /etc/profile.d/go.sh && \
echo "source /etc/profile.d/go.sh" >> $HOME/.bashrc
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/setup-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ runs:
java-version: 11
distribution: "zulu"

- name: "Set up GOLANG 1.21.1"
- name: "Set up GOLANG 1.21.5"
uses: actions/setup-go@v3
with:
go-version: "1.21.1"
go-version: "1.21.5"

- name: "Set up Maven"
uses: stCarolas/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To start building the Apache KIE Tools project, you're going to need:
- pnpm `8.7.0` _(To install, follow these instructions: https://pnpm.io/installation)_
- Maven `3.8.6`
- Java `11`
- Go `1.21.1` _(To install, follow these instructions: https://go.dev/doc/install)_
- Go `1.21.5` _(To install, follow these instructions: https://go.dev/doc/install)_
- Helm `3.13.3` _(To install, follow these instructions: https://helm.sh/docs/intro/install/)_

> **ℹ️ NOTE:** Some packages will require that `make` is available as well.
Expand Down
2 changes: 1 addition & 1 deletion examples/commit-message-validation-service/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/apache/incubator-kie-tools/examples/commit-message-validation-service

go 1.20
go 1.21

require (
github.com/gin-contrib/cors v1.4.0
Expand Down
1 change: 1 addition & 0 deletions examples/commit-message-validation-service/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
Expand Down
1 change: 1 addition & 0 deletions examples/uniforms-patternfly/src/schemas/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const schema = {
type: "string",
format: "date-time",
max: "2000-04-04T10:30:00.000Z",
description: "this is date and time field",
},
},
disabled: false,
Expand Down
3 changes: 3 additions & 0 deletions packages/chrome-extension/src/app/Dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export class Dependencies {
};

public readonly openRepoInExternalEditor = {
buttonContainerOnRepoHome: () => {
return document.querySelector("#repository-details-container .pagehead-actions") as HTMLElement | null;
},
buttonContainerOnRepoFilesList: () => {
return document.querySelector(".d-flex.gap-2")?.parentElement as HTMLElement | null;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const GitHubContextProvider: React.FC<{}> = (props) => {

const userIsLoggedIn = useCallback(() => {
return !!globals.dependencies.all.notificationIndicator();
}, []);
}, [globals.dependencies.all]);

const octokit = useCallback(() => {
return octokitInstance;
Expand All @@ -77,7 +77,7 @@ export const GitHubContextProvider: React.FC<{}> = (props) => {
console.debug("Token not found.");
}
setReady(true);
}, []);
}, [token]);

useLayoutEffect(() => {
if (!token) {
Expand All @@ -87,7 +87,7 @@ export const GitHubContextProvider: React.FC<{}> = (props) => {
setCookie(globals.githubAuthTokenCookieName, token);
octokitInstance = new Octokit({ auth: token });
}
}, [token]);
}, [globals.githubAuthTokenCookieName, token]);

return (
<GitHubContext.Provider value={{ token, setToken, octokit, userIsLoggedIn }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ const RefForwardingKogitoEditorIframe: React.ForwardRefRenderFunction<IsolatedEd
const { repoInfo, textMode, fullscreen, onEditorReady } = useContext(IsolatedEditorContext);
const { locale } = useChromeExtensionI18n();
const wasOnTextMode = usePrevious(textMode);
const { openFileExtension, contentPath, getFileContents, readonly, onSetContentError } = props;

const stateControl = useMemo(() => globalStateControl || new StateControl(), [globalStateControl]);

const resourceContentService = useMemo(() => {
return resourceContentServiceFactory.createNew(githubApi.octokit(), repoInfo);
}, [repoInfo]);
}, [githubApi, repoInfo, resourceContentServiceFactory]);

const onResourceContentRequest = useCallback(
(request: ResourceContentRequest) =>
Expand All @@ -85,13 +86,13 @@ const RefForwardingKogitoEditorIframe: React.ForwardRefRenderFunction<IsolatedEd
// When changing from textMode to !textMode, we should update the diagram content
useEffect(() => {
if (!textMode && wasOnTextMode) {
props.getFileContents().then((content) => editor?.setContent(props.contentPath, content ?? ""));
getFileContents().then((content) => editor?.setContent(contentPath, content ?? ""));
}
}, [textMode, wasOnTextMode, editor]);
}, [textMode, wasOnTextMode, editor, getFileContents, contentPath]);

// When !textMode, we should listen for changes on the diagram to update GitHub's default text editor.
useEffect(() => {
if (props.readonly || textMode || !editor) {
if (readonly || textMode || !editor) {
return;
}

Expand All @@ -106,7 +107,7 @@ const RefForwardingKogitoEditorIframe: React.ForwardRefRenderFunction<IsolatedEd
});
});
return () => editor.getStateControl().unsubscribe(stateControlSubscription);
}, [textMode, editor]);
}, [textMode, editor, readonly]);

// Forward reference methods to set content programmatically vs property
useImperativeHandle(
Expand All @@ -117,10 +118,10 @@ const RefForwardingKogitoEditorIframe: React.ForwardRefRenderFunction<IsolatedEd
}

return {
setContent: (content: string) => editor.setContent(props.contentPath, content),
setContent: (content: string) => editor.setContent(contentPath, content),
};
},
[editor]
[editor, contentPath]
);

return (
Expand All @@ -133,7 +134,7 @@ const RefForwardingKogitoEditorIframe: React.ForwardRefRenderFunction<IsolatedEd
kogitoEditor_ready={onEditorReady}
kogitoWorkspace_resourceContentRequest={onResourceContentRequest}
kogitoWorkspace_resourceListRequest={onResourceContentList}
kogitoEditor_setContentError={props.onSetContentError}
kogitoEditor_setContentError={onSetContentError}
editorEnvelopeLocator={envelopeLocator}
locale={locale}
customChannelApiImpl={customChannelApiImpl}
Expand Down
56 changes: 30 additions & 26 deletions packages/chrome-extension/src/app/components/common/KogitoMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,48 @@ export function KogitoMenu() {
const [isInfoPopOverOpen, setInfoPopOverOpen] = useState(false);
const [potentialToken, setPotentialToken] = useState("");

async function updateToken(token?: string) {
const validToken = await tokenIsValid(token);

if (validToken) {
gitHubApi.setToken(token!);
setPotentialToken("");
} else {
gitHubApi.setToken("");
}

return validToken;
}
const updateToken = useCallback(
async (token?: string) => {
const validToken = await tokenIsValid(token);
if (validToken) {
gitHubApi.setToken(token!);
setPotentialToken("");
} else {
gitHubApi.setToken("");
}
return validToken;
},
[gitHubApi]
);

useEffect(() => {
updateToken(gitHubApi.token).then(() => {
console.debug("Checked GitHub token.");
});
}, []);

const onPaste = useCallback((e) => {
const token = e.clipboardData.getData("text/plain").slice(0, GITHUB_OAUTH_TOKEN_SIZE);
setPotentialToken(token);
setTimeout(async () => {
const wasValid = await updateToken(token);
if (wasValid) {
setTimeout(() => setWholeMenuOpen(false), 2000);
}
inputRef.current!.setSelectionRange(0, 0);
}, 0);
}, []);
}, [gitHubApi.token, updateToken]);

const onPaste = useCallback(
(e) => {
const token = e.clipboardData.getData("text/plain").slice(0, GITHUB_OAUTH_TOKEN_SIZE);
setPotentialToken(token);
setTimeout(async () => {
const wasValid = await updateToken(token);
if (wasValid) {
setTimeout(() => setWholeMenuOpen(false), 2000);
}
inputRef.current!.setSelectionRange(0, 0);
}, 0);
},
[updateToken, setPotentialToken, setWholeMenuOpen]
);

const onReset = useCallback(() => {
gitHubApi.setToken("");
setPotentialToken("");
setTimeout(() => {
inputRef.current!.focus();
}, 0);
}, []);
}, [gitHubApi]);

const toggleInfoPopOver = useCallback(() => {
setInfoPopOverOpen(!isInfoPopOverOpen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export function useEffectAfterFirstRender(func: () => ReturnType<EffectCallback>
} else {
firstRender.current = false;
}
}, deps);
// Using deps as an extension mechanism to allow callers to define their own custom dependencies.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [func, ...deps]);
}

export function useIsolatedEditorTogglingEffect(
Expand All @@ -43,7 +45,7 @@ export function useIsolatedEditorTogglingEffect(
githubTextEditorToReplace.classList.add("hidden");
iframeContainer.classList.remove("hidden");
}
}, [textMode]);
}, [githubTextEditorToReplace.classList, iframeContainer.classList, textMode]);
}

export function useInitialAsyncCallEffect<T>(promise: () => Promise<T>, callback: (a: T) => void) {
Expand All @@ -60,5 +62,5 @@ export function useInitialAsyncCallEffect<T>(promise: () => Promise<T>, callback
return () => {
canceled = true;
};
}, []);
}, [callback, promise]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
import * as React from "react";
import * as ReactDOM from "react-dom";
import { Globals, Main } from "../common/Main";
import { createAndGetMainContainer, openRepoInExternalEditorContainer, removeAllChildren } from "../../utils";
import {
createAndGetMainContainer,
openRepoInExternalEditorContainer,
openRepoInExternalEditorContainerFromRepositoryHome,
removeAllChildren,
} from "../../utils";
import { OpenInExternalEditorButton } from "./OpenInExternalEditorButton";
import { GitHubPageType } from "../../github/GitHubPageType";
import {
KOGITO_IFRAME_CONTAINER_PR_CLASS,
KOGITO_OPEN_REPO_IN_EXTERNAL_EDITOR_CONTAINER_CLASS,
KOGITO_TOOLBAR_CONTAINER_PR_CLASS,
KOGITO_VIEW_ORIGINAL_LINK_CONTAINER_PR_CLASS,
} from "../../constants";
import { KOGITO_OPEN_REPO_IN_EXTERNAL_EDITOR_CONTAINER_CLASS } from "../../constants";

export function renderOpenRepoInExternalEditorApp(
args: Globals & { className: string; pageType: GitHubPageType; container: () => HTMLElement }
Expand All @@ -50,7 +50,9 @@ export function renderOpenRepoInExternalEditorApp(
>
{ReactDOM.createPortal(
<OpenInExternalEditorButton className={args.className} pageType={args.pageType} />,
openRepoInExternalEditorContainer(args.id, args.container())
GitHubPageType.REPO_HOME === args.pageType
? openRepoInExternalEditorContainerFromRepositoryHome(args.id, args.container())
: openRepoInExternalEditorContainer(args.id, args.container())
)}
</Main>,
createAndGetMainContainer(args.id, args.dependencies.all.body()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export interface PrInfo {
targetGitRef: string;
org: string;
gitRef: string;
commitSHA: string;
}

export function IsolatedPrEditor(props: {
Expand All @@ -65,18 +64,22 @@ export function IsolatedPrEditor(props: {
const [fileStatusOnPr, setFileStatusOnPr] = useState(FileStatusOnPr.UNKNOWN);

const { isolatedEditorRef } = useIsolatedEditorRef();
const originalFilePath = useMemo(() => getOriginalFilePath(props.unprocessedFilePath), []);
const modifiedFilePath = useMemo(() => getModifiedFilePath(props.unprocessedFilePath), []);
const originalFilePath = useMemo(() => getOriginalFilePath(props.unprocessedFilePath), [props.unprocessedFilePath]);
const modifiedFilePath = useMemo(() => getModifiedFilePath(props.unprocessedFilePath), [props.unprocessedFilePath]);

useIsolatedEditorTogglingEffect(
textMode,
iframeContainer(globals.id, props.prFileContainer),
props.githubTextEditorToReplace
);

useInitialAsyncCallEffect(() => {
return discoverFileStatusOnPr(githubApi.octokit(), props.prInfo, originalFilePath, modifiedFilePath);
}, setFileStatusOnPr);
useInitialAsyncCallEffect(
useCallback(
() => discoverFileStatusOnPr(githubApi.octokit(), props.prInfo, originalFilePath, modifiedFilePath),
[githubApi, props.prInfo, originalFilePath, modifiedFilePath]
),
setFileStatusOnPr
);

const closeDiagram = useCallback(() => {
setTextMode(true);
Expand All @@ -92,7 +95,7 @@ export function IsolatedPrEditor(props: {
return showOriginal || fileStatusOnPr === FileStatusOnPr.DELETED
? () => getOriginalFileContents(githubApi.octokit(), props.prInfo, originalFilePath)
: () => getModifiedFileContents(githubApi.octokit(), props.prInfo, modifiedFilePath);
}, [showOriginal, fileStatusOnPr, originalFilePath, modifiedFilePath, githubApi.octokit]);
}, [showOriginal, fileStatusOnPr, githubApi, props.prInfo, originalFilePath, modifiedFilePath]);

const shouldAddLinkToOriginalFile = useMemo(() => {
return fileStatusOnPr === FileStatusOnPr.CHANGED || fileStatusOnPr === FileStatusOnPr.DELETED;
Expand All @@ -114,7 +117,14 @@ export function IsolatedPrEditor(props: {
gitref: props.prInfo.gitRef,
repo: props.prInfo.repo,
};
}, [showOriginal]);
}, [
props.prInfo.gitRef,
props.prInfo.org,
props.prInfo.repo,
props.prInfo.targetGitRef,
props.prInfo.targetOrg,
showOriginal,
]);

const onEditorReady = useCallback(() => {
setEditorReady(true);
Expand Down Expand Up @@ -284,19 +294,11 @@ function iframeContainer(id: string, container: HTMLElement) {
}

function getModifiedFileContents(octokit: Octokit, prInfo: PrInfo, modifiedFilePath: string) {
return fetchFile(octokit, prInfo.org, prInfo.repo, prInfo.gitRef, modifiedFilePath, undefined, prInfo.commitSHA);
return fetchFile(octokit, prInfo.org, prInfo.repo, prInfo.gitRef, modifiedFilePath, undefined);
}

function getOriginalFileContents(octokit: Octokit, prInfo: PrInfo, originalFilePath: string) {
return fetchFile(
octokit,
prInfo.targetOrg,
prInfo.repo,
prInfo.targetGitRef,
originalFilePath,
undefined,
prInfo.commitSHA
);
return fetchFile(octokit, prInfo.targetOrg, prInfo.repo, prInfo.targetGitRef, originalFilePath, undefined);
}

function viewOriginalFileHref(prInfo: PrInfo, originalFilePath: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function PrEditorsApp(props: { prInfo: PrInfo }) {

useEffect(() => {
setPrFileContainers(supportedPrFileElements(globals.logger, globals.envelopeLocator, globals.dependencies));
}, []);
}, [globals.dependencies, globals.envelopeLocator, globals.logger]);

useEffect(() => {
const observer = new MutationObserver((mutations) => {
Expand All @@ -59,7 +59,7 @@ export function PrEditorsApp(props: { prInfo: PrInfo }) {
return () => {
observer.disconnect();
};
}, [prFileContainers]);
}, [globals.dependencies, globals.envelopeLocator, globals.logger, prFileContainers]);

return (
<>
Expand Down
Loading

0 comments on commit 7e9794e

Please sign in to comment.