mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-01-25 00:49:35 +00:00
Introduce en-x-icu collation for basic fields
This commit is contained in:
parent
a39ae03422
commit
0efb2fdd32
5 changed files with 33 additions and 27 deletions
backend/src/baserow
changelog/entries/unreleased/bug
web-frontend/modules
|
@ -1423,7 +1423,9 @@ class LastModifiedByFieldType(ReadOnlyFieldType):
|
|||
|
||||
def get_value_for_filter(self, row: "GeneratedTableModel", field: Field) -> any:
|
||||
value = getattr(row, field.db_column)
|
||||
return value
|
||||
if value is None:
|
||||
return None
|
||||
return collate_expression(Value(value.first_name))
|
||||
|
||||
def get_search_expression(self, field: Field, queryset: QuerySet) -> Expression:
|
||||
return Subquery(
|
||||
|
@ -1626,7 +1628,9 @@ class CreatedByFieldType(ReadOnlyFieldType):
|
|||
|
||||
def get_value_for_filter(self, row: "GeneratedTableModel", field: Field) -> any:
|
||||
value = getattr(row, field.db_column)
|
||||
return value
|
||||
if value is None:
|
||||
return None
|
||||
return collate_expression(Value(value.first_name))
|
||||
|
||||
def get_search_expression(self, field: Field, queryset: QuerySet) -> Expression:
|
||||
return Subquery(
|
||||
|
@ -3598,7 +3602,7 @@ class SingleSelectFieldType(SelectOptionBaseFieldType):
|
|||
"""
|
||||
|
||||
name = f"{field_name}__value"
|
||||
order = collate_expression(F(name))
|
||||
order = F(name)
|
||||
|
||||
if order_direction == "ASC":
|
||||
order = order.asc(nulls_first=True)
|
||||
|
@ -4033,7 +4037,7 @@ class MultipleSelectFieldType(
|
|||
sort_column_name = f"{field_name}_agg_sort"
|
||||
query = Coalesce(StringAgg(f"{field_name}__value", ","), Value(""))
|
||||
annotation = {sort_column_name: query}
|
||||
order = collate_expression(F(sort_column_name))
|
||||
order = F(sort_column_name)
|
||||
|
||||
if order_direction == "DESC":
|
||||
order = order.desc(nulls_first=True)
|
||||
|
@ -4093,7 +4097,7 @@ class MultipleSelectFieldType(
|
|||
return set(value1) == set(value2)
|
||||
|
||||
|
||||
class PhoneNumberFieldType(CharFieldMatchingRegexFieldType):
|
||||
class PhoneNumberFieldType(CollationSortMixin, CharFieldMatchingRegexFieldType):
|
||||
"""
|
||||
A simple wrapper around a TextField which ensures any entered data is a
|
||||
simple phone number.
|
||||
|
@ -4136,6 +4140,10 @@ class PhoneNumberFieldType(CharFieldMatchingRegexFieldType):
|
|||
def random_value(self, instance, fake, cache):
|
||||
return fake.phone_number()
|
||||
|
||||
def get_value_for_filter(self, row: "GeneratedTableModel", field: Field) -> any:
|
||||
value = getattr(row, field.db_column)
|
||||
return collate_expression(Value(value))
|
||||
|
||||
|
||||
class FormulaFieldType(ReadOnlyFieldType):
|
||||
type = "formula"
|
||||
|
@ -5486,7 +5494,7 @@ class MultipleCollaboratorsFieldType(
|
|||
query = Coalesce(StringAgg(f"{field_name}__first_name", ""), Value(""))
|
||||
annotation = {sort_column_name: query}
|
||||
|
||||
order = collate_expression(F(sort_column_name))
|
||||
order = F(sort_column_name)
|
||||
|
||||
if order_direction == "DESC":
|
||||
order = order.desc(nulls_first=True)
|
||||
|
|
|
@ -418,9 +418,6 @@ def get_collation_name() -> Optional[str]:
|
|||
can be used, None otherwise.
|
||||
"""
|
||||
|
||||
if "collation" not in settings.FEATURE_FLAGS:
|
||||
return None
|
||||
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
"SELECT collname FROM pg_collation where collname = %s AND collencoding = -1",
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"type": "bug",
|
||||
"message": "Introduce en-x-icu collation for basic fields",
|
||||
"issue_number": 1603,
|
||||
"bullet_points": [],
|
||||
"created_at": "2023-12-25"
|
||||
}
|
|
@ -1,8 +1,3 @@
|
|||
import {
|
||||
featureFlagIsEnabled,
|
||||
getFeatureFlags,
|
||||
} from '@baserow/modules/core/utils/env'
|
||||
|
||||
/**
|
||||
* Generates a UUID version 4 (UUID v4) string.
|
||||
*
|
||||
|
@ -184,14 +179,7 @@ export const isSubstringOfStrings = (strings, searchTerm) => {
|
|||
}
|
||||
|
||||
export function collatedStringCompare(stringA, stringB, order) {
|
||||
const featureFlags = getFeatureFlags()
|
||||
if (featureFlagIsEnabled(featureFlags, 'collation')) {
|
||||
return order === 'ASC'
|
||||
? stringA.localeCompare(stringB, 'en')
|
||||
: stringB.localeCompare(stringA, 'en')
|
||||
} else {
|
||||
return order === 'ASC'
|
||||
? stringA.localeCompare(stringB)
|
||||
: stringB.localeCompare(stringA)
|
||||
}
|
||||
return order === 'ASC'
|
||||
? stringA.localeCompare(stringB, 'en')
|
||||
: stringB.localeCompare(stringA, 'en')
|
||||
}
|
||||
|
|
|
@ -2825,7 +2825,9 @@ export class SingleSelectFieldType extends FieldType {
|
|||
const stringA = a[name] === null ? '' : '' + a[name].value
|
||||
const stringB = b[name] === null ? '' : '' + b[name].value
|
||||
|
||||
return collatedStringCompare(stringA, stringB, order)
|
||||
return order === 'ASC'
|
||||
? stringA.localeCompare(stringB)
|
||||
: stringB.localeCompare(stringA)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3049,7 +3051,9 @@ export class MultipleSelectFieldType extends FieldType {
|
|||
const stringB =
|
||||
valuesB.length > 0 ? valuesB.map((obj) => obj.value).join('') : ''
|
||||
|
||||
return collatedStringCompare(stringA, stringB, order)
|
||||
return order === 'ASC'
|
||||
? stringA.localeCompare(stringB)
|
||||
: stringB.localeCompare(stringA)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3705,7 +3709,9 @@ export class MultipleCollaboratorsFieldType extends FieldType {
|
|||
stringB = valuesB.map((obj) => obj.name).join('')
|
||||
}
|
||||
|
||||
return collatedStringCompare(stringA, stringB, order)
|
||||
return order === 'ASC'
|
||||
? stringA.localeCompare(stringB)
|
||||
: stringB.localeCompare(stringA)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue