Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/__testing__/routing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('routing utilities', () => {
expect(getShareableResourceRoute(RESOURCE_TYPE.DESIGN, 'd2', 'design')).toBe(
'http://localhost/workspace?mode=design&design=d2'
);
expect(() => getShareableResourceRoute('filter' as any, 'f1', 'filter')).toThrow(
expect(() => getShareableResourceRoute('filter' as unknown as RESOURCE_TYPE, 'f1', 'filter')).toThrow(
'Unknown resource type filter'
);
});
Expand Down
4 changes: 2 additions & 2 deletions src/actors/worker/workerfy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export const workerfyActor = (actor: AnyActorLogic) => {
}

if (event.data.type === WORKER_COMMANDS.STOP_ACTOR) {
snapshotSubscription?.unsubscribe && snapshotSubscription.unsubscribe();
actorRef?.stop && actorRef.stop();
snapshotSubscription?.unsubscribe?.();
actorRef?.stop?.();
}

if (event.data.type === WORKER_COMMANDS.SEND_EVENT) {
Expand Down
5 changes: 3 additions & 2 deletions src/base/Hidden/Hidden.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Hidden as MuiHidden, HiddenProps as MuiHiddenProps } from '@mui/material';
import React from 'react';

export const Hidden = React.forwardRef<HTMLDivElement, MuiHiddenProps>((props, ref) => {
return React.cloneElement(<MuiHidden {...props} />, { ref });
export const Hidden = React.forwardRef<HTMLDivElement, MuiHiddenProps>((props) => {
// MuiHidden doesn't support ref forwarding
return <MuiHidden {...props} />;
});

export default Hidden;
2 changes: 1 addition & 1 deletion src/custom/CatalogDesignTable/CatalogDesignTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
setPageSize(tableState.rowsPerPage);
break;
case 'search':
setSearch && setSearch(tableState.searchText !== null ? tableState.searchText : '');
setSearch?.(tableState.searchText !== null ? tableState.searchText : '');
break;
case 'sort':
if (
Expand Down
25 changes: 14 additions & 11 deletions src/custom/CatalogDetail/ChallengesSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import React, { useMemo, useState } from 'react';
import { Link, ListItemIcon } from '../../base';
import { MESHERY_CLOUD_PROD } from '../../constants/constants';
import { ChallengesIcon } from '../../icons';
Expand All @@ -14,18 +14,21 @@ interface ChallengesSectionProps {

const ChallengesSection: React.FC<ChallengesSectionProps> = ({ filteredAcademyData }) => {
const theme = useTheme();
const [openChallenges, setOpenChallenges] = useState(false);
const [autoUpdate, setAutoUpdate] = useState(true);

useEffect(() => {
if (autoUpdate) {
setOpenChallenges((filteredAcademyData?.['challenges'] ?? []).length > 0);
}
}, [filteredAcademyData, autoUpdate]);
const [userToggleValue, setUserToggleValue] = useState<boolean | null>(null);

const hasChallenges = useMemo(
() => (filteredAcademyData?.['challenges'] ?? []).length > 0,
[filteredAcademyData]
);

// Derive the open state: use user's manual toggle if set, otherwise use hasChallenges
const openChallenges = userToggleValue ?? hasChallenges;

const toggleOpenChallenges = () => {
setOpenChallenges((prev) => !prev);
setAutoUpdate(false);
setUserToggleValue((prev) => {
const currentValue = prev !== null ? prev : hasChallenges;
return !currentValue;
});
};

const renderChallengeItem = (item: string, index: number) => (
Expand Down
19 changes: 12 additions & 7 deletions src/custom/CatalogDetail/ContentClassInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ interface ContentClassInfoProps {
classes: Class[];
}

interface ClassIconProps {
className: string;
contentClass: ContentClassType;
}

const ClassIcon: React.FC<ClassIconProps> = ({ className, contentClass }) => {
const Icon = contentClass[className]?.icon;
const fill = contentClass[className]?.color;
return Icon ? <Icon width="25px" height="25px" fill={fill} /> : null;
};

const ContentClassInfo: React.FC<ContentClassInfoProps> = ({ contentClass, classes }) => {
const _classDescription = (className: string): string | undefined => {
const classObj = classes && classes.find((classObj) => classObj.class === className);
Expand All @@ -35,12 +46,6 @@ const ContentClassInfo: React.FC<ContentClassInfoProps> = ({ contentClass, class
}
} as const;

const ClassIcon: React.FC<{ className: string }> = ({ className }) => {
const Icon = CONTENT_CLASS[className]?.icon;
const fill = CONTENT_CLASS[className]?.color;
return Icon ? <Icon width="25px" height="25px" fill={fill} /> : null;
};

return (
<div>
<Box style={{ display: 'flex', alignItems: 'center', gap: '0.3rem' }}>
Expand All @@ -61,7 +66,7 @@ const ContentClassInfo: React.FC<ContentClassInfoProps> = ({ contentClass, class
fontFamily: 'inherit'
}}
>
<ClassIcon className={contentClass} />
<ClassIcon className={contentClass} contentClass={CONTENT_CLASS} />
{formatToTitleCase(contentClass)}
</ContentDetailsText>
</div>
Expand Down
25 changes: 14 additions & 11 deletions src/custom/CatalogDetail/LearningSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useMemo, useState } from 'react';
import { Link, ListItemIcon } from '../../base';
import { MESHERY_CLOUD_PROD } from '../../constants/constants';
import { LearningIcon } from '../../icons';
Expand All @@ -14,18 +14,21 @@ interface LearningSectionProps {

const LearningSection: React.FC<LearningSectionProps> = ({ filteredAcademyData }) => {
const theme = useTheme();
const [openLearning, setOpenLearning] = useState<boolean>(false);
const [autoUpdate, setAutoUpdate] = useState<boolean>(true);

useEffect(() => {
if (autoUpdate) {
setOpenLearning(Boolean((filteredAcademyData?.['learning-path'] ?? []).length > 0));
}
}, [filteredAcademyData, autoUpdate]);
const [userToggleValue, setUserToggleValue] = useState<boolean | null>(null);

const hasLearningPaths = useMemo(
() => Boolean((filteredAcademyData?.['learning-path'] ?? []).length > 0),
[filteredAcademyData]
);

// Derive the open state: use user's manual toggle if set, otherwise use hasLearningPaths
const openLearning = userToggleValue ?? hasLearningPaths;

const toggleOpenLearning = (): void => {
setOpenLearning((prev) => !prev);
setAutoUpdate(false);
setUserToggleValue((prev) => {
const currentValue = prev !== null ? prev : hasLearningPaths;
return !currentValue;
});
};

const renderLearningItem = (item: string, index: number) => (
Expand Down
27 changes: 17 additions & 10 deletions src/custom/CustomCatalog/CatalogCardDesignLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ interface CatalogCardDesignLogoProps {
style?: React.CSSProperties;
}

interface SvgComponentProps {
type: { type: string };
width: string;
height: string;
style: React.CSSProperties;
}

const SvgComponent: React.FC<SvgComponentProps> = ({ type, width, height, style }) => {
return type.type === 'filter' ? (
<MesheryFilterIcon width={width} height={height} style={style} />
) : (
<DesignIcon width={width} height={height} style={style} />
);
};

const CatalogCardDesignLogo: React.FC<CatalogCardDesignLogoProps> = ({
zoomEffect = false,
imgURL,
Expand All @@ -32,14 +47,6 @@ const CatalogCardDesignLogo: React.FC<CatalogCardDesignLogoProps> = ({
setIsZoomed(false);
};

const SvgComponent: React.FC<{ type: { type: string } }> = ({ type }) => {
return type.type === 'filter' ? (
<MesheryFilterIcon width={width} height={height} style={style} />
) : (
<DesignIcon width={width} height={height} style={style} />
);
};

return (
<>
{imgURL && imgURL.length > 0 ? (
Expand Down Expand Up @@ -82,11 +89,11 @@ const CatalogCardDesignLogo: React.FC<CatalogCardDesignLogoProps> = ({
</Dialog>
</>
) : (
<SvgComponent type={type} />
<SvgComponent type={type} width={width} height={height} style={style} />
)}
</div>
) : (
<SvgComponent type={type} />
<SvgComponent type={type} width={width} height={height} style={style} />
)}
</>
);
Expand Down
4 changes: 2 additions & 2 deletions src/custom/FlipCard/FlipCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export function FlipCard({
onClick={() => {
if (disableFlip) return;
setFlipped((flipped) => !flipped);
onClick && onClick();
onShow && onShow();
onClick?.();
onShow?.();
}}
>
<InnerCard
Expand Down
8 changes: 4 additions & 4 deletions src/custom/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ export const useModal = ({ headerIcon }: { headerIcon: React.ReactNode }): UseMo
const [reactNode, setReactNode] = useState<React.ReactNode | null>(null);

const openModal: openModalCallback = ({ title, reactNode = null, onClose }) => {
title && setTitle(title);
onClose && (onCloseRef.current = onClose);
if (title) setTitle(title);
if (onClose) onCloseRef.current = onClose;
setOpen(true);
reactNode && setReactNode(reactNode);
if (reactNode) setReactNode(reactNode);
};

const closeModal = () => {
setOpen(false);
onCloseRef.current && onCloseRef.current();
onCloseRef.current?.();
setReactNode(null);
setTitle('');
onCloseRef.current = null;
Expand Down
27 changes: 14 additions & 13 deletions src/custom/ResourceDetailFormatters/Formatter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ interface ResourceProgressProps {
type: string;
}

interface ResourceProgressWithChartProps extends ResourceProgressProps {
chartOptions: (percentage: number, type: string) => ChartOptions;
}

interface StatusColorType {
background: string;
text: string;
Expand Down Expand Up @@ -358,6 +362,13 @@ export const StatusChip = ({ status }: { status: string }) => {
);
};

const ResourceProgress: React.FC<ResourceProgressWithChartProps> = ({ title, percentage, type, chartOptions }) => (
<ResourceProgressContainer>
<Typography variant="body1">{title}</Typography>
<BBChart options={chartOptions(percentage, type)} />
</ResourceProgressContainer>
);

export const MemoryUsage: React.FC<MemoryUsageProps> = ({
allocatable,
capacity,
Expand Down Expand Up @@ -427,25 +438,15 @@ export const MemoryUsage: React.FC<MemoryUsageProps> = ({
[height, width]
);

const ResourceProgress = useCallback<React.FC<ResourceProgressProps>>(
({ title, percentage, type }) => (
<ResourceProgressContainer>
<Typography variant="body1">{title}</Typography>
<BBChart options={chartOptions(percentage, type)} />
</ResourceProgressContainer>
),
[chartOptions]
);

if (!allocatable || !capacity) {
return null;
}

return (
<FlexResourceContainer>
<ResourceProgress title="System Reserved Cpu" percentage={reservedCpu} type={'CPU'} />
<ResourceProgress title="Memory Usage" percentage={memoryUsage} type={'Memory'} />
<ResourceProgress title="Disk Usage" percentage={diskUsagePercent} type={'Disk'} />
<ResourceProgress title="System Reserved Cpu" percentage={reservedCpu} type={'CPU'} chartOptions={chartOptions} />
<ResourceProgress title="Memory Usage" percentage={memoryUsage} type={'Memory'} chartOptions={chartOptions} />
<ResourceProgress title="Disk Usage" percentage={diskUsagePercent} type={'Disk'} chartOptions={chartOptions} />
</FlexResourceContainer>
);
};
Expand Down
6 changes: 3 additions & 3 deletions src/custom/ResponsiveDataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const ResponsiveDataTable = ({
if (colToAdd) {
if (colToAdd.options) {
colToAdd.options.display = true;
updateCols && updateCols([...columns]);
updateCols?.([...columns]);
}
}
break;
Expand All @@ -189,7 +189,7 @@ const ResponsiveDataTable = ({
if (colToRemove) {
if (colToRemove.options) {
colToRemove.options.display = false;
updateCols && updateCols([...columns]);
updateCols?.([...columns]);
}
}
break;
Expand Down Expand Up @@ -236,7 +236,7 @@ const ResponsiveDataTable = ({
}
}
});
updateCols && updateCols([...columns]);
updateCols?.([...columns]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [columnVisibility, updateCols]);

Expand Down
2 changes: 1 addition & 1 deletion src/custom/ShareModal/ShareModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const AccessListActor: React.FC<AccessListActorProps> = ({
src={actorData.avatar_url}
imgProps={{ referrerPolicy: 'no-referrer' }}
onClick={() => {
hostURL && openInNewTab(`${hostURL}/user/${actorData.id}`);
if (hostURL) openInNewTab(`${hostURL}/user/${actorData.id}`);
}}
/>
</ListItemAvatar>
Expand Down
8 changes: 4 additions & 4 deletions src/custom/TeamTable/TeamTableConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export default function TeamTableConfiguration({
id={`edit_team-${tableMeta.rowIndex}`}
title="Edit Team"
onClick={(ev) => {
isEditTeamAllowed && handleTeamView(ev, tableMeta.rowData);
if (isEditTeamAllowed) handleTeamView(ev, tableMeta.rowData);
}}
iconType="edit"
>
Expand All @@ -252,9 +252,9 @@ export default function TeamTableConfiguration({
id={`remove_team-${tableMeta.rowIndex}`}
title={'Move Team'}
onClick={() => {
isRemoveTeamFromWorkspaceAllowed &&
handleRemoveTeamFromWorkspace &&
if (isRemoveTeamFromWorkspaceAllowed && handleRemoveTeamFromWorkspace) {
handleRemoveTeamFromWorkspace(tableMeta.rowData[0]);
}
}}
iconType="delete"
>
Expand All @@ -267,7 +267,7 @@ export default function TeamTableConfiguration({
id={`delete_team-${tableMeta.rowIndex}`}
title={'Delete Team'}
onClick={(ev: React.MouseEvent) => {
isDeleteTeamAllowed && handleDeleteTeam(ev, tableMeta.rowData);
if (isDeleteTeamAllowed) handleDeleteTeam(ev, tableMeta.rowData);
}}
iconType="delete"
>
Expand Down
2 changes: 1 addition & 1 deletion src/custom/TypingFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function TypingFilter({ filterSchema, handleFilter, autoFilter = false }:
/>
<Popper
open={filterState.state != FilteringState.IDLE && isPopperOpen}
anchorEl={inputFieldRef.current}
anchorEl={anchorEl}
placement="bottom-start"
style={{ zIndex: 2000 }}
transition
Expand Down
3 changes: 2 additions & 1 deletion src/custom/Workspaces/EnvironmentTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,12 @@ const EnvironmentTable: React.FC<EnvironmentTableProps> = ({
id={`delete_team-${tableMeta.rowIndex}`}
title="Remove Environment"
onClick={() => {
isRemoveAllowed &&
if (isRemoveAllowed) {
unassignEnvironmentFromWorkspace({
workspaceId,
environmentId: tableMeta.rowData[0]
});
}
}}
iconType="delete"
>
Expand Down
2 changes: 1 addition & 1 deletion src/custom/Workspaces/WorkspaceContentMoveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const WorkspaceContentMoveModal: React.FC<WorkspaceContentMoveModalProps> = ({
message: `Successfully moved ${type === RESOURCE_TYPE.DESIGN ? 'design' : 'view'}${multiSelectedContent.length > 1 ? 's' : ''} to ${selectedWorkspaceForMove!.name}`,
event_type: EVENT_TYPES.SUCCESS
});
} catch (error) {
} catch {
notify({
message: `Failed to move ${type === RESOURCE_TYPE.DESIGN ? 'design' : 'view'}. Please try again.`,
event_type: EVENT_TYPES.ERROR
Expand Down
Loading
Loading