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

Display Classifications filter as a tree #2467

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
fa9d249
WIp
cesarvarela Oct 13, 2023
37037a9
Update discover page
cesarvarela Oct 14, 2023
396bbc0
Handle Algolia's configure prop not working
cesarvarela Oct 17, 2023
4720111
Fix range config
cesarvarela Oct 18, 2023
1e017be
Update routing tests
cesarvarela Oct 18, 2023
75593de
Remove need for custom configure context
cesarvarela Oct 19, 2023
9994318
Fix highlights in facets
cesarvarela Oct 20, 2023
83d7fac
Update tests
cesarvarela Oct 20, 2023
616ac56
Merge remote-tracking branch 'upstream/staging' into chore-discover-h…
cesarvarela Oct 21, 2023
57144e8
Reduce flake
cesarvarela Oct 21, 2023
8e3eca2
Prevent emtpy message to flash before loading
cesarvarela Oct 21, 2023
418053a
Cleanup sorting
cesarvarela Oct 21, 2023
8e5fc55
Remove unnecessary connector
cesarvarela Oct 21, 2023
cf33c20
Remove unnecessary connector
cesarvarela Oct 21, 2023
3eb93a8
Make sure Algolia setting changes are pushed to replicas
cesarvarela Oct 21, 2023
1da9549
Fix view types
cesarvarela Oct 23, 2023
074e0b1
Reduce flake
cesarvarela Oct 23, 2023
8d91294
Increase timeout
cesarvarela Oct 24, 2023
7d38981
Extract discover items for cleanliness
cesarvarela Oct 24, 2023
356cc76
Fix hydration error
cesarvarela Oct 24, 2023
df703b6
Reduce flake
cesarvarela Oct 24, 2023
101cfa7
Reduce flake
cesarvarela Oct 24, 2023
07ae275
Refactor classifications filter as tree
cesarvarela Nov 7, 2023
3d2c50b
Disable tests tmp
cesarvarela Nov 7, 2023
c73ebf8
Merge Staging
cesarvarela Nov 7, 2023
4c3478b
Reduce test flake
cesarvarela Nov 8, 2023
4c22424
Conditionally render controls based on window size
cesarvarela Nov 8, 2023
a55f470
Debounce resize
cesarvarela Nov 8, 2023
512b602
Add virtual filters to prevent refinements from getting removed from …
cesarvarela Nov 8, 2023
67b6cba
Reduce flake
cesarvarela Nov 8, 2023
2bd5594
Merge branch 'fix-discover-performance' into feature-discover-tree
cesarvarela Nov 10, 2023
fa078d2
Add search
cesarvarela Nov 10, 2023
0767fbc
Update text
cesarvarela Nov 10, 2023
a8271c7
Merge branch 'staging' into feature-discover-tree
cesarvarela Nov 10, 2023
502218e
Add search empty results message
cesarvarela Nov 10, 2023
8513509
Enable tests back
cesarvarela Nov 10, 2023
9866b0a
Handle new classification refinements url params
cesarvarela Nov 11, 2023
1be7636
Merge
cesarvarela Dec 5, 2023
ca2a064
dasda
cesarvarela Dec 5, 2023
0e34571
dfsdf
cesarvarela Dec 5, 2023
39bfe3a
fsdfsd
cesarvarela Dec 5, 2023
ea22d2e
fsdfs
cesarvarela Dec 5, 2023
3c67828
fsdfds
cesarvarela Dec 5, 2023
6995a3a
dasdas
cesarvarela Dec 5, 2023
6bd263c
sdfsdf
cesarvarela Dec 6, 2023
b4abcf0
Merge branch 'feature-run-github' into feature-discover-tree
cesarvarela Dec 20, 2023
6da42b6
Remove unwanted changes
cesarvarela Dec 20, 2023
6fc693d
Update test
cesarvarela Dec 22, 2023
73ae4f8
Merge branch 'feature-run-github' into feature-discover-tree
cesarvarela Dec 26, 2023
ec22666
Do not hide namespaces with empty results
cesarvarela Dec 26, 2023
e17b9b5
Merge remote-tracking branch 'upstream/staging' into feature-discover…
cesarvarela Dec 26, 2023
09034c3
Skip tests
cesarvarela Dec 26, 2023
8ebaa1b
Merge remote-tracking branch 'upstream/staging' into feature-discover…
cesarvarela Jan 4, 2024
6190855
Increase timeout
cesarvarela Jan 5, 2024
f17e501
Merge remote-tracking branch 'upstream/staging' into feature-discover…
cesarvarela Jan 8, 2024
fa84114
Skip image tests
cesarvarela Jan 8, 2024
57e7586
increase timeout
cesarvarela Jan 9, 2024
4e2d153
Cleanup diff
cesarvarela Jan 9, 2024
5803db6
Add missing command
cesarvarela Jan 9, 2024
6265a87
Improve legibility
cesarvarela Jan 10, 2024
052eb9a
reuse key variable
cesarvarela Jan 10, 2024
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
3 changes: 3 additions & 0 deletions site/gatsby-site/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ const config = {
rollbar: {
token: process.env.GATSBY_ROLLBAR_TOKEN,
},
discover: {
taxa: ['CSETv0', 'CSETv1', 'GMF'],
},
cloudflareR2: {
accountId: process.env.CLOUDFLARE_R2_ACCOUNT_ID,
accessKeyId: process.env.CLOUDFLARE_R2_ACCESS_KEY_ID,
Expand Down
28 changes: 28 additions & 0 deletions site/gatsby-site/cypress/e2e/integration/discover.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,32 @@ describe('The Discover app', () => {
cy.get('div[data-cy="hits-container"]').children().should('have.length.at.least', 8);
}
);

conditionalIt(
!Cypress.env('isEmptyEnvironment'),
'Search using the classifications filter',
() => {
cy.visit(url);

cy.waitForStableDOM();

cy.get('[data-cy=expand-filters]').click();

cy.contains('button', 'Classifications').click();

cy.get('[data-cy="search"] input').type('Buenos Aires');

cy.get('[data-cy="attributes"] [data-cy="Named Entities"]').contains('Buenos Aires').click();

cy.waitForStableDOM();

cy.url().should('include', 'classifications=CSETv0%3ANamed%20Entities%3ABuenos%20Aires');

cy.get('[data-cy="selected-refinements"]')
.contains('CSETv0 : Named Entities : Buenos Aires')
.should('be.visible');

cy.get('div[data-cy="hits-container"]').children().should('have.length.at.least', 1);
}
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,12 @@ describe('Incidents', () => {
it('Should display an error message if no Incident ID is provided', () => {
cy.visit('/incidents/history?incident_id=');

cy.waitForStableDOM();

cy.contains('Invalid Incident ID').should('exist');
});

it('Should display an error message if an invalid Incident ID is provided', () => {
cy.visit('/incidents/history?incident_id=xxx');

cy.waitForStableDOM();

cy.contains('Invalid Incident ID').should('exist');
});

Expand All @@ -172,7 +168,6 @@ describe('Incidents', () => {
cy.url().should('include', '/cite/10');
});

// wasn't able to get this one passing on github runners
conditionalIt.skip(
!Cypress.env('isEmptyEnvironment'),
'Should refresh Report history if the user go back on the browser',
Expand Down Expand Up @@ -217,9 +212,7 @@ describe('Incidents', () => {

cy.go('forward');

cy.waitForStableDOM();

cy.wait(['@FindIncidentHistory', '@FindEntities'], { timeout: 30000 });
cy.wait(['@FindIncidentHistory', '@FindEntities']);
}
);

Expand Down
4 changes: 2 additions & 2 deletions site/gatsby-site/cypress/e2e/integration/integrity.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Integrity', () => {
}
);

it.skip(
it(
`is_incident_report should be true for reports assigned to incidents and vice versa`,
{ requestTimeout: 60000, defaultCommandTimeout: 60000, responseTimeout: 60000 },
() => {
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('Integrity', () => {

it(
`Classifications should be linked to one and only one incident`,
{ requestTimeout: 30000, defaultCommandTimeout: 30000, responseTimeout: 30000 },
{ requestTimeout: 60000, defaultCommandTimeout: 60000, responseTimeout: 60000 },
() => {
cy.query({
query: gql`
Expand Down
80 changes: 43 additions & 37 deletions site/gatsby-site/cypress/e2e/integration/pages.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Pages', () => {

paths.forEach((path) => {
languages.forEach(({ code }) => {
it(`/${code}${path} Should not have errors`, () => {
it(`/${code}${path} Should not have errors`, { defaultCommandTimeout: 30000 }, () => {
const canonicalPath = switchLocalizedPath({ newLang: code, path });

cy.visit(canonicalPath, {
Expand Down Expand Up @@ -118,44 +118,50 @@ describe('Pages', () => {
`[rel="alternate"][hrefLang="${language.hrefLang}"][href="${alternateUrl}"]`
).should('exist');
}
});

cy.get('body')
.then(($body) => {
if ($body.find('[data-cy="cloudinary-image-wrapper"]').length) {
return true;
}
return false;
})
.then((selectorExists) => {
if (selectorExists) {
cy.get('[data-cy="cloudinary-image-wrapper"]').each(($el) => {
cy.wrap($el)
.scrollIntoView()
.find('[data-cy="cloudinary-image"]')
.should('have.attr', 'src')
.then(($src) => {
cy.request({
url: $src.toString(),
failOnStatusCode: false,
}).then((resp) => {
if (resp.status !== 200) {
// If image is failing, check if cloudinary image is hidden
cy.wrap($el)
.find('[data-cy="cloudinary-image"]')
.should('have.class', 'hidden');
// Check if placeholder image is displayed instead
cy.wrap($el)
.find('[data-cy="cloudinary-image-placeholder"]')
.should('not.have.class', 'hidden');
}
it.skip(
`/${code}${path} Should load images properly`,
{ defaultCommandTimeout: 30000 },
() => {
cy.get('body')
.then(($body) => {
if ($body.find('[data-cy="cloudinary-image-wrapper"]').length) {
return true;
}
return false;
})
.then((selectorExists) => {
if (selectorExists) {
cy.get('[data-cy="cloudinary-image-wrapper"]').each(($el) => {
cy.wrap($el)
.scrollIntoView()
.find('[data-cy="cloudinary-image"]')
.should('have.attr', 'src')
.then(($src) => {
cy.request({
url: $src.toString(),
failOnStatusCode: false,
}).then((resp) => {
if (resp.status !== 200) {
// If image is failing, check if cloudinary image is hidden
cy.wrap($el)
.find('[data-cy="cloudinary-image"]')
.should('have.class', 'hidden');
// Check if placeholder image is displayed instead
cy.wrap($el)
.find('[data-cy="cloudinary-image-placeholder"]')
.should('not.have.class', 'hidden');
}
});
});
});
});
} else {
cy.log(`No images found on page, skipping image test for path ${path}`);
}
});
});
});
} else {
cy.log(`No images found on page, skipping image test for path ${path}`);
}
});
}
);
});
});
});
78 changes: 66 additions & 12 deletions site/gatsby-site/cypress/e2e/unit/AlgoliaUpdater.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,41 @@ const reports = [
title: 'Report 23 title',
url: 'https://url.com/stuff',
},

// this report hast no parent incidents
{
_id: new ObjectID('60dd465f80935bc89e6f9b07'),
authors: ['Test User'],
date_downloaded: '2019-04-13',
date_modified: '2020-06-14',
date_published: '2015-05-19',
date_submitted: '2019-06-01',
description: 'Description of report 40',
epoch_date_downloaded: 1555113600,
epoch_date_modified: 1592092800,
epoch_date_published: 1431993600,
epoch_date_submitted: 1559347200,
image_url: 'http://url.com',
cloudinary_id: 'http://cloudinary.com',
language: 'es',
report_number: 40,
source_domain: 'blogs.wsj.com',
submitters: ['Roman Yampolskiy'],
tags: [],
text: 'Report 40 **text**',
plain_text: 'Report 40 text',
title: 'Report 40 title',
url: 'https://url.com/stuff',
},
];

const classifications = [
{
_id: '60dd465f80935bc89e6f9b00',
incidents: [1],
reports: [],
namespace: 'CSETv0',
attributes: [
// { short_name: 'Annotator', value_json: '"1"' },
// { short_name: 'Annotation Status', value_json: '"6. Complete and final"' },
// { short_name: 'Reviewer', value_json: '"5"' },
// { short_name: 'Quality Control', value_json: 'false' },
// { short_name: 'Full Description', value_json: '"On December 5, 2018, a robot punctured."' },
{ short_name: 'Named Entities', value_json: '["Amazon"]' },
{
short_name: 'Harm Type',
Expand All @@ -83,7 +105,8 @@ const classifications = [
},
{
_id: '60dd465f80935bc89e6f9b01',
incidents: [1],
incidents: [],
reports: [],
namespace: 'SHOULD NOT BE INCLUDED',
attributes: [{ short_name: 'Something', value_json: '"Great"' }],
notes: 'Nothing to see here',
Expand Down Expand Up @@ -265,7 +288,11 @@ describe('Algolia', () => {
});

cy.wrap(updater.run()).then(() => {
expect(mongoClient.connect.callCount).to.eq(4);
expect(mongoClient.connect.callCount).to.eq(1);

// english

expect(enIndex.replaceAllObjects.getCalls().length).eq(1);

expect(enIndex.replaceAllObjects.getCall(0).args[0].length).eq(2);

Expand All @@ -290,11 +317,16 @@ describe('Algolia', () => {
incident_id: 1,
epoch_incident_date: 1592092800,
incident_date: '2020-06-14',
namespaces: ['CSETv0'],
classifications: [
'CSETv0:Named Entities:Amazon',
'CSETv0:Harm Type:Harm to physical health/safety',
'CSETv0:Harm Type:Harm to physical property',
],
CSETv0: {
'Named Entities': ['Amazon'],
'Harm Type': ['Harm to physical health/safety', 'Harm to physical property'],
},
});

expect(enIndex.replaceAllObjects.getCall(0).args[0][1]).to.deep.nested.include({
Expand All @@ -318,13 +350,29 @@ describe('Algolia', () => {
incident_id: 1,
incident_date: '2020-06-14',
epoch_incident_date: 1592092800,
namespaces: ['CSETv0'],
classifications: [
'CSETv0:Named Entities:Amazon',
'CSETv0:Harm Type:Harm to physical health/safety',
'CSETv0:Harm Type:Harm to physical property',
],
CSETv0: {
'Named Entities': ['Amazon'],
'Harm Type': ['Harm to physical health/safety', 'Harm to physical property'],
},
});

expect(enIndex.deleteBy.getCall(0).args[0]).deep.eq({
filters: 'incident_id = 247',
});

``;
// spanish

expect(esIndex.replaceAllObjects.getCalls().length).eq(1);

expect(esIndex.replaceAllObjects.getCall(0).args[0].length).eq(2);

expect(esIndex.replaceAllObjects.getCall(0).args[0][0]).to.deep.nested.include({
authors: ['Alistair Barr'],
description: 'Description of report 1',
Expand All @@ -346,11 +394,16 @@ describe('Algolia', () => {
incident_id: 1,
incident_date: '2020-06-14',
epoch_incident_date: 1592092800,
namespaces: ['CSETv0'],
classifications: [
'CSETv0:Named Entities:Amazon',
'CSETv0:Harm Type:Harm to physical health/safety',
'CSETv0:Harm Type:Harm to physical property',
],
CSETv0: {
'Named Entities': ['Amazon'],
'Harm Type': ['Harm to physical health/safety', 'Harm to physical property'],
},
featured: 0,
});

Expand All @@ -375,23 +428,24 @@ describe('Algolia', () => {
incident_id: 1,
incident_date: '2020-06-14',
epoch_incident_date: 1592092800,
namespaces: ['CSETv0'],
classifications: [
'CSETv0:Named Entities:Amazon',
'CSETv0:Harm Type:Harm to physical health/safety',
'CSETv0:Harm Type:Harm to physical property',
],
CSETv0: {
'Named Entities': ['Amazon'],
'Harm Type': ['Harm to physical health/safety', 'Harm to physical property'],
},
featured: 2,
});

expect(enIndex.deleteBy.getCall(0).args[0]).deep.eq({
filters: 'incident_id = 247',
});

expect(esIndex.deleteBy.getCall(0).args[0]).deep.eq({
filters: 'incident_id = 247',
});

expect(mongoClient.close.callCount).to.eq(4);
expect(mongoClient.close.callCount).to.eq(1);
});
});
});
3 changes: 2 additions & 1 deletion site/gatsby-site/cypress/e2e/unit/discover/routing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Discover routing', () => {
expect(state.refinementList).to.deep.eq({
source_domain: ['theguardian.com'],
authors: ['Christopher Knaus', 'Sam Levin'],
classifications: ['CSETv0:Intent:Accident'],
'CSETv0.Intent': ['Accident'],
is_incident_report: ['true'],
});
expect(state.range).to.deep.eq({
Expand All @@ -40,6 +40,7 @@ describe('Discover routing', () => {
indexName,
locale: 'en',
queryConfig,
taxa: ['CSETv0', 'CSETv1'],
});

expect('?' + resultURL).to.eq(location.search);
Expand Down
7 changes: 5 additions & 2 deletions site/gatsby-site/src/components/discover/Discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export default function Discover() {
return null;
}

const taxa = config.discover.taxa;

return (
<InstantSearch
searchClient={searchClient}
Expand All @@ -69,8 +71,9 @@ export default function Discover() {
getLocation: () => {
return window.location;
},
parseURL: ({ location }) => parseURL({ location, indexName, queryConfig }),
createURL: ({ routeState }) => createURL({ indexName, locale, queryConfig, routeState }),
parseURL: ({ location }) => parseURL({ location, indexName, queryConfig, taxa }),
createURL: ({ routeState }) =>
createURL({ indexName, locale, queryConfig, routeState, taxa }),
push: (url) => {
navigate(`?${url}`);
},
Expand Down
Loading
Loading