Skip to content

Commit

Permalink
Merge pull request #5383 from specify/issue-5382
Browse files Browse the repository at this point in the history
Remove clone and carry buttons from COG and COJO
  • Loading branch information
CarolineDenis authored Nov 7, 2024
2 parents 105a025 + 76871c7 commit a75e847
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 65 deletions.
130 changes: 70 additions & 60 deletions specifyweb/frontend/js_src/lib/components/Forms/Save.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ export function SaveButton<SCHEMA extends AnySchema = AnySchema>({

const [carryForwardAmount, setCarryForwardAmount] = React.useState<number>(1);

const isCOGorCOJO =
resource.specifyTable.name === 'CollectionObjectGroup' ||
resource.specifyTable.name === 'CollectionObjectGroupJoin';

return (
<>
{typeof handleAdd === 'function' && canCreate ? (
Expand All @@ -237,7 +241,8 @@ export function SaveButton<SCHEMA extends AnySchema = AnySchema>({
(isInRecordSet === false || isInRecordSet === undefined) &&
isSaveDisabled &&
showCarry &&
showBulkCarry ? (
showBulkCarry &&
!isCOGorCOJO ? (
<Input.Integer
aria-label={formsText.bulkCarryForwardCount()}
className="!w-fit"
Expand All @@ -251,65 +256,70 @@ export function SaveButton<SCHEMA extends AnySchema = AnySchema>({
}
/>
) : 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<RA<SpecifyResource<SCHEMA>>> => {
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<SerializedRecord<SCHEMA>>
>(
`/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<RA<SpecifyResource<SCHEMA>>> => [
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<RA<SpecifyResource<SCHEMA>>> => {
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<SerializedRecord<SCHEMA>>
>(
`/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<RA<SpecifyResource<SCHEMA>>> => [
await resource.clone(false),
]
)
: undefined}
{showClone && !isCOGorCOJO
? copyButton(
formsText.clone(),
formsText.cloneDescription(),
async () => [await resource.clone(true)]
)
: undefined}
{showAdd &&
copyButton(
commonText.add(),
Expand Down
12 changes: 7 additions & 5 deletions specifyweb/frontend/js_src/lib/tests/jsdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const { window } = new JSDOM('<!DOCTYPE html><p>Hello world</p>');
// 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;
Expand Down

0 comments on commit a75e847

Please sign in to comment.