Skip to content

Commit

Permalink
refactor(ui): replace deprecated usage of defaultProps
Browse files Browse the repository at this point in the history
- instead use default arguments

Signed-off-by: Anton Gilgur <[email protected]>
  • Loading branch information
agilgur5 committed Oct 26, 2024
1 parent 1017c1d commit adf680d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
6 changes: 1 addition & 5 deletions ui/src/app/shared/components/editors/key-value-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface KeyValues {
[key: string]: string;
}

export function KeyValueEditor({onChange, keyValues, hide}: {keyValues: KeyValues; onChange: (value: KeyValues) => void; hide?: (key: string) => boolean}) {
export function KeyValueEditor({onChange, keyValues = {}, hide}: {keyValues: KeyValues; onChange: (value: KeyValues) => void; hide?: (key: string) => boolean}) {
const [name, setName] = useState('');
const [value, setValue] = useState('');

Expand Down Expand Up @@ -62,7 +62,3 @@ export function KeyValueEditor({onChange, keyValues, hide}: {keyValues: KeyValue
</>
);
}

KeyValueEditor.defaultProps = {
keyValues: {}
};
14 changes: 6 additions & 8 deletions ui/src/app/shared/components/graph/graph-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ interface Props {
onNodeSelect?: (id: Node) => void;
}

const defaultNodeSize = 64;

const merge = (a: {[key: string]: boolean}, b: {[key: string]: boolean}) => b && Object.assign(Object.assign({}, b), a);

export function GraphPanel(props: Props) {
const storage = new ScopedLocalStorage('graph/' + props.storageScope);
const [nodeSize, setNodeSize] = useState<number>(storage.getItem('nodeSize', props.nodeSize));
const [nodeSize, setNodeSize] = useState<number>(storage.getItem('nodeSize', props.nodeSize || defaultNodeSize));
const [horizontal, setHorizontal] = useState<boolean>(storage.getItem('horizontal', !!props.horizontal));
const [fast, setFast] = useState<boolean>(storage.getItem('fast', false));
const [nodeGenres, setNodeGenres] = useState<INodeSelectionMap>(storage.getItem('nodeGenres', props.nodeGenres));
Expand All @@ -52,7 +54,7 @@ export function GraphPanel(props: Props) {
const [checkAll, setCheckAll] = useState<boolean>(true);
const [nodeSearchKeyword, setNodeSearchKeyword] = useState<string>('');

useEffect(() => storage.setItem('nodeSize', nodeSize, props.nodeSize), [nodeSize]);
useEffect(() => storage.setItem('nodeSize', nodeSize, props.nodeSize || defaultNodeSize), [nodeSize]);
useEffect(() => storage.setItem('horizontal', horizontal, props.horizontal), [horizontal]);
useEffect(() => storage.setItem('fast', fast, false), [fast]);
useEffect(() => storage.setItem('nodeGenres', nodeGenres, props.nodeGenres), [nodeGenres, props.nodeGenres]);
Expand Down Expand Up @@ -261,13 +263,13 @@ export function GraphPanel(props: Props) {
)}
<GraphIcon icon={label.icon} progress={label.progress} nodeSize={nodeSize} />
{props.hideNodeTypes || (
<text y={nodeSize * 0.33} className='type' fontSize={(12 * nodeSize) / GraphPanel.defaultProps.nodeSize}>
<text y={nodeSize * 0.33} className='type' fontSize={(12 * nodeSize) / defaultNodeSize}>
{label.genre}
</text>
)}
</g>
<g transform={`translate(0,${(nodeSize * 3) / 4})`}>
<text className='node-label' fontSize={(18 * nodeSize) / GraphPanel.defaultProps.nodeSize}>
<text className='node-label' fontSize={(18 * nodeSize) / defaultNodeSize}>
{formatLabel(label.label)}
</text>
</g>
Expand All @@ -280,7 +282,3 @@ export function GraphPanel(props: Props) {
</div>
);
}

GraphPanel.defaultProps = {
nodeSize: 64
};

0 comments on commit adf680d

Please sign in to comment.