diff --git a/specifyweb/frontend/js_src/lib/components/Forms/Save.tsx b/specifyweb/frontend/js_src/lib/components/Forms/Save.tsx index 8b60646c114..c7f2f14ddad 100644 --- a/specifyweb/frontend/js_src/lib/components/Forms/Save.tsx +++ b/specifyweb/frontend/js_src/lib/components/Forms/Save.tsx @@ -229,6 +229,10 @@ export function SaveButton({ const [carryForwardAmount, setCarryForwardAmount] = React.useState(1); + const isCOGorCOJO = + resource.specifyTable.name === 'CollectionObjectGroup' || + resource.specifyTable.name === 'CollectionObjectGroupJoin'; + return ( <> {typeof handleAdd === 'function' && canCreate ? ( @@ -237,7 +241,8 @@ export function SaveButton({ (isInRecordSet === false || isInRecordSet === undefined) && isSaveDisabled && showCarry && - showBulkCarry ? ( + showBulkCarry && + !isCOGorCOJO ? ( ({ } /> ) : null} - {showCarry && - copyButton( - formsText.carryForward(), - formsText.carryForwardDescription(), - /** - * FEATURE: Extend this functionality to all tables - * See https://github.com/specify/specify7/pull/4804 - * - */ - resource.specifyTable.name === 'CollectionObject' && - carryForwardAmount > 1 - ? async (): Promise>> => { - const formatter = - tables.CollectionObject.strictGetLiteralField( - 'catalogNumber' - ).getUiFormatter()!; - const wildCard = formatter.valueOrWild(); - - const clonePromises = Array.from( - { length: carryForwardAmount }, - async () => { - const clonedResource = await resource.clone( - false, - true - ); - clonedResource.set('catalogNumber', wildCard as never); - return clonedResource; - } - ); - - const clones = await Promise.all(clonePromises); - - const backendClones = await ajax< - RA> - >( - `/api/specify/bulk/${resource.specifyTable.name.toLowerCase()}/`, - { - method: 'POST', - headers: { Accept: 'application/json' }, - body: clones, - } - ).then(({ data }) => - data.map((resource) => - deserializeResource(serializeResource(resource)) - ) - ); - - return Promise.all([resource, ...backendClones]); - } - : async (): Promise>> => [ - await resource.clone(false), - ] - )} - {showClone && - copyButton( - formsText.clone(), - formsText.cloneDescription(), - async () => [await resource.clone(true)] - )} + {showCarry && !isCOGorCOJO + ? copyButton( + formsText.carryForward(), + formsText.carryForwardDescription(), + /** + * FEATURE: Extend this functionality to all tables + * See https://github.com/specify/specify7/pull/4804 + * + */ + resource.specifyTable.name === 'CollectionObject' && + carryForwardAmount > 1 + ? async (): Promise>> => { + const formatter = + tables.CollectionObject.strictGetLiteralField( + 'catalogNumber' + ).getUiFormatter()!; + const wildCard = formatter.valueOrWild(); + + const clonePromises = Array.from( + { length: carryForwardAmount }, + async () => { + const clonedResource = await resource.clone( + false, + true + ); + clonedResource.set( + 'catalogNumber', + wildCard as never + ); + return clonedResource; + } + ); + + const clones = await Promise.all(clonePromises); + + const backendClones = await ajax< + RA> + >( + `/api/specify/bulk/${resource.specifyTable.name.toLowerCase()}/`, + { + method: 'POST', + headers: { Accept: 'application/json' }, + body: clones, + } + ).then(({ data }) => + data.map((resource) => + deserializeResource(serializeResource(resource)) + ) + ); + + return Promise.all([resource, ...backendClones]); + } + : async (): Promise>> => [ + await resource.clone(false), + ] + ) + : undefined} + {showClone && !isCOGorCOJO + ? copyButton( + formsText.clone(), + formsText.cloneDescription(), + async () => [await resource.clone(true)] + ) + : undefined} {showAdd && copyButton( commonText.add(), diff --git a/specifyweb/frontend/js_src/lib/tests/jsdom.js b/specifyweb/frontend/js_src/lib/tests/jsdom.js index 3a340936817..f051cd3a4fc 100644 --- a/specifyweb/frontend/js_src/lib/tests/jsdom.js +++ b/specifyweb/frontend/js_src/lib/tests/jsdom.js @@ -6,11 +6,13 @@ const { window } = new JSDOM('

Hello world

'); // Define window and other globals globalThis.window = window; globalThis.document = window.document; -global.navigator = { - userAgent: 'node.js', - appVersion: 'node.js', - platform: 'node.js', -}; +if (!global.navigator) { + global.navigator = { + userAgent: 'node.js', + appVersion: 'node.js', + platform: 'node.js', + }; +} // You can also define other browser-specific globals as needed global.HTMLElement = window.HTMLElement;