Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add deplinking and collapse expand support for meshery ui #879

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
37 changes: 31 additions & 6 deletions src/custom/ResourceDetailFormatters/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import UnfoldLessIcon from '@mui/icons-material/UnfoldLess';
import UnfoldMoreIcon from '@mui/icons-material/UnfoldMore';
import React, { useState } from 'react';
import { Grid, IconButton, Typography } from '../../base';
import { iconSmall } from '../../constants/iconsSizes';
import { iconSmall, iconXSmall } from '../../constants/iconsSizes';
import { CopyIcon } from '../../icons';
import { useTheme } from '../../theme';
import { CustomTooltip } from './../CustomTooltip';
Expand Down Expand Up @@ -29,7 +31,7 @@ import {
PrimaryDetailsProps,
SectionHeadingProps
} from './types';
import { splitCamelCaseString } from './utils.js';
import { splitCamelCaseString } from './utils';

export const PrimaryDetails: React.FC<PrimaryDetailsProps> = ({ title, value, hide = false }) => {
const titleFormatted = splitCamelCaseString(title);
Expand Down Expand Up @@ -151,16 +153,39 @@ export const ActionIconButton: React.FC<ActionIconButtonProps> = ({ title, Icon,
);
};

export const KeyValueInRow: React.FC<KeyValueProps> = ({ Key, Value }) => {
export const KeyValueInRow: React.FC<KeyValueProps> = ({ Key, Value, showFold = false }) => {
const [isFolded, setIsFolded] = useState(true);

if (!Value || !Key) return null;

const handleToggleFold = () => {
setIsFolded(!isFolded);
};

return (
<KeyValueGrid container>
<React.Fragment key={Key}>
<KeyValueGridCell item xs={3}>
<KeyValueGridCell container xs={3} spacing={1}>
<KeyValueGridTitle>{Key}</KeyValueGridTitle>
{showFold && (
<IconButton onClick={handleToggleFold}>
{isFolded ? (
<UnfoldMoreIcon style={iconXSmall} />
) : (
<UnfoldLessIcon style={iconXSmall} />
)}
</IconButton>
)}
</KeyValueGridCell>
<Grid item xs={9}>
<div>{React.isValidElement(Value) ? Value : String(Value)}</div>
<div
style={{
maxHeight: showFold && isFolded ? '200px' : 'none',
overflow: showFold ? 'auto' : 'none'
}}
>
{React.isValidElement(Value) ? Value : String(Value)}
</div>
</Grid>
</React.Fragment>
</KeyValueGrid>
Expand Down
3 changes: 2 additions & 1 deletion src/custom/ResourceDetailFormatters/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,6 @@ export const KeyValueGridTitle = styled(Typography)({
});

export const KeyValueGridCell = styled(Grid)({
placeSelf: 'center'
placeSelf: 'center',
alignItems: 'center'
});
2 changes: 2 additions & 0 deletions src/custom/ResourceDetailFormatters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface ActionIconButtonProps {
export interface KeyValueProps {
Key: string;
Value: string | number | ReactNode;
showFold?: boolean;
}

export interface EnvironmentFormatterProps {
Expand Down Expand Up @@ -264,4 +265,5 @@ export interface GetResourceCleanDataProps {
dispatchMsgToEditor?: (msg: any) => void;
activeLabels?: string[];
showStatus?: boolean;
router?: any;
}
8 changes: 7 additions & 1 deletion src/custom/ResourceDetailFormatters/useResourceCleanData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const useResourceCleanData = () => {
resource,
activeLabels,
dispatchMsgToEditor,
router,
showStatus = true
}: GetResourceCleanDataProps) => {
const parsedStatus = resource?.status?.attribute && JSON.parse(resource?.status?.attribute);
Expand Down Expand Up @@ -108,8 +109,13 @@ export const useResourceCleanData = () => {
links: [
{ nodeName: parsedSpec?.nodeName, label: 'Node' },
{ namespace: resource?.metadata?.namespace, label: 'Namespace' },
{ serviceAccount: parsedSpec?.serviceAccountName, label: 'ServiceAccount' }
{
serviceAccount: parsedSpec?.serviceAccountName,
label: 'ServiceAccount',
resourceCategory: 'Security'
Comment on lines +113 to +115
Copy link
Member

Choose a reason for hiding this comment

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

@amitamrutiya, this behavior should be defined as a modifier of the component's schema/definition and included in the respective model, not centrally embedded.

We should have precedent for this in terms of ui schema. Is that right, @Yashsharma1911 @aabidsofi19?

}
],
router: router,
dispatchMsgToEditor: dispatchMsgToEditor
},
selector: parsedSpec?.selector?.matchLabels
Expand Down
Loading