-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
72 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
apis/nucleus/src/components/listbox/hooks/useFrequencyMax.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { getFrequencyMax, neetToFetchFrequencyMax } from '../utils/frequencyMaxUtil'; | ||
|
||
const useFrequencyMax = (app, layout) => { | ||
const [frequencyMax, setFrequencyMax] = useState(); | ||
|
||
const needFetch = neetToFetchFrequencyMax(layout); | ||
|
||
useEffect(() => { | ||
if (!needFetch) { | ||
return; | ||
} | ||
const fetch = async () => { | ||
const newValue = await getFrequencyMax(layout, app); | ||
setFrequencyMax(newValue); | ||
}; | ||
fetch(); | ||
}, [needFetch && layout]); | ||
|
||
return needFetch ? frequencyMax : layout?.frequencyMax; | ||
}; | ||
|
||
export default useFrequencyMax; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
apis/nucleus/src/components/listbox/utils/frequencyMaxUtil.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const escapeField = (field) => { | ||
if (!field) { | ||
return field; | ||
} | ||
return `${field.replace(/\]/g, ']]')}`; | ||
}; | ||
|
||
export const neetToFetchFrequencyMax = (layout) => layout?.frequencyMax === 'fetch'; | ||
|
||
export const getFrequencyMaxExpression = (field) => { | ||
const escapedField = escapeField(field); | ||
return `Max(AGGR(Count(${escapedField}), ${escapedField}))`; | ||
}; | ||
|
||
export const getFrequencyMax = async (layout, app) => { | ||
const dimInfo = layout.qListObject.qDimensionInfo; | ||
const field = dimInfo.qGroupFieldDefs[dimInfo.qGroupPos]; | ||
const expression = getFrequencyMaxExpression(field); | ||
const evaluadedExpression = await app.evaluateEx(expression); | ||
return evaluadedExpression.qNumber; | ||
}; |