-
Notifications
You must be signed in to change notification settings - Fork 20
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
Added support for boundary filters in kibana dashboard #1729
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,33 @@ const IFrameInterface = (props) => { | |
enabled: true, | ||
}); | ||
|
||
function addBoundaryFilters(url, filters) { | ||
const { province, district } = filters || {}; | ||
|
||
// Determine filter type based on district and province | ||
const filter = district | ||
? `(query:(match_phrase:(Data.boundaryHierarchy.district.keyword:'${district}')))` | ||
: province | ||
? `(query:(match_phrase:(Data.boundaryHierarchy.province.keyword:'${province}')))` | ||
: null; | ||
|
||
// If there's a filter to apply | ||
if (filter) { | ||
// Match existing filters in the URL | ||
const existingFilters = /filters:\!\((.*?)\)/.exec(url); | ||
|
||
// Replace existing filters or append the new filter | ||
const updatedUrl = existingFilters | ||
? url.replace(existingFilters[0], `filters:!(${filter})`).replace(/ /g, '%20') | ||
: url; | ||
|
||
setUrl(updatedUrl); | ||
} else { | ||
// No filter to add, keep original URL | ||
setUrl(url); | ||
} | ||
} | ||
|
||
const injectCustomHttpInterceptors = (iframeWindow) => { | ||
// console.log("iframeInInterceptor",iframeWindow) | ||
const injectCustomHttpInterceptor = () => { | ||
|
@@ -173,6 +200,7 @@ const IFrameInterface = (props) => { | |
: ""; | ||
const title = pageObject?.["title"] || ""; | ||
let url = `${domain}${contextPath}`; | ||
addBoundaryFilters(url, filters?.filters); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve error handling and state management for boundary filter integration The current integration has potential issues:
Consider refactoring the URL construction logic: - addBoundaryFilters(url, filters?.filters);
+ try {
+ // Combine URL modifications to avoid multiple state updates
+ let processedUrl = url;
+ if (filters?.filters) {
+ processedUrl = addBoundaryFilters(processedUrl, filters.filters);
+ }
+ if (pageObject?.authToken?.enable) {
+ processedUrl = addAuthToken(processedUrl, pageObject.authToken);
+ }
+ setUrl(processedUrl);
+ } catch (error) {
+ console.error('Error processing URL with filters:', error);
+ setUrl(url);
+ } Also, consider extracting the URL processing logic into a separate useCallback hook to better manage dependencies and prevent unnecessary re-renders.
|
||
if (pageObject?.authToken && pageObject?.authToken?.enable) { | ||
const authKey = pageObject?.authToken?.key || "auth-token"; | ||
if (pageObject?.authToken?.customFun && Digit.Utils.createFunction(pageObject?.authToken?.customFun)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Consider architectural improvements for boundary filter feature
To enhance maintainability and reliability:
Would you like me to:
Also applies to: 203-203
Add input validation and security measures to
addBoundaryFilters
The function needs several security and robustness improvements:
Consider applying these improvements:
📝 Committable suggestion