From 231ac56ca81e24debfb3d54b15426bdde39edc45 Mon Sep 17 00:00:00 2001 From: Caroline D <108160931+CarolineDenis@users.noreply.github.com> Date: Fri, 8 Mar 2024 07:54:55 -0800 Subject: [PATCH 01/20] Add support for explicitly choose a formatter in QB Fixes #1959 --- .../lib/components/QueryBuilder/Line.tsx | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx index 13110bbd62b..b0a7a1248e5 100644 --- a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx +++ b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx @@ -49,6 +49,7 @@ import type { DatePart } from './fieldSpec'; import { QueryFieldSpec } from './fieldSpec'; import type { QueryField } from './helpers'; import { QueryLineTools } from './QueryLineTools'; +import { QueryFieldFormatter } from './Formatter'; // REFACTOR: split this component into smaller components export function QueryLine({ @@ -372,6 +373,27 @@ export function QueryLine({ mappingElementDivider ) )} + {(fieldMeta.fieldType === 'formatter' || + fieldMeta.fieldType === 'aggregator') && + typeof fieldMeta.tableName === 'string' ? ( + <> + {mappingElementDivider} + + handleChange({ + ...field, + dataObjFormatter: dataObjectFormatter, + }) + } + /> + + ) : undefined} {filtersVisible ? (
Date: Fri, 8 Mar 2024 15:59:02 +0000 Subject: [PATCH 02/20] Lint code with ESLint and Prettier Triggered by 231ac56ca81e24debfb3d54b15426bdde39edc45 on branch refs/heads/issue-1959 --- specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx index b0a7a1248e5..a1a6742e0b4 100644 --- a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx +++ b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx @@ -47,9 +47,9 @@ import { } from './FieldFilter'; import type { DatePart } from './fieldSpec'; import { QueryFieldSpec } from './fieldSpec'; +import { QueryFieldFormatter } from './Formatter'; import type { QueryField } from './helpers'; import { QueryLineTools } from './QueryLineTools'; -import { QueryFieldFormatter } from './Formatter'; // REFACTOR: split this component into smaller components export function QueryLine({ From a72dbf9aa4a4bdee6835a75c88570381bc5238c8 Mon Sep 17 00:00:00 2001 From: Caroline D <108160931+CarolineDenis@users.noreply.github.com> Date: Fri, 8 Mar 2024 11:29:02 -0800 Subject: [PATCH 03/20] Add cog icon to display formatter selector, change cog color depending on default value --- .../lib/components/QueryBuilder/Formatter.tsx | 64 +++++++++++++------ .../lib/components/QueryBuilder/Line.tsx | 1 - .../frontend/js_src/lib/localization/query.ts | 3 + 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx index 3e45ec9e844..e2ba054df6c 100644 --- a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx +++ b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx @@ -5,7 +5,8 @@ import { commonText } from '../../localization/common'; import { Select } from '../Atoms/Form'; import type { Tables } from '../DataModel/types'; import { fetchFormatters } from '../Formatters/formatters'; -import { mappingElementDivider } from '../WbPlanView/LineComponents'; +import { Button } from '../Atoms/Button'; +import { queryText } from '../../localization/query'; export function QueryFieldFormatter({ type, @@ -23,42 +24,67 @@ export function QueryFieldFormatter({ () => // Some code duplication, but required by TypeScript (type === 'formatter' - ? formatters?.formatters.map(({ table, name, title }) => ({ + ? formatters?.formatters.map(({ table, name, title, isDefault }) => ({ table, name, title, + isDefault, })) - : formatters?.aggregators.map(({ table, name, title }) => ({ + : formatters?.aggregators.map(({ table, name, title, isDefault }) => ({ table, name, title, + isDefault, })) ) ?.filter(({ table }) => table?.name === tableName) - .map(({ name, title = name }) => ({ name, title })), + .map(({ name, title = name, isDefault }) => ({ + name, + title, + isDefault, + })), [type, formatters, tableName] ); + + const [formatterSelectIsOpen, toggleFormatterSelect] = React.useState(false); + return availableFormatters === undefined ? ( typeof formatter === 'string' ? ( <>{commonText.loading()} ) : null ) : availableFormatters.length > 1 ? ( <> - {mappingElementDivider} -
- -
+ toggleFormatterSelect(!formatterSelectIsOpen)} + className={ + formatter && + availableFormatters.find((selected) => selected.name === formatter) + ?.isDefault + ? '' + : 'bg-yellow-250 dark:bg-yellow-900' + } + /> + {formatterSelectIsOpen && ( +
+ +
+ )} ) : null; } diff --git a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx index a1a6742e0b4..1c32a8fb01c 100644 --- a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx +++ b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Line.tsx @@ -377,7 +377,6 @@ export function QueryLine({ fieldMeta.fieldType === 'aggregator') && typeof fieldMeta.tableName === 'string' ? ( <> - {mappingElementDivider} Date: Fri, 8 Mar 2024 11:30:13 -0800 Subject: [PATCH 04/20] Remove unecessary check --- .../frontend/js_src/lib/components/QueryBuilder/Formatter.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx index e2ba054df6c..9933f014d60 100644 --- a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx +++ b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx @@ -59,7 +59,6 @@ export function QueryFieldFormatter({ title={queryText.chooseFormatter()} onClick={() => toggleFormatterSelect(!formatterSelectIsOpen)} className={ - formatter && availableFormatters.find((selected) => selected.name === formatter) ?.isDefault ? '' From f5355f534df5708e3e4eed4c0d036bf671d330db Mon Sep 17 00:00:00 2001 From: Caroline D <108160931+CarolineDenis@users.noreply.github.com> Date: Fri, 8 Mar 2024 19:33:41 +0000 Subject: [PATCH 05/20] Lint code with ESLint and Prettier Triggered by dd2c4cd17f35b493dca9b1fdd950d2ff9349becc on branch refs/heads/issue-1959 --- .../js_src/lib/components/QueryBuilder/Formatter.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx index 9933f014d60..0f829fda5a4 100644 --- a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx +++ b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx @@ -2,11 +2,11 @@ import React from 'react'; import { usePromise } from '../../hooks/useAsyncState'; import { commonText } from '../../localization/common'; +import { queryText } from '../../localization/query'; +import { Button } from '../Atoms/Button'; import { Select } from '../Atoms/Form'; import type { Tables } from '../DataModel/types'; import { fetchFormatters } from '../Formatters/formatters'; -import { Button } from '../Atoms/Button'; -import { queryText } from '../../localization/query'; export function QueryFieldFormatter({ type, @@ -55,15 +55,15 @@ export function QueryFieldFormatter({ ) : availableFormatters.length > 1 ? ( <> toggleFormatterSelect(!formatterSelectIsOpen)} className={ availableFormatters.find((selected) => selected.name === formatter) ?.isDefault ? '' : 'bg-yellow-250 dark:bg-yellow-900' } + icon="cog" + title={queryText.chooseFormatter()} + onClick={() => toggleFormatterSelect(!formatterSelectIsOpen)} /> {formatterSelectIsOpen && (
From fdd14d8e6d1aae92f3c510ed7198fadd5e4af8ac Mon Sep 17 00:00:00 2001 From: Caroline D <108160931+CarolineDenis@users.noreply.github.com> Date: Fri, 8 Mar 2024 11:48:37 -0800 Subject: [PATCH 06/20] Add style to gear icon --- .../js_src/lib/components/QueryBuilder/Formatter.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx index 0f829fda5a4..6544789c80a 100644 --- a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx +++ b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx @@ -55,12 +55,12 @@ export function QueryFieldFormatter({ ) : availableFormatters.length > 1 ? ( <> selected.name === formatter) ?.isDefault ? '' - : 'bg-yellow-250 dark:bg-yellow-900' - } + : 'bg-yellow-250 dark:bg-yellow-900 ' + } border border-gray-500 p-0.5`} icon="cog" title={queryText.chooseFormatter()} onClick={() => toggleFormatterSelect(!formatterSelectIsOpen)} From 864286f7d7c81b7948eabcd0dabcc0ab36da5983 Mon Sep 17 00:00:00 2001 From: Caroline D <108160931+CarolineDenis@users.noreply.github.com> Date: Fri, 8 Mar 2024 13:43:13 -0800 Subject: [PATCH 07/20] Add background, change hover text, grey when blank, --- .../frontend/js_src/lib/components/QueryBuilder/Formatter.tsx | 4 ++-- specifyweb/frontend/js_src/lib/localization/query.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx index 6544789c80a..25c878a6393 100644 --- a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx +++ b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx @@ -57,8 +57,8 @@ export function QueryFieldFormatter({ selected.name === formatter) - ?.isDefault - ? '' + ?.isDefault || formatter === undefined + ? 'bg-white dark:bg-neutral-600' : 'bg-yellow-250 dark:bg-yellow-900 ' } border border-gray-500 p-0.5`} icon="cog" diff --git a/specifyweb/frontend/js_src/lib/localization/query.ts b/specifyweb/frontend/js_src/lib/localization/query.ts index ef2f0f94ef6..520bdd4cfdf 100644 --- a/specifyweb/frontend/js_src/lib/localization/query.ts +++ b/specifyweb/frontend/js_src/lib/localization/query.ts @@ -884,6 +884,6 @@ export const queryText = createDictionary({ 'uk-ua': 'Переглянути записи', }, chooseFormatter: { - 'en-us': 'Choose fromatter', + 'en-us': 'Choose formatter', }, } as const); From 4c9e7e56388a9e6e83929c062fa1d8144a7152c4 Mon Sep 17 00:00:00 2001 From: Caroline D <108160931+CarolineDenis@users.noreply.github.com> Date: Fri, 8 Mar 2024 13:54:09 -0800 Subject: [PATCH 08/20] Use btn small instead of btn icon --- .../js_src/lib/components/QueryBuilder/Formatter.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx index 25c878a6393..e86e57ce405 100644 --- a/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx +++ b/specifyweb/frontend/js_src/lib/components/QueryBuilder/Formatter.tsx @@ -7,6 +7,7 @@ import { Button } from '../Atoms/Button'; import { Select } from '../Atoms/Form'; import type { Tables } from '../DataModel/types'; import { fetchFormatters } from '../Formatters/formatters'; +import { icons } from '../Atoms/Icons'; export function QueryFieldFormatter({ type, @@ -54,17 +55,19 @@ export function QueryFieldFormatter({ ) : null ) : availableFormatters.length > 1 ? ( <> - selected.name === formatter) ?.isDefault || formatter === undefined ? 'bg-white dark:bg-neutral-600' : 'bg-yellow-250 dark:bg-yellow-900 ' - } border border-gray-500 p-0.5`} - icon="cog" + }`} title={queryText.chooseFormatter()} onClick={() => toggleFormatterSelect(!formatterSelectIsOpen)} - /> + > + {icons.cog} + {formatterSelectIsOpen && (
{ - handleChange?.(value); - }} + onValueChange={handleChange} >