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

refactor(ui): replace deprecated usage of defaultProps #13822

Merged
merged 1 commit into from
Oct 30, 2024
Merged
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
6 changes: 1 addition & 5 deletions ui/src/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/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
};
Loading