Skip to content

Commit

Permalink
Merge pull request #1373 from bcgov/feat/hamed-improve-number-filteri…
Browse files Browse the repository at this point in the history
…ng-1350

Feat: Implement startsWith Filter for Number Columns - 1350
  • Loading branch information
hamed-valiollahi authored Dec 9, 2024
2 parents 8e4aa91 + eadb9b0 commit f2e379b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 28 deletions.
1 change: 1 addition & 0 deletions backend/lcfs/web/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def apply_number_filter_conditions(field, filter_value, filter_option):
"greaterThanOrEqual": field >= filter_value,
"lessThan": field < filter_value,
"lessThanOrEqual": field <= filter_value,
"startsWith": cast(field, String).like(f"{filter_value}%"),
}
return number_filter_mapping.get(filter_option)

Expand Down
2 changes: 1 addition & 1 deletion backend/lcfs/web/api/fuel_code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""User API."""
"""Fuel code API."""

from lcfs.web.api.fuel_code.views import router

Expand Down
14 changes: 12 additions & 2 deletions frontend/src/views/Admin/AdminMenu/components/_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ export const userLoginHistoryColDefs = (t) => [
{
field: 'userLoginHistoryId',
headerName: t('admin:userLoginHistoryColLabels.userLoginHistoryId'),
cellDataType: 'number'
cellDataType: 'number',
filter: 'agNumberColumnFilter',
filterParams: {
filterOptions: ['startsWith'],
buttons: ['clear']
}
},
{
field: 'keycloakEmail',
Expand Down Expand Up @@ -230,7 +235,12 @@ export const auditLogColDefs = (t) => [
headerName: t('admin:auditLogColLabels.rowId'),
minWidth: 100,
sortable: true,
filter: 'agTextColumnFilter'
cellDataType: 'number',
filter: 'agNumberColumnFilter',
filterParams: {
filterOptions: ['startsWith'],
buttons: ['clear']
}
},
{
colId: 'changedFields',
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/views/FuelCodes/_schema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,24 @@ export const fuelCodeColDefs = (t) => [
{
field: 'fuelSuffix',
headerName: t('fuelCode:fuelCodeColLabels.fuelSuffix'),
cellRenderer: TextRenderer
cellRenderer: TextRenderer,
type: 'numericColumn',
filter: 'agNumberColumnFilter',
filterParams: {
filterOptions: ['startsWith'],
buttons: ['clear']
}
},
{
field: 'carbonIntensity',
headerName: t('fuelCode:fuelCodeColLabels.carbonIntensity'),
cellRenderer: TextRenderer,
type: 'numericColumn'
type: 'numericColumn',
filter: 'agNumberColumnFilter',
filterParams: {
filterOptions: ['startsWith'],
buttons: ['clear']
}
},
{
field: 'edrms',
Expand Down
48 changes: 25 additions & 23 deletions frontend/src/views/Transactions/_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
numberFormatter,
currencyFormatter,
dateFormatter,
spacesFormatter,
spacesFormatter
} from '@/utils/formatters'
import { TransactionStatusRenderer } from '@/utils/grid/cellRenderers'
import { BCColumnSetFilter } from '@/components/BCDataGrid/components'
Expand All @@ -26,7 +26,7 @@ export const transactionsColDefs = (t) => [
return `${prefix}${params.data.transactionId}`
},
filterParams: {
buttons:["clear"],
buttons: ['clear']
}
},
{
Expand All @@ -39,11 +39,11 @@ export const transactionsColDefs = (t) => [
textFormatter: (value) => value.replace(/\s+/g, '').toLowerCase(),
textCustomComparator: (filter, value, filterText) => {
// Remove spaces and convert both to lowercase for comparison
const cleanFilterText = filterText.replace(/\s+/g, '').toLowerCase();
const cleanValue = value.replace(/\s+/g, '').toLowerCase();
return cleanValue.includes(cleanFilterText);
const cleanFilterText = filterText.replace(/\s+/g, '').toLowerCase()
const cleanValue = value.replace(/\s+/g, '').toLowerCase()
return cleanValue.includes(cleanFilterText)
},
buttons:["clear"],
buttons: ['clear']
},
width: 222
},
Expand All @@ -54,7 +54,7 @@ export const transactionsColDefs = (t) => [
minWidth: 300,
flex: 2,
filterParams: {
buttons:["clear"],
buttons: ['clear']
}
},
{
Expand All @@ -64,7 +64,7 @@ export const transactionsColDefs = (t) => [
minWidth: 300,
flex: 2,
filterParams: {
buttons:["clear"],
buttons: ['clear']
}
},
{
Expand All @@ -76,7 +76,8 @@ export const transactionsColDefs = (t) => [
width: 140,
filter: 'agNumberColumnFilter',
filterParams: {
buttons:["clear"],
filterOptions: ['startsWith'],
buttons: ['clear']
}
},
{
Expand All @@ -86,12 +87,13 @@ export const transactionsColDefs = (t) => [
valueFormatter: currencyFormatter,
width: 190,
valueGetter: (params) => {
const value = params.data?.pricePerUnit;
return value !== null && value !== undefined ? value : null;
const value = params.data?.pricePerUnit
return value !== null && value !== undefined ? value : null
},
filter: 'agNumberColumnFilter',
filterParams: {
buttons:["clear"],
filterOptions: ['startsWith'],
buttons: ['clear']
}
},
{
Expand Down Expand Up @@ -122,20 +124,20 @@ export const transactionsColDefs = (t) => [
filterOptions: ['inRange', 'equals', 'lessThan', 'greaterThan'],
defaultOption: 'inRange',
comparator: (filterDate, cellValue) => {
const cellDate = new Date(cellValue).setHours(0, 0, 0, 0);
const filterDateOnly = new Date(filterDate).setHours(0, 0, 0, 0);
const cellDate = new Date(cellValue).setHours(0, 0, 0, 0)
const filterDateOnly = new Date(filterDate).setHours(0, 0, 0, 0)

if (cellDate < filterDateOnly) {
return -1; // Cell date is before the filter date
} else if (cellDate > filterDateOnly) {
return 1; // Cell date is after the filter date
} else {
return 0; // Dates are the same (ignoring time)
}
if (cellDate < filterDateOnly) {
return -1 // Cell date is before the filter date
} else if (cellDate > filterDateOnly) {
return 1 // Cell date is after the filter date
} else {
return 0 // Dates are the same (ignoring time)
}
},
browserDatePicker: true, // Uses the browser's date picker if available
buttons:["clear"],
}
buttons: ['clear']
}
}
]

Expand Down

0 comments on commit f2e379b

Please sign in to comment.