Skip to content

Commit

Permalink
Remove duplicated query and limit users to 9999 (#2372)
Browse files Browse the repository at this point in the history
* Remove duplicated query and limit users to 9999

* Trigger deploy

* Fix map of editors

* Fix admin test to use mock

* Add missing users to. mock

* Fix users list

* Fix user selection on userfields dropdown
  • Loading branch information
clari182 authored Nov 20, 2023
1 parent baa42cf commit 035af83
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
8 changes: 5 additions & 3 deletions site/gatsby-site/src/components/users/UsersField.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useState } from 'react';
import { useField } from 'formik';
import { AsyncTypeahead, Token } from 'react-bootstrap-typeahead';
import { useQuery } from '@apollo/client';
import { FIND_USERS_FIELDS_ONLY } from '../../graphql/users';
import { FIND_USERS } from '../../graphql/users';

const filterBy = (option, text) => {
return (
Expand All @@ -15,7 +15,7 @@ const filterBy = (option, text) => {
export default function UsersField({ id, name, placeHolder = '' }) {
const [{ value }, , { setTouched, setValue }] = useField({ name });

const { data } = useQuery(FIND_USERS_FIELDS_ONLY);
const { data } = useQuery(FIND_USERS);

const [loading, setLoading] = useState(true);

Expand All @@ -32,7 +32,9 @@ export default function UsersField({ id, name, placeHolder = '' }) {
if (data?.users) {
setSelected((selected) =>
selected.map(({ id }) => {
const { userId, first_name, last_name } = data.users.find((user) => user.userId == id);
const user = data.users.find((user) => user.userId == id);

const { userId, first_name = '', last_name = '' } = user || {};

return { id: userId, first_name, last_name };
})
Expand Down
13 changes: 1 addition & 12 deletions site/gatsby-site/src/graphql/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@ import gql from 'graphql-tag';

export const FIND_USERS = gql`
query FindUsers {
users {
roles
userId
first_name
last_name
}
}
`;

export const FIND_USERS_FIELDS_ONLY = gql`
query FindUsers {
users {
users(limit: 9999) {
roles
userId
first_name
Expand Down
4 changes: 2 additions & 2 deletions site/gatsby-site/src/pages/cite/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Image } from 'utils/cloudinary';
import { fill } from '@cloudinary/base/actions/resize';
import { NumberParam, useQueryParam, withDefault } from 'use-query-params';
import { FIND_REPORT, FIND_REPORT_HISTORY, UPDATE_REPORT } from '../../graphql/reports';
import { FIND_USERS_FIELDS_ONLY } from '../../graphql/users';
import { FIND_USERS } from '../../graphql/users';
import { useMutation, useQuery } from '@apollo/client/react/hooks';
import { useTranslation, Trans } from 'react-i18next';
import DefaultSkeleton from 'elements/Skeletons/Default';
Expand Down Expand Up @@ -41,7 +41,7 @@ function IncidentHistoryPage() {

const [report, setReport] = useState(null);

const { data: usersData, loading: loadingUsers } = useQuery(FIND_USERS_FIELDS_ONLY);
const { data: usersData, loading: loadingUsers } = useQuery(FIND_USERS);

const { data: reportData, loading: loadingReport } = useQuery(FIND_REPORT, {
fetchPolicy: 'network-only',
Expand Down
2 changes: 1 addition & 1 deletion site/gatsby-site/src/pages/incidents/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function EditCitePage(props) {
)}

{loading && <DefaultSkeleton />}
{incident === null && !loading && <div>Report not found</div>}
{incident === null && !loading && <div>Incident not found</div>}

{incident && (
<Formik
Expand Down
4 changes: 2 additions & 2 deletions site/gatsby-site/src/pages/incidents/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
FIND_INCIDENT_HISTORY,
UPDATE_INCIDENT,
} from '../../graphql/incidents';
import { FIND_USERS_FIELDS_ONLY } from '../../graphql/users';
import { FIND_USERS } from '../../graphql/users';
import { FIND_ENTITIES } from '../../graphql/entities';
import { FIND_CLASSIFICATION } from '../../graphql/classifications';
import { useMutation, useQuery } from '@apollo/client/react/hooks';
Expand Down Expand Up @@ -46,7 +46,7 @@ function IncidentHistoryPage(props) {

const [incidentClassifications, setIncidentClassifications] = useState([]);

const { data: usersData, loading: loadingUsers } = useQuery(FIND_USERS_FIELDS_ONLY);
const { data: usersData, loading: loadingUsers } = useQuery(FIND_USERS);

const { data: entitiesData, loading: loadingEntities } = useQuery(FIND_ENTITIES, {
fetchPolicy: 'network-only',
Expand Down

0 comments on commit 035af83

Please sign in to comment.