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

Hide spinner in /cite notify button on logged out #3284

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
12 changes: 11 additions & 1 deletion site/gatsby-site/playwright/e2e-full/cite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,16 @@ test.describe('Cite pages', () => {
expect(data.subscriptions).toEqual([{ type: 'incident', incident_id: { incident_id: 3 } }]);
});

test('Should not show a spinner on notify button when not logged in', async ({ page, login }) => {

const id = 'r1';

await page.goto('/cite/1#' + id);

await expect(page.locator('[data-cy="notify-button"] [data-cy="spinner"]')).toHaveCount(0);

});

test('Should show proper entities card text', async ({ page }) => {
await page.goto('/cite/3/');
await expect(page.locator('[data-cy="alleged-entities"]')).toHaveText(
Expand Down Expand Up @@ -561,4 +571,4 @@ test.describe('Cite pages', () => {
await expect(page.getByText('Incident 4 description')).toBeVisible();
await expect(page.getByText('Alleged: Entity 2 developed an AI system deployed by Entity 1, which harmed Entity 3.')).toBeVisible()
});
});
});
8 changes: 4 additions & 4 deletions site/gatsby-site/src/components/cite/NotifyButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { Button, Spinner } from 'flowbite-react';

const { useTranslation, Trans } = require('react-i18next');

function NotifyButton({ subscribing, onClick, subscribed }) {
function NotifyButton({ subscribing, onClick, subscribed, userLoggedIn }) {
const { t } = useTranslation();

return (
<Button color="gray" onClick={onClick}>
<Button color="gray" onClick={onClick} data-cy="notify-button">
<div className="flex gap-2 items-center">
{subscribing || subscribed == undefined ? (
<div>
{userLoggedIn && (subscribing || subscribed == undefined) ? (
<div data-cy="spinner">
<Spinner size="sm" />
</div>
) : (
Expand Down
1 change: 1 addition & 0 deletions site/gatsby-site/src/components/cite/Tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function Tools({
subscribing={subscribing}
onClick={subscribeToNewReports}
subscribed={isSubscribed}
userLoggedIn={isUserLoggedIn}
/>
<Button
color="gray"
Expand Down
10 changes: 8 additions & 2 deletions site/gatsby-site/src/utils/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ module.exports.computeEntities = ({ incidents, entities, responses }) => {
});

for (const field of entityFields) {
for (const id of incident[field.property]) {
const ids = incident[field.property];

if (!ids) continue;
for (const id of ids) {
const name = getName(entities, id);

if (!entitiesHash[id]) {
Expand Down Expand Up @@ -120,7 +123,10 @@ module.exports.computeEntities = ({ incidents, entities, responses }) => {
.filter((incident) => entityFields.some((field) => incident[field.property].includes(id)))
.reduce((related, incident) => {
for (const field of entityFields) {
for (const relatedId of incident[field.property]) {
const ids = incident[field.property];

if (!ids) continue;
for (const relatedId of ids) {
if (relatedId !== id && !related.some((r) => r == relatedId)) {
related.push(relatedId);
}
Expand Down
Loading