Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -62,16 +62,28 @@ export function generateUploadSpec(
const field = queryFieldSpec.getField();
const queryResultsFormatter = (
value: number | string | null | undefined
): string | undefined =>
value === undefined || value === null || field?.isRelationship === true
? undefined
: syncFieldFormat(
field,
value.toString(),
queryFieldSpec.parser,
undefined,
true
);
): string | undefined => {
if (value === undefined || value === null || field?.isRelationship === true)
return undefined;

const rawValue = value.toString();
const fieldFormatter = field?.getUiFormatter();
if (fieldFormatter !== undefined)
// Catalog number formatting can vary by Collection Object Type. The
// query field only has the schema-level formatter, so preserve database
// values that do not match that formatter instead of dropping them.
return fieldFormatter.format(rawValue) ?? rawValue;

return (
syncFieldFormat(
field,
rawValue,
queryFieldSpec.parser,
undefined,
true
) ?? rawValue
);
};
return {
staticPathKey,
formatQueryResults: queryResultsFormatter,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { requireContext } from '../../../tests/helpers';
import { generateUploadSpec } from '../SelectUploadPath';

requireContext();

describe('generateUploadSpec catalog number result formatting', () => {
test('preserves catalog numbers that do not match the schema formatter', () =>
expect(
generateUploadSpec('collectionObjectCatalogNumber').formatQueryResults!(
'F-250750'
)
).toBe('F-250750'));

test('keeps canonical formatting for values accepted by the schema formatter', () =>
expect(
generateUploadSpec('collectionObjectCatalogNumber').formatQueryResults!(
'123'
)
).toBe('000000123'));
});
4 changes: 2 additions & 2 deletions specifyweb/frontend/js_src/lib/components/DataModel/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ export const getTableById = <SCHEMA extends AnySchema>(
tableId: number
): SpecifyTable<SCHEMA> =>
(Object.values(genericTables).find((table) => table.tableId === tableId) as
SpecifyTable<SCHEMA> | undefined) ??
error(`Table with id ${tableId} does not exist`);
| SpecifyTable<SCHEMA>
| undefined) ?? error(`Table with id ${tableId} does not exist`);

// If this is true, then you can use {domainfilter:true} when fetching that table
export const hasHierarchyField = (table: SpecifyTable): boolean =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export function usePaginatedCollection<COLLECTION_TYPE>({
const [results, setResults] = useTriggerState<
RA<COLLECTION_TYPE | undefined> | undefined
>(initialRecords);

const resultsRef = React.useRef(results);

const handleSetResults: GetOrSet<
RA<COLLECTION_TYPE | undefined> | undefined
>[typeof SET] = React.useCallback(
Expand Down
Loading