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

[75] bulk add button did not work #120

Merged
merged 4 commits into from
Apr 3, 2024
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
45 changes: 33 additions & 12 deletions data-serving/data-service/src/controllers/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { CaseRevision } from '../model/case-revision';
import { Query } from 'mongoose';
import _ from 'lodash';

import { logger } from '../util/logger';

export const getCase = async (
request: Request,
): Promise<CaseDocument | null> => {
Expand Down Expand Up @@ -75,6 +77,7 @@ export const setBatchUpsertFields = async (
response: Response,
next: NextFunction,
): Promise<void> => {
const currentDate = Date.now();
// Find and map existing cases by sourceId:sourceEntryId.
const existingCasesByCaseRefCombo = new Map(
(await findCasesWithCaseReferenceData(request))
Expand Down Expand Up @@ -104,6 +107,22 @@ export const setBatchUpsertFields = async (
);
}
}
const curator = request.body.curator;
if (curator) {
c.curator = curator;
c.revisionMetadata = {
revisionNumber: 0,
creationMetadata: {
curator: curator.email,
date: currentDate,
},
updateMetadata: {
curator: curator.email,
date: currentDate,
notes: 'Creation',
},
};
}
});
// Clean up the additional metadata that falls outside the `case` entity.
delete request.body.curator;
Expand Down Expand Up @@ -226,14 +245,18 @@ export const createBatchDeleteCaseRevisions = async (
});
}

await CaseRevision.insertMany(casesToDelete, {
ordered: false,
rawResult: true,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Mongoose types don't include the `lean` option from its
// documentation: https://mongoosejs.com/docs/api.html#model_Model.insertMany
lean: true,
});
try {
await CaseRevision.insertMany(casesToDelete, {
ordered: false,
rawResult: true,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Mongoose types don't include the `lean` option from its
// documentation: https://mongoosejs.com/docs/api.html#model_Model.insertMany
lean: true,
});
} catch (err) {
logger.error(`Failed to insert some case revisions: ${err}`);
}

next();
};
Expand Down Expand Up @@ -261,8 +284,7 @@ export const createBatchUpsertCaseRevisions = async (
lean: true,
});
} catch (err) {
console.log('Failed to insert some case revisions');
console.log(err);
logger.error(`Failed to insert some case revisions: ${err}`);
}

next();
Expand Down Expand Up @@ -297,8 +319,7 @@ export const createBatchUpdateCaseRevisions = async (
lean: true,
});
} catch (err) {
console.log('Failed to insert some case revisions');
console.log(err);
logger.error(`Failed to insert some case revisions: ${err}`);
}

next();
Expand Down
14 changes: 9 additions & 5 deletions verification/curator-service/ui/src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,15 @@ export default function App(): JSX.Element {
<AutomatedSourceForm onModalClose={onModalClose} />
</Route>
)}
{user && hasAnyRole(user, [Role.Curator]) && (
<Route path="/cases/bulk">
<BulkCaseForm onModalClose={onModalClose} />
</Route>
)}
{user &&
hasAnyRole(user, [
Role.Curator,
Role.JuniorCurator,
]) && (
<Route path="/cases/bulk">
<BulkCaseForm onModalClose={onModalClose} />
</Route>
)}
{user && hasAnyRole(user, [Role.Curator]) && (
<Route path="/sources/backfill">
<AutomatedBackfill onModalClose={onModalClose} />
Expand Down
34 changes: 20 additions & 14 deletions verification/curator-service/ui/src/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,26 @@ const Sidebar = ({ drawerOpen }: SidebarProps): JSX.Element => {
>
<MenuItem>New bulk upload</MenuItem>
</Link>
<Link
to="/sources/automated"
onClick={closeCreateNewPopup}
className={classes.link}
>
<MenuItem>New automated source</MenuItem>
</Link>
<Link
to="/sources/backfill"
onClick={closeCreateNewPopup}
className={classes.link}
>
<MenuItem>New automated source backfill</MenuItem>
</Link>
{hasAnyRole(user, [Role.Curator]) && (
<>
<Link
to="/sources/automated"
onClick={closeCreateNewPopup}
className={classes.link}
>
<MenuItem>New automated source</MenuItem>
</Link>
<Link
to="/sources/backfill"
onClick={closeCreateNewPopup}
className={classes.link}
>
<MenuItem>
New automated source backfill
</MenuItem>
</Link>
</>
)}
</Menu>
</>
<List>
Expand Down
Loading