Skip to content

Commit

Permalink
[WIFI-13259] Fixed potential crash in field explanations
Browse files Browse the repository at this point in the history
Signed-off-by: Charles <[email protected]>
  • Loading branch information
BourqueCharles committed Jan 2, 2024
1 parent 664ef73 commit 42d0c48
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 45 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wlan-cloud-owprov-ui",
"version": "3.0.0(5)",
"version": "3.0.0(6)",
"description": "",
"main": "index.tsx",
"scripts": {
Expand Down
42 changes: 0 additions & 42 deletions src/components/FormFields/ConfigurationFieldExplanation/index.jsx

This file was deleted.

51 changes: 51 additions & 0 deletions src/components/FormFields/ConfigurationFieldExplanation/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { useMemo } from 'react';
import { InfoIcon } from '@chakra-ui/icons';
import { Tooltip } from '@chakra-ui/react';
import { useAuth } from 'contexts/AuthProvider';

const findDefinition = (
definitionKey?: string,
CONFIGURATION_DESCRIPTIONS?: {
[key: string]: { properties?: { [key: string]: { description: string } } };
},
) => {
try {
if (!definitionKey || !CONFIGURATION_DESCRIPTIONS) return null;
const split = definitionKey.split('.');
const { length } = split;
if (length < 2) return null;
const start = split.slice(0, length - 1);
const end = split[length - 1];
return (
CONFIGURATION_DESCRIPTIONS[start.slice(0, length - 1).join('.')]?.properties?.[end ?? '']?.description ?? null
);
} catch (e) {
return null;
}
};

interface ConfigurationFieldExplanationProps {
definitionKey?: string;
}
const ConfigurationFieldExplanation: React.FC<ConfigurationFieldExplanationProps> = ({ definitionKey }) => {
const { configurationDescriptions } = useAuth();
const definition = useMemo(
() =>
findDefinition(
definitionKey,
configurationDescriptions as {
[key: string]: { properties: { [key: string]: { description: string } } };
},
),
[configurationDescriptions],
);
if (!definition) return null;

return (
<Tooltip hasArrow label={definition}>
<InfoIcon ml={2} mb="2px" />
</Tooltip>
);
};

export default React.memo(ConfigurationFieldExplanation);

0 comments on commit 42d0c48

Please sign in to comment.