Skip to content

Conversation

@antoinebhs
Copy link
Contributor

@antoinebhs antoinebhs commented Dec 16, 2025

PR Summary

  • Add a way to see the number of variables simulated and add a limit to it (corresponding to our current memory sizing)
  • Result/variable count are now displayed at the same levels as the tabs to make it understandable that it corresponds to all tabs.
  • Simplify the logic to compute the number of results/variables :
    • remove the concept of having a count per tab, on parameter change recompute all the variables/results count. It does not add much overhead given that we use batch endpoints in filter server and actions server which loads the network only once in memory
    • given this, we just need to recompute the counts when the parameters changes (loading parameters/changing user input)
    • remove unused code due to previous logic

@antoinebhs antoinebhs force-pushed the change-factor-count-calculation branch from e559374 to a14074e Compare December 16, 2025 10:04
Comment on lines 34 to 37
export interface FactorsCount {
resultCount: number;
variableCount: number;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

not really a constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

);
};

export const useFactorCountDisplay = (count: number, maxCount: number, messageId: string, launchLoader: boolean) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

launchLoader -> isLoading ?
I saw it's base on old code though, no need to change it here I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let's change it :)

);
};

export const useFactorCountDisplay = (count: number, maxCount: number, messageId: string, launchLoader: boolean) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

hook returning JSX ?
make this file a component instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

)
.map((entry) => entry[COUNT])
.reduce((a, b) => a + b, 0);
const getFactorsCount = useCallback(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const getFactorsCount = useCallback(() => {
const updateFactorCount = useCallback(() => {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

const [sensitivityAnalysisParams, setSensitivityAnalysisParams] = useState(params);
const { snackError } = useSnackMessage();
const [analysisComputeComplexity, setAnalysisComputeComplexity] = useState(0);
const [factorsCount, setFactorsCount] = useState<FactorsCount>({ resultCount: 0, variableCount: 0 });
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const [factorsCount, setFactorsCount] = useState<FactorsCount>({ resultCount: 0, variableCount: 0 });
const [factorsCount, setFactorsCount] = useState<FactorsCount>(DEFAULT_FACTOR_COUNT);

Then reuse it at line 169

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

formatNewParams(filteredFormValues)
)
.then((response) => {
response.text().then((value: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

make this transformation in getSensitivityAnalysisFactorsCount directly to prevent promise chaining here
use backendFetchText ?

You could even use backendFetchJson so you don't have to parse it yourself

I'm confused that you need to parseInt yourself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed! I did not change the existing code (https://github.com/gridsuite/commons-ui/pull/967/changes#diff-17f4a437a70614bc66b84276022b6e01a917a2dba012ad66966df80c6d78128bL236-L242) but I really don't know why we went that way... Fixed in 6681389

Comment on lines 238 to 241
const timeoutId = setTimeout(() => {
setLaunchLoader(false);
}, 500);
return () => clearTimeout(timeoutId);
Copy link
Contributor

Choose a reason for hiding this comment

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

as discussed, this is weird, but we'll leave it since it was here before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, probably need some ref/use effect to increase robustness...

@antoinebhs antoinebhs force-pushed the change-factor-count-calculation branch from f184871 to b18f0af Compare December 18, 2025 13:53
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
8.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants