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

SIMSBIOHUB-647: Create Observations Page #1444

Open
wants to merge 26 commits into
base: dev
Choose a base branch
from
Open

Conversation

mauberti-bc
Copy link
Collaborator

@mauberti-bc mauberti-bc commented Dec 3, 2024

Links to Jira Tickets

  • {Include a link to all applicable Jira tickets}

Description of Changes

  • Allows observations to be added from a dedicated page

Testing Notes

  • {List any relevant testing considerations, necessary pre-reqs, and areas of the app to focus on. Specifically, include anything that will help the reviewers of this PR verify the code is functioning as expected.}

TODO

  • Check frontend tests
  • Check backend tests

@mauberti-bc mauberti-bc added the Not Ready For Review Addressing feedback and/or refactoring label Dec 3, 2024
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 20.14028% with 797 lines in your changes missing coverage. Please review.

Project coverage is 45.35%. Comparing base (d1eb7b2) to head (bfa4367).

Files with missing lines Patch % Lines
...nts/sampling/hooks/useSamplingInformationCache.tsx 0.00% 76 Missing ⚠️
...veys/observations/create/CreateObservationPage.tsx 0.00% 69 Missing ⚠️
...ents/environments/environment/EnvironmentField.tsx 0.00% 69 Missing ⚠️
...onents/sampling/components/SamplingPeriodField.tsx 0.00% 57 Missing ⚠️
...nents/sampling/components/MethodTechniqueField.tsx 0.00% 55 Missing ⚠️
...mponents/sampling/components/SamplingSiteField.tsx 0.00% 45 Missing ⚠️
...s/observation-repository/observation-repository.ts 30.61% 32 Missing and 2 partials ⚠️
...i/src/repositories/observation-repository/utils.ts 60.25% 31 Missing ⚠️
...ations/form/components/subcounts/SubcountsForm.tsx 0.00% 29 Missing ⚠️
...ures/surveys/observations/form/ObservationForm.tsx 0.00% 28 Missing ⚠️
... and 49 more
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1444      +/-   ##
==========================================
- Coverage   45.92%   45.35%   -0.57%     
==========================================
  Files         907      946      +39     
  Lines       23537    24262     +725     
  Branches     3492     3639     +147     
==========================================
+ Hits        10809    11005     +196     
- Misses      12136    12649     +513     
- Partials      592      608      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mauberti-bc mauberti-bc added Early Feedback Welcome PR is not finished, but early review feedback is welcomed and removed Not Ready For Review Addressing feedback and/or refactoring labels Jan 8, 2025
@mauberti-bc mauberti-bc added Ready For Review PR is ready for review and removed Early Feedback Welcome PR is not finished, but early review feedback is welcomed labels Jan 16, 2025
@NickPhura
Copy link
Collaborator

I pushed up a few misc changes. Mostly just some component cleanup and addressing a few react dependency complaints, etc.

@NickPhura NickPhura added Early Feedback Welcome PR is not finished, but early review feedback is welcomed and removed Ready For Review PR is ready for review labels Jan 20, 2025
mauberti-bc and others added 2 commits January 21, 2025 10:06
wip

wip: create location and date sections on form

wip: style subcount form

wip: adding measurements to subcounts

add dual autocomplete

subcount form

subcount table on create observation page

fix measurement search

show measurement options in subcount table on create observation page

wip: formik validation

add subcount sign placeholder to create request

wip: environments incorrectly formatted in handlesubmit

fix incorrect key

fix environments on create observations page

fix measurement interfaces

SIMSBIOHUB-659: Add Pagination to System Alerts on Admin Page (#1459)

Add Pagination to System Alerts on Admin Page

---------

Co-authored-by: Nick Phura <[email protected]>

Update CSV Error Import Dialog Styling (#1456)

- update csv import error dialog
- replace failure snackbar & add frontend pagination to csv import errors

BugFix: Fix Type for Capture Attachments (#1460)

- modifying critter index file

---------

Co-authored-by: Macgregor Aubertin-Young <[email protected]>
Co-authored-by: Macgregor Aubertin-Young <[email protected]>

BugFix: Method Attributes SQL (#1462)

- fix sql

Added DualAutocompleteUnitField.tsx to help reduce the size of the DualAutocompleteField.tsx.
Renamed some of the dual autocomplete field props, just to make them more consistent/predictable.
Fixed missing props in create/edit technique vantages (missing category data type prop).
Add formik snackbar error component to observation form.
Addressed a few react missing dependency warnings.

Update missed jsdoc comments.

Update missed jsdoc comments 2.

WIP: Add create observation sampling fields.

Working sampling fields.

Enhancements to sampling fields
Copy link

sonarqubecloud bot commented Feb 4, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
10.1% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@NickPhura NickPhura added Ready For Review PR is ready for review and removed Early Feedback Welcome PR is not finished, but early review feedback is welcomed labels Feb 4, 2025
if (pagination.sort && pagination.order) {
if (pagination.sort === 'subcount') {
const knex = getKnex();
query.orderByRaw(knex.raw(`(subcount->>?)::numeric ${pagination.order}`, [pagination.sort]));

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query string depends on a
user-provided value
.
if (pagination.sort && pagination.order) {
if (pagination.sort === 'subcount') {
const knex = getKnex();
query.orderByRaw(knex.raw(`(subcount->>?)::numeric ${pagination.order}`, [pagination.sort]));

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query string depends on a
user-provided value
.

Copilot Autofix AI about 23 hours ago

To fix the problem, we need to ensure that the user-provided pagination.order value is safely embedded into the SQL query. This can be achieved by using parameterized queries or by explicitly validating and sanitizing the input before using it in the query.

The best way to fix this issue without changing existing functionality is to validate the pagination.order value to ensure it is either 'asc' or 'desc' before using it in the query. This can be done by using a conditional check and throwing an error if the value is invalid.

Suggested changeset 1
api/src/repositories/observation-repository/observation-repository.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api/src/repositories/observation-repository/observation-repository.ts b/api/src/repositories/observation-repository/observation-repository.ts
--- a/api/src/repositories/observation-repository/observation-repository.ts
+++ b/api/src/repositories/observation-repository/observation-repository.ts
@@ -293,2 +293,5 @@
           const knex = getKnex();
+          if (pagination.order !== 'asc' && pagination.order !== 'desc') {
+            throw new Error('Invalid order value');
+          }
           query.orderByRaw(knex.raw(`(subcount->>?)::numeric ${pagination.order}`, [pagination.sort]));
EOF
@@ -293,2 +293,5 @@
const knex = getKnex();
if (pagination.order !== 'asc' && pagination.order !== 'desc') {
throw new Error('Invalid order value');
}
query.orderByRaw(knex.raw(`(subcount->>?)::numeric ${pagination.order}`, [pagination.sort]));
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Do you think we should name this directory database-units or something like database-types / database-enums. I see in the database there is an additional type / enum for alert_severity would this also be a database-unit?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to any name for the folder. Can't remember how I landed on unit. Probably just trying to pick something generic that could cover database enums (but also any other enum-like concept, if there are others?), and which aren't specifically table models.

],
properties: {
observation_environment_qualitative_id: {
type: 'integer'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: minimum 1

required: ['observation_environment_quantitative_id', 'environment_quantitative_id', 'value'],
properties: {
observation_environment_quantitative_id: {
type: 'integer'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: minimum 1

required: ['observation_subcount_id', 'subcount', 'comment', 'qualitative_measurements', 'quantitative_measurements'],
properties: {
observation_subcount_id: {
type: 'integer'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: minimum 1

schema: {
type: 'array',
items: {
type: 'integer'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: minimum 1 / 0?

description: 'ITIS TSN number',
required: false,
schema: {
type: 'integer',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: minimum 1 / 0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review PR is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants