Skip to content

Commit

Permalink
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/s…
Browse files Browse the repository at this point in the history
…earch-ds
  • Loading branch information
AmanAgarwal041 committed Jan 8, 2025
2 parents 23a91a2 + 5978a96 commit aa2489b
Show file tree
Hide file tree
Showing 19 changed files with 693 additions and 104 deletions.
65 changes: 31 additions & 34 deletions app/client/packages/design-system/ads/src/List/List.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useState } from "react";
import clsx from "classnames";

import type { ListItemProps, ListProps } from "./List.types";
Expand All @@ -22,6 +22,7 @@ import {
ListItemTextOverflowClassName,
ListItemTitleClassName,
} from "./List.constants";
import { useEventCallback } from "usehooks-ts";

function List({ className, items, ...rest }: ListProps) {
return (
Expand All @@ -34,39 +35,30 @@ function List({ className, items, ...rest }: ListProps) {
}

function TextWithTooltip(props: TextProps & { isMultiline?: boolean }) {
const ref = React.useRef<HTMLDivElement>(null);
const [disableTooltip, setDisableTooltip] = useState(true);

const isEllipsisActive = () => {
let active = false;

if (ref.current) {
const text_node = ref.current.children[0];

if (props.isMultiline) {
active = text_node && text_node.clientHeight < text_node.scrollHeight;
} else {
active = text_node && text_node.clientWidth < text_node.scrollWidth;
const handleShowFullText = useEventCallback(
(e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
let isInEllipsis = false;
const text_node = e.target;

if (text_node instanceof HTMLElement) {
if (props.isMultiline) {
isInEllipsis =
text_node && text_node.clientHeight < text_node.scrollHeight;
} else {
isInEllipsis =
text_node && text_node.clientWidth < text_node.scrollWidth;
}
}
}

setDisableTooltip(!active);
};

useEffect(() => {
if (ref.current) {
isEllipsisActive();
ref.current.addEventListener("mouseover", isEllipsisActive);

return () => {
ref.current?.removeEventListener("mouseover", isEllipsisActive);
};
}
}, []);
setDisableTooltip(!isInEllipsis);
},
);

return (
<Tooltip content={props.children} isDisabled={disableTooltip}>
<TooltipTextWrapper ref={ref}>
<TooltipTextWrapper onMouseOver={handleShowFullText}>
<Text
{...props}
className={clsx(ListItemTextOverflowClassName, props.className)}
Expand All @@ -92,28 +84,33 @@ function ListItem(props: ListItemProps) {
const isBlockDescription = descriptionType === "block" && description;
const isInlineDescription = descriptionType === "inline" && description;

const handleOnClick = () => {
const handleOnClick = useEventCallback((e: React.MouseEvent) => {
e.stopPropagation();

if (!props.isDisabled && props.onClick) {
props.onClick();
props.onClick(e);
}
};
});

const handleDoubleClick = useEventCallback((e: React.MouseEvent) => {
e.stopPropagation();

const handleDoubleClick = () => {
if (!props.isDisabled && props.onDoubleClick) {
props.onDoubleClick();
}
};
});

const handleRightControlClick = (e: React.MouseEvent) => {
const handleRightControlClick = useEventCallback((e: React.MouseEvent) => {
e.stopPropagation();
};
});

return (
<StyledListItem
className={clsx(ListItemClassName, props.className)}
data-disabled={props.isDisabled || false}
data-rightcontrolvisibility={rightControlVisibility}
data-selected={props.isSelected}
id={props.id}
onClick={handleOnClick}
onDoubleClick={handleDoubleClick}
role="listitem"
Expand Down
4 changes: 2 additions & 2 deletions app/client/packages/design-system/ads/src/List/List.types.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Sizes } from "../__config__/types";
import type { ReactNode } from "react";
import type { MouseEvent, ReactNode } from "react";

export type ListSizes = Extract<Sizes, "md" | "lg">;

Expand All @@ -11,7 +11,7 @@ export interface ListItemProps {
/** Control the visibility trigger of right control */
rightControlVisibility?: "hover" | "always";
/** callback for when the list item is clicked */
onClick: () => void;
onClick: (e: MouseEvent) => void;
/** callback for when the list item is double-clicked */
onDoubleClick?: () => void;
/** Whether the list item is disabled. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe("useEditableText", () => {
act(() => {
handleKeyUp({
key: "Enter",
stopPropagation: jest.fn(),
} as unknown as React.KeyboardEvent<HTMLInputElement>);
});

Expand Down Expand Up @@ -113,6 +114,7 @@ describe("useEditableText", () => {
act(() => {
handleKeyUp({
key: "Enter",
stopPropagation: jest.fn(),
} as unknown as React.KeyboardEvent<HTMLInputElement>);
});

Expand All @@ -134,7 +136,10 @@ describe("useEditableText", () => {
const [, , , handleKeyUp] = result.current;

act(() => {
handleKeyUp({ key: "Escape" } as React.KeyboardEvent<HTMLInputElement>);
handleKeyUp({
key: "Escape",
stopPropagation: jest.fn(),
} as unknown as React.KeyboardEvent<HTMLInputElement>);
});

expect(mockExitEditing).toHaveBeenCalled();
Expand All @@ -155,7 +160,10 @@ describe("useEditableText", () => {
const [, , , handleKeyUp] = result.current;

act(() => {
handleKeyUp({ key: "Enter" } as React.KeyboardEvent<HTMLInputElement>);
handleKeyUp({
key: "Enter",
stopPropagation: jest.fn(),
} as unknown as React.KeyboardEvent<HTMLInputElement>);
});

expect(mockExitEditing).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export function useEditableText(
]);

const handleKeyUp = useEventCallback((e: KeyboardEvent<HTMLInputElement>) => {
e.stopPropagation();

if (e.key === "Enter") {
attemptSave();
} else if (e.key === "Escape") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const Template = (props: EntityItemProps) => {
<ExplorerContainer borderRight="STANDARD" height="500px" width="255px">
<Flex flexDirection="column" gap="spaces-2" p="spaces-3">
<EntityItem
id="storyItem"
onDoubleClick={() => {
setIsEditing(true);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ListItem, Spinner, Tooltip } from "../../..";
import type { EntityItemProps } from "./EntityItem.types";
import { EntityEditableName } from "./EntityItem.styles";
import { useEditableText } from "../Editable";
import clx from "classnames";

export const EntityItem = (props: EntityItemProps) => {
const {
Expand Down Expand Up @@ -77,7 +78,10 @@ export const EntityItem = (props: EntityItemProps) => {
return (
<ListItem
{...props}
className={clx("t--entity-item", props.className)}
customTitleComponent={customTitle}
data-testid={`t--entity-item-${props.title}`}
id={"entity-" + props.id}
startIcon={startIcon}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export interface EntityItemProps
ListItemProps,
"customTitleComponent" | "description" | "descriptionType"
> {
/** ID of the entity. Will be added to the markup for identification */
id: string;
/** Control the name editing behaviour */
nameEditorConfig: {
// Set editable based on user permissions
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/constants/WidgetConstants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const MODAL_PORTAL_CLASSNAME = "bp3-modal-widget";
export const MODAL_PORTAL_OVERLAY_CLASSNAME = "bp3-overlay-zindex";
export const CANVAS_SELECTOR = "canvas";

export const DEFAULT_CENTER = { lat: -34.397, lng: 150.644 };
export const DEFAULT_CENTER = { lat: 40.7128, lng: -74.006 };

export enum FontStyleTypes {
BOLD = "BOLD",
Expand Down
4 changes: 2 additions & 2 deletions app/client/src/widgets/MapWidget/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class MapWidget extends BaseWidget<MapWidgetProps, WidgetState> {
zoomLevel: 50,
enablePickLocation: true,
allowZoom: true,
mapCenter: { lat: 25.122, long: 50.132 },
defaultMarkers: [{ lat: 25.122, long: 50.132, title: "Location1" }],
mapCenter: { lat: 40.7128, long: -74.006 },
defaultMarkers: [{ lat: 40.7128, long: -74.006, title: "New York" }],
isClickedMarkerCentered: true,
version: 1,
animateLoading: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.appsmith.external.dtos.MergeStatusDTO;
import com.appsmith.external.git.constants.GitSpan;
import com.appsmith.external.git.constants.ce.RefType;
import com.appsmith.external.git.dtos.FetchRemoteDTO;
import com.appsmith.external.git.handler.FSGitHandler;
import com.appsmith.external.helpers.Stopwatch;
import com.appsmith.git.configurations.GitServiceConfig;
Expand All @@ -33,7 +34,6 @@
import org.eclipse.jgit.api.ResetCommand;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.TransportConfigCallback;
import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.BranchTrackingStatus;
import org.eclipse.jgit.lib.PersonIdent;
Expand All @@ -42,6 +42,7 @@
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.TagOpt;
import org.eclipse.jgit.util.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.FileSystemUtils;
Expand Down Expand Up @@ -92,6 +93,11 @@ public class FSGitHandlerCEImpl implements FSGitHandler {

private final Scheduler scheduler = Schedulers.boundedElastic();

private static final String BRANCH_REF_REMOTE_SRC = "refs/heads/";
private static final String BRANCH_REF_LOCAL_DST = "refs/remotes/origin/";
private static final String SRC_DST_DELIMITER = ":";
private static final String TAG_REF = "refs/tags/";

private static final String SUCCESS_MERGE_STATUS = "This branch has no conflicts with the base branch.";

/**
Expand Down Expand Up @@ -846,15 +852,14 @@ public Mono<String> mergeBranch(Path repoSuffix, String sourceBranch, String des
git -> Mono.fromCallable(() -> {
Stopwatch processStopwatch = StopwatchHelpers.startStopwatch(
repoSuffix, AnalyticsEvents.GIT_MERGE.getEventName());
log.debug(Thread.currentThread().getName() + ": Merge branch " + sourceBranch
+ " on " + destinationBranch);
try {
// checkout the branch on which the merge command is run
git.checkout()
.setName(destinationBranch)
.setCreateBranch(false)
.call();

log.info(
"{}: Merge branch {} on {}",
Thread.currentThread().getName(),
sourceBranch,
destinationBranch);

try {
MergeResult mergeResult = git.merge()
.include(git.getRepository().findRef(sourceBranch))
.setStrategy(MergeStrategy.RECURSIVE)
Expand Down Expand Up @@ -934,9 +939,7 @@ public Mono<String> fetchRemote(

@Override
public Mono<String> fetchRemote(
Path repoSuffix, String publicKey, String privateKey, boolean isRepoPath, String... branchNames) {
Stopwatch processStopwatch =
StopwatchHelpers.startStopwatch(repoSuffix, AnalyticsEvents.GIT_FETCH.getEventName());
Path repoSuffix, boolean isRepoPath, FetchRemoteDTO fetchRemoteDTO, String publicKey, String privateKey) {
Path repoPath = TRUE.equals(isRepoPath) ? repoSuffix : createRepoPath(repoSuffix);
return Mono.using(
() -> Git.open(repoPath.toFile()),
Expand All @@ -945,21 +948,35 @@ public Mono<String> fetchRemote(
new SshTransportConfigCallback(privateKey, publicKey);
String fetchMessages;

List<String> refNames = fetchRemoteDTO.getRefNames();
RefType refType = fetchRemoteDTO.getRefType();

List<RefSpec> refSpecs = new ArrayList<>();
for (String branchName : branchNames) {
RefSpec ref = new RefSpec(
"refs/heads/" + branchName + ":refs/remotes/origin/" + branchName);
refSpecs.add(ref);
if (RefType.tag.equals(refType)) {
for (String tagName : refNames) {
RefSpec refSpec = new RefSpec(TAG_REF + tagName + ":" + TAG_REF + tagName);
refSpecs.add(refSpec);
}
} else {
for (String refName : refNames) {
RefSpec ref = new RefSpec(BRANCH_REF_REMOTE_SRC
+ refName
+ SRC_DST_DELIMITER
+ BRANCH_REF_LOCAL_DST
+ refName);
refSpecs.add(ref);
}
}

fetchMessages = git.fetch()
.setRefSpecs(refSpecs.toArray(new RefSpec[0]))
.setRemoveDeletedRefs(true)
.setTagOpt(TagOpt.NO_TAGS) // no tags would mean that tags are fetched
// explicitly
.setTransportConfigCallback(config)
.call()
.getMessages();

processStopwatch.stopAndLogTimeInMillis();
return fetchMessages;
})
.onErrorResume(error -> {
Expand All @@ -980,30 +997,13 @@ public Mono<MergeStatusDTO> isMergeBranch(Path repoSuffix, String sourceBranch,
return Mono.using(
() -> Git.open(createRepoPath(repoSuffix).toFile()),
git -> Mono.fromCallable(() -> {
log.debug(
Thread.currentThread().getName()
+ ": Check mergeability for repo {} with src: {}, dest: {}",
log.info(
"{}: Check merge-ability for repo {} with source: {}, destination: {}",
Thread.currentThread().getName(),
repoSuffix,
sourceBranch,
destinationBranch);

// checkout the branch on which the merge command is run
try {
git.checkout()
.setName(destinationBranch)
.setCreateBranch(false)
.call();
} catch (GitAPIException e) {
if (e instanceof CheckoutConflictException) {
MergeStatusDTO mergeStatus = new MergeStatusDTO();
mergeStatus.setMergeAble(false);
mergeStatus.setConflictingFiles(
((CheckoutConflictException) e).getConflictingPaths());
processStopwatch.stopAndLogTimeInMillis();
return mergeStatus;
}
}

MergeResult mergeResult = git.merge()
.include(git.getRepository().findRef(sourceBranch))
.setFastForward(MergeCommand.FastForwardMode.NO_FF)
Expand Down Expand Up @@ -1054,6 +1054,19 @@ public Mono<MergeStatusDTO> isMergeBranch(Path repoSuffix, String sourceBranch,
return Mono.error(e);
}
})
.onErrorResume(error -> {
MergeStatusDTO mergeStatusDTO = new MergeStatusDTO();
mergeStatusDTO.setMergeAble(false);
mergeStatusDTO.setMessage(error.getMessage());
mergeStatusDTO.setReferenceDoc(ErrorReferenceDocUrl.GIT_MERGE_CONFLICT.getDocUrl());
try {
return resetToLastCommit(repoSuffix, destinationBranch)
.thenReturn(mergeStatusDTO);
} catch (GitAPIException | IOException e) {
log.error("Error while hard resetting to latest commit {0}", e);
return Mono.error(e);
}
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)),
Git::close)
.subscribeOn(scheduler);
Expand Down
Loading

0 comments on commit aa2489b

Please sign in to comment.