Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
90 changes: 90 additions & 0 deletions app/client/src/ce/pages/Applications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
MenuItem as ListItem,
Text,
TextType,
FontWeight,
} from "@appsmith/ads-old";
import { loadingUserWorkspaces } from "pages/Applications/ApplicationLoaders";
import PageWrapper from "pages/common/PageWrapper";
Expand Down Expand Up @@ -395,6 +396,59 @@ export const textIconStyles = (props: { color: string; hover: string }) => {
`;
};

const WorkspaceItemRow = styled.a<{ disabled?: boolean; selected?: boolean }>`
display: flex;
align-items: center;
justify-content: space-between;
text-decoration: none;
padding: 0px var(--ads-spaces-6);
background-color: ${(props) =>
props.selected ? "var(--ads-v2-color-bg-muted)" : "transparent"};
.${Classes.TEXT} {
color: var(--ads-v2-color-fg);
}
.${Classes.ICON} {
svg {
path {
fill: var(--ads-v2-color-fg);
}
}
}
height: 38px;

${(props) =>
!props.disabled
? `
&:hover {
text-decoration: none;
cursor: pointer;
background-color: var(--ads-v2-color-bg-subtle);
border-radius: var(--ads-v2-border-radius);
}`
: `
&:hover {
text-decoration: none;
cursor: default;
}
`}
`;

const WorkspaceIconContainer = styled.span`
display: flex;
align-items: center;

.${Classes.ICON} {
margin-right: var(--ads-spaces-5);
}
`;

const WorkspaceLogoImage = styled.img`
width: 20px;
height: 20px;
object-fit: contain;
margin-right: var(--ads-spaces-5);
`;

export function WorkspaceMenuItem({
isFetchingWorkspaces,
selected,
Expand All @@ -403,6 +457,7 @@ export function WorkspaceMenuItem({
}: any) {
const history = useHistory();
const location = useLocation();
const [imageError, setImageError] = React.useState(false);

const handleWorkspaceClick = () => {
const workspaceId = workspace?.id;
Expand All @@ -414,8 +469,43 @@ export function WorkspaceMenuItem({
}
};

const handleImageError = () => {
setImageError(true);
};

if (!workspace.id) return null;

const hasLogo = workspace?.logoUrl && !imageError;
const displayText = isFetchingWorkspaces
? workspace?.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the workspaces are still being fetched, where would you obtain the workspace name? Wouldn't this be undefined in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rahulbarwal It should not be undefined. Based on everything I can see, the name comes from the getFetchedWorkspaces. Initially, the workspaces array is empty and isFetchingWorkspaces is true. Nothing would show up. While refreshing, it may contain older data - but then when done fetching, it will refresh over it. In the initial state, it all should be safe

: workspace?.name?.length > 22
? workspace.name.slice(0, 22).concat(" ...")
: workspace?.name;

// Use custom component when there's a logo, otherwise use ListItem
if (hasLogo && !isFetchingWorkspaces) {
return (
<Tooltip content={workspace?.name} placement="bottomLeft">
<WorkspaceItemRow
className={selected ? "selected-workspace" : ""}
onClick={handleWorkspaceClick}
selected={selected}
>
<WorkspaceIconContainer>
<WorkspaceLogoImage
alt={`${workspace.name} logo`}
onError={handleImageError}
src={workspace.logoUrl}
/>
<Text type={TextType.H5} weight={FontWeight.NORMAL}>
{displayText}
</Text>
</WorkspaceIconContainer>
</WorkspaceItemRow>
</Tooltip>
);
}

return (
<ListItem
className={selected ? "selected-workspace" : ""}
Expand Down
15 changes: 15 additions & 0 deletions app/client/src/ce/reducers/uiReducers/workspaceReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ export const handlers = {

draftState.loadingStates.isSavingWorkspaceInfo = false;
draftState.list = [...workspaces];

// Also update searchEntities if they exist to keep search results in sync
if (draftState.searchEntities?.workspaces) {
const searchWorkspaceIndex =
draftState.searchEntities.workspaces.findIndex(
(workspace: Workspace) => workspace.id === action.payload.id,
);

if (searchWorkspaceIndex !== -1) {
draftState.searchEntities.workspaces[searchWorkspaceIndex] = {
...draftState.searchEntities.workspaces[searchWorkspaceIndex],
...action.payload,
};
}
}
},
[ReduxActionErrorTypes.SAVE_WORKSPACE_ERROR]: (
draftState: WorkspaceReduxState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public static String toSlug(String text) {

@JsonView(Views.Public.class)
public String getLogoUrl() {
// If there's no logo, return null instead of constructing a URL like "/api/v1/assets/null"
// This prevents the frontend from making pointless requests to load a non-existent image
if (logoAssetId == null || logoAssetId.isEmpty()) {
return null;
}
return Url.ASSET_URL + "/" + logoAssetId;
}

Expand Down