Skip to content

Commit

Permalink
OSN-549. Refactor PoolLink component to fix navigation
Browse files Browse the repository at this point in the history
- Simplified the getUrl function by removing the organizationId parameter.
- Updated the onClick handler in PoolLink to navigate directly if organizationId is not provided, or update the scope with organizationId and redirect URL if it is.
  • Loading branch information
ek-hystax authored Jan 13, 2025
1 parent 463f03b commit 5472045
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions ngui/ui/src/components/PoolLabel/PoolLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
import Link from "@mui/material/Link";
import { FormattedMessage } from "react-intl";
import { useNavigate } from "react-router-dom";
import IconLabel from "components/IconLabel";
import PoolTypeIcon from "components/PoolTypeIcon";
import SlicedText from "components/SlicedText";
import { useUpdateScope } from "hooks/useUpdateScope";
import { getPoolUrl, isPoolIdWithSubPools } from "urls";
import { formQueryString } from "utils/network";

const SLICED_POOL_NAME_LENGTH = 35;

const getUrl = (poolId: string, organizationId: string) => {
const getUrl = (poolId: string) => {
// TODO: remove this after https://datatrendstech.atlassian.net/browse/OS-4157
const poolIdWithoutSubPoolMark = isPoolIdWithSubPools(poolId) ? poolId.slice(0, poolId.length - 1) : poolId;
const baseUrl = getPoolUrl(poolIdWithoutSubPoolMark);
return organizationId ? `${baseUrl}&${formQueryString({ organizationId })}` : baseUrl;

return getPoolUrl(poolIdWithoutSubPoolMark);
};

const SlicedPoolName = ({ name }) => <SlicedText limit={SLICED_POOL_NAME_LENGTH} text={name} />;

const PoolLink = ({ id, name, dataTestId, organizationId }) => {
const updateScope = useUpdateScope();
const navigate = useNavigate();

return (
<Link
component="button"
onClick={() => {
updateScope({
newScopeId: organizationId,
redirectTo: getUrl(id, organizationId)
});
const url = getUrl(id);
if (organizationId) {
updateScope({
newScopeId: organizationId,
redirectTo: url
});
} else {
navigate(url);
}
}}
data-test-id={dataTestId}
>
Expand Down

0 comments on commit 5472045

Please sign in to comment.