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

Remove react-dom/server dependency #51

Merged
merged 1 commit into from
May 8, 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect, useCallback } from 'react';
import PropTypes from 'prop-types';
import {
Progress,
Expand All @@ -12,10 +12,7 @@ import SyncAltIcon from '@patternfly/react-icons/dist/esm/icons/sync-alt-icon';
import { translate as __ } from 'foremanReact/common/I18n';

import './UtilizationProgress.scss';
import {
findLargestFittingUnit,
areReactElementsEqual,
} from '../../../../helper';
import { findLargestFittingUnit } from '../../../../helper';

const UtilizationProgress = ({
cardId,
Expand All @@ -40,7 +37,8 @@ const UtilizationProgress = ({
else if (resourceUtilizationPercent < 100) return ProgressVariant.warning;
return ProgressVariant.danger;
};
const updateResourceUtilizationView = () => {

const updateResourceUtilizationView = useCallback(() => {
let newPercent;
let newTooltipText;

Expand Down Expand Up @@ -93,13 +91,14 @@ const UtilizationProgress = ({
</div>
);
}
if (resourceUtilizationPercent !== newPercent)
setResourceUtilizationPercent(newPercent);
if (!areReactElementsEqual(resourceUtilizationTooltipText, newTooltipText))
setResourceUtilizationTooltipText(newTooltipText);
};
setResourceUtilizationPercent(newPercent);
setResourceUtilizationTooltipText(newTooltipText);
}, [isNewQuota, resourceUnits, resourceUtilization, resourceValue]);

// call it once
updateResourceUtilizationView();
useEffect(() => {
updateResourceUtilizationView();
}, [updateResourceUtilizationView]);

return (
<div>
Expand Down
14 changes: 1 addition & 13 deletions webpack/helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import ReactDOMServer from 'react-dom/server';

/**
* Performs a deep equality comparison between two objects, including nested objects and arrays.
* @param {Object} obj1 - The first object to compare.
Expand Down Expand Up @@ -37,16 +35,6 @@ const deepEqual = (obj1, obj2) => {
return true;
};

const areReactElementsEqual = (element1, element2) => {
const elementToStr = element =>
element && ReactDOMServer.renderToStaticMarkup(element);

const element1Str = elementToStr(element1);
const element2Str = elementToStr(element2);

return element1Str === element2Str;
};

/**
* Recursively copies values from the source hash (`src`) to the destination hash (`dest`).
* Only keys that are a member of dest will copied from src.
Expand Down Expand Up @@ -83,4 +71,4 @@ const findLargestFittingUnit = (value, unitList) => {
return unitList[0];
};

export { deepEqual, deepCopy, findLargestFittingUnit, areReactElementsEqual };
export { deepEqual, deepCopy, findLargestFittingUnit };
Loading