From 5d92f8cfc31ce75dec49723280e5f627d8b96159 Mon Sep 17 00:00:00 2001 From: Caroline Denis Date: Thu, 12 Mar 2026 15:05:41 -0400 Subject: [PATCH 1/4] Fix: Trim leading zeros and keep decimal digits in formatted fields Fixes #7451 --- specifyweb/backend/stored_queries/format.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/specifyweb/backend/stored_queries/format.py b/specifyweb/backend/stored_queries/format.py index c9a284432ab..1bba18832bb 100644 --- a/specifyweb/backend/stored_queries/format.py +++ b/specifyweb/backend/stored_queries/format.py @@ -218,18 +218,27 @@ def make_expr(self, # Helper function to apply only string-ish transforms with no numeric casts def apply_stringish(expr): e = expr + if fieldNodeAttrib.get('trimzeros') == 'true': - numeric_str = cast(cast(e, types.Numeric(65)), types.String()) - e = case( - (e.op('REGEXP')(r'^-?[0-9]+(\.[0-9]+)?$'), numeric_str), - else_=cast(e, types.String()), - ) + e = cast(e, types.String()) + + # remove leading zeros + e = func.regexp_replace(e, r'^(-?)0+([0-9])', r'\1\2') + + # remove trailing zeros after decimal + e = func.regexp_replace(e, r'(\.[0-9]*?)0+$', r'\1') + + # remove trailing decimal point + e = func.regexp_replace(e, r'\.$', '') + fmt = fieldNodeAttrib.get('format') if fmt is not None: e = self.pseudo_sprintf(fmt, e) + sep = fieldNodeAttrib.get('sep') if sep is not None: e = concat(sep, e) + return e stringish_expr = apply_stringish(raw_expr) From f2cc2acbdc233e40bdd5aded73e406822692472c Mon Sep 17 00:00:00 2001 From: alec_dev Date: Wed, 18 Mar 2026 15:51:05 +0000 Subject: [PATCH 2/4] Lint code with ESLint and Prettier Triggered by e0cd4a4df29c186994e24dade6194b0e89d4b78c on branch refs/heads/issue-7451 --- .../__tests__/AppResourceEditButton.test.tsx | 24 +++++++++---------- .../js_src/lib/components/Molecules/index.tsx | 6 ++--- .../WbPlanView/CustomSelectElement.tsx | 2 +- .../js_src/lib/components/WorkBench/hooks.ts | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/AppResources/__tests__/AppResourceEditButton.test.tsx b/specifyweb/frontend/js_src/lib/components/AppResources/__tests__/AppResourceEditButton.test.tsx index 76e1b3e8977..c8aff34b80e 100644 --- a/specifyweb/frontend/js_src/lib/components/AppResources/__tests__/AppResourceEditButton.test.tsx +++ b/specifyweb/frontend/js_src/lib/components/AppResources/__tests__/AppResourceEditButton.test.tsx @@ -70,18 +70,18 @@ describe('AppResourceEditButton', () => { const dialog = getByRole('dialog'); expect(dialog.innerHTML).toMatchInlineSnapshot(` -"

TestTitle

" -`); + "

TestTitle

" + `); expect(handleDeleted).not.toHaveBeenCalled(); }); diff --git a/specifyweb/frontend/js_src/lib/components/Molecules/index.tsx b/specifyweb/frontend/js_src/lib/components/Molecules/index.tsx index 0adade45a00..6420a8f4c10 100644 --- a/specifyweb/frontend/js_src/lib/components/Molecules/index.tsx +++ b/specifyweb/frontend/js_src/lib/components/Molecules/index.tsx @@ -7,9 +7,9 @@ import React from 'react'; +import { useHueDifference } from '../../hooks/useHueDifference'; import { commonText } from '../../localization/common'; import type { RA } from '../../utils/types'; -import { useHueDifference } from '../../hooks/useHueDifference'; export const loadingGif = (
@@ -31,7 +31,7 @@ export const loadingGif = ( * This must be accompanied by a label since loading bar is hidden from screen * readers */ -const LoadingBar = () => { +function LoadingBar() { const hueDifference = useHueDifference(); return ( @@ -45,7 +45,7 @@ const LoadingBar = () => { />
); -}; +} export const loadingBar = ; diff --git a/specifyweb/frontend/js_src/lib/components/WbPlanView/CustomSelectElement.tsx b/specifyweb/frontend/js_src/lib/components/WbPlanView/CustomSelectElement.tsx index bcdd53e4ddf..f3e4a7aa0b1 100644 --- a/specifyweb/frontend/js_src/lib/components/WbPlanView/CustomSelectElement.tsx +++ b/specifyweb/frontend/js_src/lib/components/WbPlanView/CustomSelectElement.tsx @@ -849,8 +849,8 @@ export function CustomSelectElement({ > Date: Wed, 18 Mar 2026 15:59:46 -0400 Subject: [PATCH 3/4] Fix: Chnage trim zero string --- specifyweb/frontend/js_src/lib/localization/resources.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/localization/resources.ts b/specifyweb/frontend/js_src/lib/localization/resources.ts index a8841282914..44eeb65b4bf 100644 --- a/specifyweb/frontend/js_src/lib/localization/resources.ts +++ b/specifyweb/frontend/js_src/lib/localization/resources.ts @@ -1020,13 +1020,7 @@ export const resourcesText = createDictionary({ 'uk-ua': 'Налаштувати поле', }, trimZeros: { - 'en-us': 'Trim Leading Zeros', - 'de-ch': 'Führende Nullen entfernen', - 'es-es': 'Recortar ceros iniciales', - 'fr-fr': 'Supprimer les zéros non significatifs', - 'pt-br': 'Eliminar zeros à esquerda', - 'ru-ru': 'Обрезка ведущих нулей', - 'uk-ua': 'Видалити початкові нулі', + 'en-us': 'Trim Zeros', }, trimZerosDescription: { 'en-us': 'Remove leading zeros from numeric values.', From 606abea616dd705bd3519c432ee3f1ed8ac93fa0 Mon Sep 17 00:00:00 2001 From: Caroline Denis Date: Mon, 23 Mar 2026 20:32:38 +0100 Subject: [PATCH 4/4] Apply only for numeric patern --- specifyweb/backend/stored_queries/format.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/specifyweb/backend/stored_queries/format.py b/specifyweb/backend/stored_queries/format.py index 14fa6888fb5..8f6d250b1d5 100644 --- a/specifyweb/backend/stored_queries/format.py +++ b/specifyweb/backend/stored_queries/format.py @@ -221,15 +221,18 @@ def apply_stringish(expr): if fieldNodeAttrib.get('trimzeros') == 'true': e = cast(e, types.String()) + trimmed = e # remove leading zeros - e = func.regexp_replace(e, r'^(-?)0+([0-9])', r'\1\2') + trimmed = func.regexp_replace(trimmed, r'^(-?)0+([0-9])', r'\1\2') # remove trailing zeros after decimal - e = func.regexp_replace(e, r'(\.[0-9]*?)0+$', r'\1') + trimmed = func.regexp_replace(trimmed, r'(\.[0-9]*?)0+$', r'\1') # remove trailing decimal point - e = func.regexp_replace(e, r'\.$', '') + trimmed = func.regexp_replace(trimmed, r'\.$', '') + + e = case((e.op('REGEXP')(r'^-?[0-9]+(\.[0-9]+)?$'), trimmed), else_=e) fmt = fieldNodeAttrib.get('format') if fmt is not None: