Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0fd3c95
feat(FieldFormatter): begin implementing visual editor
maxpatiiuk Jun 30, 2024
03acac0
refactor(FieldFormatters): cleanup placeholder & regex semantics
maxpatiiuk Jul 6, 2024
4e0cec6
refactor(FieldFormatter): rename "Field" to "Part"
maxpatiiuk Jul 6, 2024
ac18dc4
feat(FieldFormatters): complete visual editor
maxpatiiuk Jul 6, 2024
516a519
feat(FieldFormatters): improve visual editor UX
maxpatiiuk Jul 7, 2024
6850bab
tests(FieldFormatters): update failing tests
maxpatiiuk Jul 7, 2024
4ae2f21
Lint code with ESLint and Prettier
maxpatiiuk Jul 7, 2024
0b5cba0
refactor(FieldFormatters): do a self code review
maxpatiiuk Jul 7, 2024
c5eff48
feat(SchemaConfig): add link to FieldFormatter VisualEditor
maxpatiiuk Jul 7, 2024
0587e45
fix(FieldFormatters): normalize ^ and $ in regex
maxpatiiuk Jul 13, 2024
61ef5fd
fix(FieldFormatters): correctly resolve formatter in editor preview
maxpatiiuk Jul 13, 2024
1bdece9
fix(FieldFormatters): don't expose internal autoNumbering state in UI
maxpatiiuk Jul 13, 2024
a118d30
Lint code with ESLint and Prettier
maxpatiiuk Jul 13, 2024
7978624
fix(FieldFormatters): resolve minor UX issues
maxpatiiuk Jul 21, 2024
1cfe2d8
fix(FieldFormatters): fix schema config indexes being off
maxpatiiuk Jul 30, 2024
f7a6b3e
fix(FieldFormatters): don't trigger "Save" without user changes
maxpatiiuk Nov 27, 2024
7ac3ded
docs(localization): fix __init__.py file name typo
maxpatiiuk Nov 27, 2024
341915d
refactor(FieldFormatters): deduplicate formatter normalization logic
maxpatiiuk Dec 14, 2024
93eefca
refactor(FieldFormatters): remove duplidate regex normalization logic
maxpatiiuk Dec 14, 2024
d2dcc58
fix(FieldFormatters): prevent CustomElementSelect not closing on click
maxpatiiuk Dec 14, 2024
c4318aa
fix(FieldFormatters): set max field size at 9999
maxpatiiuk Dec 14, 2024
52365e1
revert(localization): delete unused string
maxpatiiuk Dec 14, 2024
b7d3cb0
fix(FieldFormatter): resolve reported issues
maxpatiiuk Dec 25, 2024
3d4b511
fix(FieldFormatters): clear stale regex validation error
maxpatiiuk Jan 20, 2025
b95c145
fix(FieldFormatters): disable auto-numering in UI where not allowed b…
maxpatiiuk Jan 20, 2025
c8acc26
fix(FieldFormatters): force-wrap long preview lines
maxpatiiuk Jan 27, 2025
37ca347
Lint code with ESLint and Prettier
maxpatiiuk Jan 27, 2025
b7f9e80
Merge remote-tracking branch 'origin/main' into field-editor
CarolineDenis Sep 26, 2025
7dda0a7
Merge branch 'main' of https://github.com/specify/specify7 into field…
alesan99 Sep 29, 2025
7ae4caf
fix(FieldFormatters): fix merge conflicts
alesan99 Sep 29, 2025
24b6e9a
fix(FieldFormatters): update tests
alesan99 Sep 29, 2025
6fa1871
Merge branch 'main' into field-editor
grantfitzsimmons Sep 29, 2025
bd0ed80
Lint code with ESLint and Prettier
grantfitzsimmons Sep 29, 2025
aaeda89
Fix: Disable bulk carry for alphanumeric catalogNumber fields
CarolineDenis Sep 30, 2025
7244a42
Merge remote-tracking branch 'origin/main' into field-editor
CarolineDenis Sep 30, 2025
628c9bb
Fix: Error message says 'record formatter' instead of either formatte…
CarolineDenis Sep 30, 2025
68a6973
Lint code with ESLint and Prettier
CarolineDenis Sep 30, 2025
fd49c36
Merge branch 'main' into field-editor
grantfitzsimmons Oct 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import type {
} from '../DataModel/types';
import { RssExportFeedEditor } from '../ExportFeed';
import { exportFeedSpec } from '../ExportFeed/spec';
import { FieldFormattersEditor } from '../FieldFormatters/Editor';
import { fieldFormattersSpec } from '../FieldFormatters/spec';
import { DataObjectFormatter } from '../Formatters';
import { formattersSpec } from '../Formatters/spec';
import { FormEditor } from '../FormEditor';
Expand Down Expand Up @@ -168,7 +170,10 @@ export const visualAppResourceEditors = f.store<
visual: WebLinkEditor,
xml: generateXmlEditor(webLinksSpec),
},
uiFormatters: undefined,
uiFormatters: {
visual: FieldFormattersEditor,
xml: generateXmlEditor(fieldFormattersSpec),
},
dataObjectFormatters: {
visual: DataObjectFormatter,
xml: generateXmlEditor(formattersSpec),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const appResourceSubTypes = ensure<IR<AppResourceSubType>>()({
documentationUrl:
'https://github.com/specify/specify6/blob/master/config/backstop/uiformatters.xml',
icon: icons.hashtag,
label: resourcesText.uiFormatters(),
label: resourcesText.fieldFormatters(),
},
dataObjectFormatters: {
mimeType: 'text/xml',
Expand Down
1 change: 1 addition & 0 deletions specifyweb/frontend/js_src/lib/components/Atoms/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export const Input = {
props.onChange?.(event);
},
readOnly: isReadOnly,
...withPreventWheel(props.onWheel),
}
),
Float: wrap<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { LocalizedString } from 'typesafe-i18n';

import { requireContext } from '../../../tests/helpers';
import { formatterToParser } from '../../../utils/parser/definitions';
import { fieldFormatterToParser } from '../../../utils/parser/definitions';
import type { IR, RA } from '../../../utils/types';
import { localized } from '../../../utils/types';
import { tables } from '../../DataModel/tables';
import {
CatalogNumberNumeric,
formatterTypeMapper,
fieldFormatterTypeMapper,
UiFormatter,
} from '../../FieldFormatters';
import { syncFieldFormat } from '../../Formatters/fieldFormat';
Expand Down Expand Up @@ -49,7 +51,7 @@ const fileNameTestSpec: TestDefinition = {
false,
localized('testNumeric'),
[
new formatterTypeMapper.numeric({
new fieldFormatterTypeMapper.numeric({
size: 3,
autoIncrement: true,
byYear: false,
Expand All @@ -74,10 +76,10 @@ const fileNameTestSpec: TestDefinition = {
false,
localized('testRegex'),
[
new formatterTypeMapper.regex({
new fieldFormatterTypeMapper.regex({
size: 3,
autoIncrement: true,
value: localized('^\\d{1,6}(?:[a-zA-Z]{1,2})?$'),
placeholder: localized('^\\d{1,6}(?:[a-zA-Z]{1,2})?$'),
byYear: false,
}),
],
Expand All @@ -103,13 +105,14 @@ describe('file names resolution test', () => {
jest.spyOn(console, 'error').mockImplementation();
const field = tables.CollectionObject.getLiteralField('text1')!;
const getResultFormatter =
(formatter: UiFormatter) => (value: number | string | undefined) =>
(formatter: UiFormatter) =>
(value: number | string | undefined): LocalizedString | undefined =>
value === undefined || value === null
? undefined
: syncFieldFormat(
field,
value.toString(),
formatterToParser(field, formatter),
fieldFormatterToParser(field, formatter),
undefined,
true
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ import {
serializeResource,
} from '../DataModel/serializers';
import { strictGetTable, tables } from '../DataModel/tables';
import type { SpQuery, Tables } from '../DataModel/types';
import type { CollectionObject } from '../DataModel/types';
import type { CollectionObject, SpQuery, Tables } from '../DataModel/types';
import type { UiFormatter } from '../FieldFormatters';
import { formatterTypeMapper } from '../FieldFormatters';
import { queryFieldFilterSpecs } from '../QueryBuilder/FieldFilterSpec';
import { makeQueryField } from '../QueryBuilder/fromTree';
import type { QueryFieldWithPath } from '../Statistics/types';
Expand Down Expand Up @@ -105,7 +103,7 @@ function generateInQueryResource(
};
const { path, ...field } = rawField;
return serializeResource(
makeQueryField(baseTable, rawField.path, { ...field, position: index })
makeQueryField(baseTable, path, { ...field, position: index })
);
});

Expand Down Expand Up @@ -232,24 +230,15 @@ export function resolveFileNames(
// BUG: Won't catch if formatters begin or end with a space
const splitName = stripFileExtension(fileName).trim();
let nameToParse = splitName;
if (
formatter !== undefined &&
formatter.fields.every(
(field) => !(field instanceof formatterTypeMapper.regex)
)
) {
const formattedLength = formatter.fields.reduce(
(length, field) => length + field.size,
0
);
nameToParse = fileName.trim().slice(0, formattedLength);
if (formatter?.parts.every((field) => field.type !== 'regex') === true) {
nameToParse = fileName.trim().slice(0, formatter.size);
}
let formatted = nameToParse === '' ? undefined : getFormatted(nameToParse);
const numericFields = formatter?.fields.filter(
(field) => field instanceof formatterTypeMapper.numeric
const numericFields = formatter?.parts.filter(
(field) => field.type === 'numeric'
);
if (
formatter?.fields?.length === 1 &&
formatter?.parts?.length === 1 &&
numericFields?.length === 1 &&
formatted === undefined &&
splitName !== ''
Expand Down
59 changes: 59 additions & 0 deletions specifyweb/frontend/js_src/lib/components/DataEntryTables/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { ajax } from '../../utils/ajax';
import { getAppResourceUrl } from '../../utils/ajax/helpers';
import { f } from '../../utils/functools';
import type { RA } from '../../utils/types';
import { filterArray } from '../../utils/types';
import { parseJavaClassName } from '../DataModel/resource';
import type { SpecifyTable } from '../DataModel/specifyTable';
import { fetchContext as fetchSchema, getTable } from '../DataModel/tables';
import type { Tables } from '../DataModel/types';
import { fetchView } from '../FormParse';
import { cacheableUrl } from '../InitialContext';
import { xmlToSpec } from '../Syncer/xmlUtils';
import { dataEntryItems } from './spec';

const url = cacheableUrl(getAppResourceUrl('DataEntryTaskInit'));

export const fetchLegacyForms = f.store(
async (): Promise<RA<SpecifyTable>> =>
Promise.all([
ajax<Element>(url, {
headers: { Accept: 'text/xml' },
}),
fetchSchema,
])
.then(async ([{ data }]) =>
Promise.all(
xmlToSpec(data, dataEntryItems()).items.map(async ({ viewName }) =>
f.maybe(viewName, resolveTable)
)
)
)
.then(filterArray)
);

async function resolveTable(
viewName: string
): Promise<SpecifyTable | undefined> {
const table = getTable(viewName);
if (typeof table === 'object') return table;
const form = await fetchView(viewName);
return typeof form === 'object'
? getTable(parseJavaClassName(form.class))
: undefined;
}

export const defaultFormTablesConfig: RA<keyof Tables> = [
'CollectionObject',
'CollectingEvent',
'Locality',
'Taxon',
'Agent',
'Geography',
'DNASequence',
'ReferenceWork',
];

export const exportsForTests = {
fetchLegacyForms,
};
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export class SpecifyTable<SCHEMA extends AnySchema = AnySchema> {
*
* I.e, table can be scoped to collection using a "collectionMemberId" field
* (which is not a relationship - sad). Back-end looks at that relationship
* for scoping inconsistenly. Front-end does not look at all.
* for scoping inconsistently. Front-end does not look at all.
*/
public getScopingRelationship(): Relationship | undefined {
this.scopingRelationship ??=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';

import type { AppResourceTabProps } from '../AppResources/TabDefinitions';
import { createXmlContext, XmlEditor } from '../Formatters';
import { fieldFormattersRoutes } from './Routes';
import { fieldFormattersSpec } from './spec';

export function FieldFormattersEditor(props: AppResourceTabProps): JSX.Element {
return (
<XmlEditor
context={FieldFormattersContext}
props={props}
rootTagName="formatters"
routes={fieldFormattersRoutes}
spec={fieldFormattersSpec()}
/>
);
}

export const FieldFormattersContext = createXmlContext(fieldFormattersSpec());
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { useParams } from 'react-router-dom';

import { resourcesText } from '../../localization/resources';
import { ReadOnlyContext } from '../Core/Contexts';
import { makeXmlEditorShellSlot, XmlEditorShell } from '../Formatters/Element';
import { FieldFormatterElement } from './FieldFormatter';
import type { FieldFormattersOutlet } from './List';
import type { FieldFormatter } from './spec';

export function FieldFormatterWrapper(): JSX.Element {
const { index } = useParams();
const isReadOnly = React.useContext(ReadOnlyContext);
return (
<XmlEditorShell<FieldFormatter, FieldFormattersOutlet>
header={resourcesText.fieldFormatters()}
>
{makeXmlEditorShellSlot(
(getSet) => (
<FieldFormatterElement item={getSet} />
),
index,
isReadOnly
)}
</XmlEditorShell>
);
}
Loading
Loading