Skip to content

Commit

Permalink
Merge pull request #2679 from clari182/feature/quiet-submission
Browse files Browse the repository at this point in the history
Feature/quiet submission
  • Loading branch information
kepae authored Apr 1, 2024
2 parents 4913a2b + 7533d21 commit 1e36315
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 12 deletions.
4 changes: 2 additions & 2 deletions site/gatsby-site/cypress/e2e/integration/cite.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('Cite pages', () => {
expect(variables.query.report_number).to.equal(23);
expect(variables.set).deep.eq({
flag: true,
date_modified: format(now, 'yyyy-MM-dd'),
date_modified: now.toISOString(),
epoch_date_modified: getUnixTime(now),
});
});
Expand All @@ -212,7 +212,7 @@ describe('Cite pages', () => {
);

expectedReport.modifiedBy = '';
expectedReport.date_modified = format(now, 'yyyy-MM-dd');
expectedReport.date_modified = now.toISOString();
expectedReport.epoch_date_modified = getUnixTime(now);

expect(input).to.deep.eq(expectedReport);
Expand Down
3 changes: 3 additions & 0 deletions site/gatsby-site/cypress/e2e/integration/citeEdit.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ describe('Edit report', () => {
cy.get(`[name=${key}]`).clear().type(updates[key]);
});

cy.get(`[name="quiet"]`).click();

cy.setEditorText(
'## This is text in English\n\nthat is longer that eighty characters, yes eighty characters!',
'[data-cy="text"] .CodeMirror'
Expand Down Expand Up @@ -215,6 +217,7 @@ describe('Edit report', () => {
source_domain: 'test.com',
editor_notes: 'Pro iustitia tantum',
language: 'en',
quiet: true,
};

cy.wait('@updateReport').then((xhr) => {
Expand Down
6 changes: 3 additions & 3 deletions site/gatsby-site/cypress/e2e/integration/discover.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import flaggedReport from '../../fixtures/reports/flagged.json';
import unflaggedReport from '../../fixtures/reports/unflagged.json';
import config from '../../../config';
import path from 'path';
import { format, getUnixTime } from 'date-fns';
import { getUnixTime } from 'date-fns';
import { deleteReportTypenames, transformReportData } from '../../../src/utils/reports';
import { conditionalIt } from '../../support/utils';

Expand Down Expand Up @@ -267,7 +267,7 @@ describe('The Discover app', () => {
expect(variables.query.report_number).to.equal(23);
expect(variables.set).deep.eq({
flag: true,
date_modified: format(now, 'yyyy-MM-dd'),
date_modified: now.toISOString(),
epoch_date_modified: getUnixTime(now),
});
});
Expand All @@ -280,7 +280,7 @@ describe('The Discover app', () => {
);

expectedReport.modifiedBy = '';
expectedReport.date_modified = format(now, 'yyyy-MM-dd');
expectedReport.date_modified = now.toISOString();
expectedReport.epoch_date_modified = getUnixTime(now);

expect(input).to.deep.eq(expectedReport);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const submission = {
editor_similar_incidents: [],
tags: [],
user: 'user1',
quiet: false,
};

const submission_with_embedding = {
Expand Down Expand Up @@ -68,6 +69,7 @@ const submission_with_embedding = {
editor_similar_incidents: [],
tags: [],
user: 'user1',
quiet: false,
embedding: {
vector: [1, 2, 3],
from_reports: [1],
Expand Down Expand Up @@ -244,6 +246,7 @@ describe('Functions', () => {
language: 'en',
tags: [],
user: 'user1',
quiet: false,
};

expect(reportsCollection.insertOne.firstCall.args[0]).to.deep.eq(expectedReport);
Expand Down Expand Up @@ -404,6 +407,7 @@ describe('Functions', () => {
language: 'en',
tags: [],
user: 'user1',
quiet: false,
embedding: {
vector: [1, 2, 3],
from_reports: [1],
Expand Down Expand Up @@ -561,6 +565,7 @@ describe('Functions', () => {
language: 'en',
tags: [],
user: 'user1',
quiet: false,
};

expect(reportsCollection.insertOne.firstCall.args[0]).to.deep.eq(expectedReport);
Expand Down Expand Up @@ -862,6 +867,7 @@ describe('Functions', () => {
source_domain: 'projects.tampabay.com',
language: 'en',
tags: [],
quiet: false,
};

expect(reportsCollection.insertOne.firstCall.args[0]).to.deep.eq(expectedReport);
Expand Down
3 changes: 2 additions & 1 deletion site/gatsby-site/cypress/fixtures/reports/flagged.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"epoch_date_downloaded": 1559347200,
"date_submitted": "2019-06-01",
"date_modified": "2019-06-02",
"language": "en"
"language": "en",
"quiet": false
}
}
}
3 changes: 2 additions & 1 deletion site/gatsby-site/cypress/fixtures/reports/unflagged.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"epoch_date_modified": 1559347200,
"epoch_date_downloaded": 1559347200,
"date_submitted": "2019-06-01",
"date_modified": "2019-06-02"
"date_modified": "2019-06-02",
"quiet": false
}
}
}
4 changes: 4 additions & 0 deletions site/gatsby-site/i18n/locales/en/popovers.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,9 @@
"submittersLoggedIn": {
"title": "This is you!",
"text": "You are currently logged in so this submission will automatically be associated with your account. If you would like to remain anonymous, please open a private browsing window to submit."
},
"quiet": {
"title": "Quiet",
"text": "Quiet reports are those that will not be published in the 'Latest Reports' section of the homepage. Quiet reports are used for reports that are useful for internal data but do not need to be promoted. If you are unsure, leave this field blank."
}
}
4 changes: 4 additions & 0 deletions site/gatsby-site/i18n/locales/es/popovers.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,9 @@
"submittersLoggedIn": {
"title": "¡Este eres tú!",
"text": "Actualmente estás conectado, por lo que este reporte se asociará automáticamente con tu cuenta. Si deseas permanecer anónimo, por favor abre una ventana de navegación privada."
},
"quiet": {
"title": "¿Es un informe silencioso?",
"text": "Los informes silenciosos son aquellos que no se publicarán en la sección 'Últimos informes' de la página de inicio. Los informes silenciosos se utilizan para informes que son útiles para datos internos pero que no necesitan promocionarse. Si no está seguro, deje este campo en blanco."
}
}
4 changes: 4 additions & 0 deletions site/gatsby-site/i18n/locales/fr/popovers.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@
"submittersLoggedIn": {
"title": "C'est vous !",
"text": "Vous êtes actuellement connecté, donc cette soumission sera automatiquement associée à votre compte. Si vous souhaitez rester anonyme, veuillez ouvrir une fenêtre de navigation privée pour soumettre."
},
"quiet": {
"title": "Est-ce un rapport silencieux ?",
"text": "Les rapports silencieux sont ceux qui ne seront pas publiés dans la section « Derniers rapports » de la page d'accueil. Les rapports silencieux sont utilisés pour les rapports utiles pour les données internes mais qui n'ont pas besoin d'être promus. Si vous n'êtes pas sûr, laissez ce champ vide."
}
}
4 changes: 3 additions & 1 deletion site/gatsby-site/page-creators/createLandingPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const createLandingPage = async (graphql, createPage) => {
const result = await graphql(`
query LandingPage {
latestIncidents: allMongodbAiidprodIncidents(
filter: { reports: { elemMatch: { is_incident_report: { eq: true } } } }
filter: {
reports: { elemMatch: { is_incident_report: { eq: true }, quiet: { in: [null, false] } } }
}
sort: { reports: { epoch_date_submitted: DESC } }
limit: 5
) {
Expand Down
4 changes: 2 additions & 2 deletions site/gatsby-site/src/components/discover/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import CustomButton from '../../elements/Button';
import { Modal } from 'flowbite-react';
import { useUserContext } from 'contexts/userContext';
import { useLogReportHistory } from '../../hooks/useLogReportHistory';
import { format, getUnixTime } from 'date-fns';
import { getUnixTime } from 'date-fns';
import useLocalizePath from 'components/i18n/useLocalizePath';

function FlagModalContent({ reportNumber }) {
Expand All @@ -36,7 +36,7 @@ function FlagModalContent({ reportNumber }) {

const updated = {
flag: true,
date_modified: format(now, 'yyyy-MM-dd'),
date_modified: now,
epoch_date_modified: getUnixTime(now),
};

Expand Down
17 changes: 16 additions & 1 deletion site/gatsby-site/src/components/forms/IncidentReportForm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useEffect, useState } from 'react';
import { Select } from 'flowbite-react';
import { Checkbox, Select } from 'flowbite-react';
import { Form, useFormikContext } from 'formik';
import * as yup from 'yup';
import TextInputGroup from '../../components/forms/TextInputGroup';
Expand Down Expand Up @@ -425,6 +425,21 @@ const IncidentReportForm = () => {
{...TextInputGroupProps}
/>

<div className="mt-3">
<div className="flex items-center">
<Label popover="quiet" label={t('Quiet')} />
</div>
<div className="mt-1">
<Checkbox
name="quiet"
checked={values.quiet}
onChange={(e) => {
setFieldValue('quiet', e.target.checked);
}}
/>
</div>
</div>

<h4 className="mt-3">Translations</h4>

{config
Expand Down
16 changes: 15 additions & 1 deletion site/gatsby-site/src/components/submissions/SubmissionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
faTenge,
} from '@fortawesome/free-solid-svg-icons';
import FlowbiteSearchInput from 'components/forms/FlowbiteSearchInput';
import { Select } from 'flowbite-react';
import { Checkbox, Select } from 'flowbite-react';
import IncidentsField from 'components/incidents/IncidentsField';
import { graphql, useStaticQuery } from 'gatsby';

Expand Down Expand Up @@ -348,6 +348,20 @@ const SubmissionForm = ({ onChange = null }) => {
columns={['byIncidentId']}
/>

<div className="mt-3">
<div className="flex items-center">
<Label popover="quiet" label={t('Quiet')} />
</div>
<div className="mt-1">
<Checkbox
checked={values.quiet}
onChange={(e) => {
setFieldValue('quiet', e.target.checked);

Check warning on line 359 in site/gatsby-site/src/components/submissions/SubmissionForm.js

View check run for this annotation

Codecov / codecov/patch

site/gatsby-site/src/components/submissions/SubmissionForm.js#L358-L359

Added lines #L358 - L359 were not covered by tests
}}
/>
</div>
</div>

{(!values.incident_ids || values.incident_ids.length === 0) && (
<div data-cy="incident-data-section">
<hr className="my-4" />
Expand Down
4 changes: 4 additions & 0 deletions site/gatsby-site/src/graphql/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const FIND_REPORT = gql`
from_text_hash
vector
}
quiet
}
}
`;
Expand All @@ -58,6 +59,7 @@ export const FIND_REPORT_WITH_TRANSLATIONS = gql`
language
is_incident_report
inputs_outputs
quiet
translations_es: translations(input: "es") {
title
text
Expand Down Expand Up @@ -99,6 +101,7 @@ export const UPDATE_REPORT = gql`
report_number
editor_notes
language
quiet
}
}
`;
Expand Down Expand Up @@ -176,6 +179,7 @@ export const FIND_REPORT_HISTORY = gql`
url
source_domain
user
quiet
}
}
`;
Expand Down
2 changes: 2 additions & 0 deletions site/gatsby-site/src/graphql/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const FIND_SUBMISSIONS = gql`
user {
userId
}
quiet
}
}
`;
Expand Down Expand Up @@ -110,6 +111,7 @@ export const FIND_SUBMISSION = gql`
editor_similar_incidents
editor_dissimilar_incidents
status
quiet
}
}
`;
Expand Down
1 change: 1 addition & 0 deletions site/gatsby-site/src/pages/cite/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const reportFields = [
'url',
'embedding',
'inputs_outputs',
'quiet',
];

function EditCitePage(props) {
Expand Down
1 change: 1 addition & 0 deletions site/gatsby-site/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const typeDefs = `
report_number: Int
is_incident_report: Boolean
flag: Boolean
quiet: Boolean
}
type mongodbAiidprodTaxaField_list implements Node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
},
"user": {
"bsonType": "string"
},
"quiet": {
"bsonType": "bool"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
},
"status": {
"bsonType": "string"
},
"quiet": {
"bsonType": "bool"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
},
"user": {
"bsonType": "string"
},
"quiet": {
"bsonType": "bool"
}
},
"required": [
Expand Down
1 change: 1 addition & 0 deletions site/realm/functions/promoteSubmissionToReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ exports = async (input) => {
source_domain: submission.source_domain,
language: submission.language,
tags: submission.tags,
quiet: submission.quiet || false
};
if (submission.embedding) {
newReport.embedding = submission.embedding;
Expand Down

0 comments on commit 1e36315

Please sign in to comment.