Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle scoping for Picklists based on Field in Table #5044

Open
wants to merge 5 commits into
base: production
Choose a base branch
from
Open
Changes from 3 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
10 changes: 8 additions & 2 deletions specifyweb/frontend/js_src/lib/components/PickLists/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
deserializeResource,
serializeResource,
} from '../DataModel/serializers';
import { strictGetTable } from '../DataModel/tables';
import { genericTables, strictGetTable } from '../DataModel/tables';
import type { PickList, PickListItem, Tables } from '../DataModel/types';
import { softFail } from '../Errors/Crash';
import { format } from '../Formatters/formatters';
Expand Down Expand Up @@ -154,11 +154,17 @@ async function fetchFromField(
pickList.get('fieldName') ?? undefined,
'Unable to fetch pick list items as pick list field is not set'
);

const canBeScoped =
genericTables[tableName as keyof Tables]?.getScopingRelationship() !==
undefined ||
!f.includes(Object.keys(schema.domainLevelIds), toLowerCase(tableName));

return fetchRows(tableName as keyof Tables, {
limit,
fields: { [fieldName]: ['string', 'number', 'boolean', 'null'] },
distinct: true,
domainFilter: true,
domainFilter: canBeScoped,
}).then((rows) =>
rows
.map((row) => row[fieldName] ?? '')
Expand Down
Loading