Skip to content

Commit

Permalink
Merge pull request #5224 from specify/issue-5223
Browse files Browse the repository at this point in the history
Set default cotype on the frontend
  • Loading branch information
sharadsw authored Oct 17, 2024
2 parents 0ba26b2 + 60c5562 commit 319ed17
Show file tree
Hide file tree
Showing 59 changed files with 29 additions and 23,734 deletions.
4 changes: 3 additions & 1 deletion specifyweb/context/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from specifyweb.specify.models import Collection, Institution, \
Specifyuser, Spprincipal, Spversion
from specifyweb.specify.schema import base_schema
from specifyweb.specify.api import uri_for_model
from specifyweb.specify.serialize_datamodel import datamodel_to_json
from specifyweb.specify.specify_jar import specify_jar
from specifyweb.specify.views import login_maybe_required, openapi
Expand Down Expand Up @@ -340,7 +341,8 @@ def domain(request):
'embeddedPaleoContext': collection.discipline.ispaleocontextembedded,
'paleoContextChildTable': collection.discipline.paleocontextchildtable,
'catalogNumFormatName': collection.catalognumformatname,
}
'defaultCollectionObjectType': uri_for_model(collection.collectionobjecttype.__class__, collection.collectionobjecttype.id) if collection.collectionobjecttype is not None else None
}

return HttpResponse(json.dumps(domain), content_type='application/json')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ describe('Collection Object business rules', () => {
const getBaseCollectionObject = () =>
new tables.CollectionObject.Resource({
id: collectionObjectlId,
collectionobjecttype: collectionObjectTypeUrl,
determinations: [
{
taxon: getResourceApiUrl('Taxon', otherTaxonId),
Expand Down Expand Up @@ -116,6 +115,9 @@ describe('Collection Object business rules', () => {
const collectionObject = getBaseCollectionObject();

expect(collectionObject.get('collectingEvent')).toBeDefined();
expect(collectionObject.get('collectionObjectType')).toEqual(
schema.defaultCollectionObjectType
);
});

const otherCollectionObjectTypeUrl = getResourceApiUrl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const determinationsResponse: RA<Partial<SerializedRecord<Determination>>> = [

const collectionObjectResponse = {
id: collectionObjectId,
collectionobjecttype: getResourceApiUrl('CollectionObjectType', 1),
resource_uri: collectionObjectUrl,
accession: accessionUrl,
catalognumber: '000029432',
Expand Down Expand Up @@ -203,6 +204,7 @@ describe('needsSaved', () => {
const resource = new tables.CollectionObject.Resource({
id: collectionObjectId,
});

expect(resource.needsSaved).toBe(false);
resource.set('text1', 'a');
expect(resource.needsSaved).toBe(true);
Expand All @@ -212,6 +214,7 @@ describe('needsSaved', () => {
const resource = new tables.CollectionObject.Resource({
id: collectionObjectId,
});

expect(resource.needsSaved).toBe(false);
resource.set('determinations', []);
expect(resource.needsSaved).toBe(true);
Expand Down Expand Up @@ -329,7 +332,7 @@ describe('placeInSameHierarchy', () => {

test('invalid hierarchy', async () => {
const collectionObject = new tables.CollectionObject.Resource({
id: 100,
id: collectionObjectId,
});
const author = new tables.Author.Resource();
await expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test('domain data is fetched and parsed correctly', async () =>
},
embeddedCollectingEvent: false,
embeddedPaleoContext: true,
defaultCollectionObjectType: '/api/specify/collectionobjecttype/1/',
fieldPartSeparator: '-',
orgHierarchy: [
'CollectionObject',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import type { SpecifyResource } from './legacyTypes';
import { fetchResource, idFromUrl } from './resource';
import { setSaveBlockers } from './saveBlockers';
import { schema } from './schema';
import type { Collection } from './specifyTable';
import { tables } from './tables';
import type {
Expand Down Expand Up @@ -154,6 +155,16 @@ export const businessRuleDefs: MappedBusinessRuleDefs = {
new tables.CollectingEvent.Resource()
);
}

// Set the default CoType
if (
typeof schema.defaultCollectionObjectType === 'string' &&
typeof collectionObject.get('collectionObjectType') !== 'string'
)
collectionObject.set(
'collectionObjectType',
schema.defaultCollectionObjectType
);
},
fieldChecks: {
collectionObjectType: async (resource): Promise<undefined> => {
Expand Down
5 changes: 5 additions & 0 deletions specifyweb/frontend/js_src/lib/components/DataModel/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Schema = {
readonly embeddedPaleoContext: boolean;
readonly paleoContextChildTable: string;
readonly catalogNumFormatName: string;
readonly defaultCollectionObjectType: string | null;
readonly orgHierarchy: readonly [
'CollectionObject',
'Collection',
Expand Down Expand Up @@ -50,6 +51,9 @@ const schemaBase: Writable<Schema> = {
paleoContextChildTable: undefined!,
catalogNumFormatName: undefined!,

// Default collectionObjectType for the collection
defaultCollectionObjectType: undefined!,

// The scoping hierarchy of Specify objects.
orgHierarchy: [
'CollectionObject',
Expand Down Expand Up @@ -90,6 +94,7 @@ export const fetchContext = load<
schemaBase.embeddedPaleoContext = data.embeddedPaleoContext;
schemaBase.paleoContextChildTable = data.paleoContextChildTable;
schemaBase.catalogNumFormatName = data.catalogNumFormatName;
schemaBase.defaultCollectionObjectType = data.defaultCollectionObjectType;
return schemaBase;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"embeddedCollectingEvent": false,
"embeddedPaleoContext": true,
"paleoContextChildTable": "collectionobject",
"catalogNumFormatName": "CatalogNumberNumeric"
"catalogNumFormatName": "CatalogNumberNumeric",
"defaultCollectionObjectType": "/api/specify/collectionobjecttype/1/"
}
45 changes: 0 additions & 45 deletions specifyweb/frontend/js_src/lib/tests/fixtures/accession.1.json

This file was deleted.

45 changes: 0 additions & 45 deletions specifyweb/frontend/js_src/lib/tests/fixtures/accession.3.json

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

41 changes: 0 additions & 41 deletions specifyweb/frontend/js_src/lib/tests/fixtures/agent.3.json

This file was deleted.

41 changes: 0 additions & 41 deletions specifyweb/frontend/js_src/lib/tests/fixtures/agent.66.json

This file was deleted.

Loading

0 comments on commit 319ed17

Please sign in to comment.