Skip to content

Commit

Permalink
Merge pull request #4158 from unicef/fix/optimise-programs-list
Browse files Browse the repository at this point in the history
Optimise programs list page
  • Loading branch information
patryk-dabrowski authored Aug 26, 2024
2 parents e79542a + 078b0da commit a0a22c1
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 22 deletions.
8 changes: 3 additions & 5 deletions frontend/fixtures/programs/fakeApolloAllPrograms.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AllProgramsDocument } from '../../src/__generated__/graphql';
import { AllProgramsForTableDocument } from '../../src/__generated__/graphql';

export const fakeApolloAllPrograms = [
{
request: {
query: AllProgramsDocument,
query: AllProgramsForTableDocument,
variables: {
businessArea: 'afghanistan',
search: '',
Expand Down Expand Up @@ -34,8 +34,7 @@ export const fakeApolloAllPrograms = [
{
cursor: 'YXJyYXljb25uZWN0aW9uOjA=',
node: {
id:
'UHJvZ3JhbU5vZGU6ZDM4YWI4MTQtOTQyNy00ZmJkLTg4ODctOGUyYzlkMzcxYjg2',
id: 'UHJvZ3JhbU5vZGU6ZDM4YWI4MTQtOTQyNy00ZmJkLTg4ODctOGUyYzlkMzcxYjg2',
name: 'Notice hair fall college enough perhaps.',
startDate: '2020-01-20',
endDate: '2020-08-19',
Expand All @@ -48,7 +47,6 @@ export const fakeApolloAllPrograms = [
populationGoal: 507376,
sector: 'EDUCATION',
totalNumberOfHouseholds: 12,
totalNumberOfHouseholdsWithTpInProgram: 12,
__typename: 'ProgramNode',
},
__typename: 'ProgramNodeEdge',
Expand Down
108 changes: 108 additions & 0 deletions frontend/src/__generated__/graphql.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions frontend/src/apollo/queries/program/AllProgramsForTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { gql } from '@apollo/client';

export const AllProgramsForTable = gql`
query AllProgramsForTable(
$before: String
$after: String
$first: Int
$last: Int
$status: [String]
$sector: [String]
$businessArea: String!
$search: String
$numberOfHouseholds: String
$budget: String
$startDate: Date
$endDate: Date
$orderBy: String
$dataCollectingType: String
) {
allPrograms(
before: $before
after: $after
first: $first
last: $last
status: $status
sector: $sector
businessArea: $businessArea
search: $search
numberOfHouseholds: $numberOfHouseholds
budget: $budget
orderBy: $orderBy
startDate: $startDate
endDate: $endDate
dataCollectingType: $dataCollectingType
) {
pageInfo {
hasNextPage
hasPreviousPage
endCursor
startCursor
}
totalCount
edgeCount
edges {
cursor
node {
id
name
startDate
endDate
status
budget
sector
totalNumberOfHouseholds
}
}
}
}
`;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AllProgramsQuery } from '@generated/graphql';
import { AllProgramsForTableQuery } from '@generated/graphql';
import { HeadCell } from '@components/core/Table/EnhancedTableHead';

export const headCells: HeadCell<
AllProgramsQuery['allPrograms']['edges'][number]['node']
AllProgramsForTableQuery['allPrograms']['edges'][number]['node']
>[] = [
{
disablePadding: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import * as React from 'react';
import { act } from '@testing-library/react';
import wait from 'waait';
import { ProgrammesTable } from '.';
import { render, ApolloLoadingLink } from '../../../testUtils/testUtils';
import { render } from '../../../testUtils/testUtils';
import { fakeProgramChoices } from '../../../../fixtures/programs/fakeProgramChoices';
import { fakeApolloAllPrograms } from '../../../../fixtures/programs/fakeApolloAllPrograms';
import {ApolloLink} from "@apollo/client";

describe('containers/tables/ProgrammesTable', () => {
const initialFilter = {
Expand Down Expand Up @@ -39,10 +38,7 @@ describe('containers/tables/ProgrammesTable', () => {

it('should render loading', () => {
const { container } = render(
<MockedProvider
addTypename={false}
mocks={fakeApolloAllPrograms}
>
<MockedProvider addTypename={false} mocks={fakeApolloAllPrograms}>
<ProgrammesTable
businessArea="afghanistan"
filter={initialFilter}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ReactElement } from 'react';
import { useTranslation } from 'react-i18next';
import {
AllProgramsQuery,
AllProgramsQueryVariables,
AllProgramsForTableQuery,
AllProgramsForTableQueryVariables,
ProgrammeChoiceDataQuery,
useAllProgramsQuery,
useAllProgramsForTableQuery,
} from '@generated/graphql';
import { TableWrapper } from '@components/core/TableWrapper';
import { UniversalTable } from '../UniversalTable';
Expand All @@ -23,7 +23,7 @@ export function ProgrammesTable({
choicesData,
}: ProgrammesTableProps): ReactElement {
const { t } = useTranslation();
const initialVariables: AllProgramsQueryVariables = {
const initialVariables: AllProgramsForTableQueryVariables = {
businessArea,
search: filter.search,
startDate: filter.startDate || null,
Expand All @@ -40,12 +40,12 @@ export function ProgrammesTable({
return (
<TableWrapper>
<UniversalTable<
AllProgramsQuery['allPrograms']['edges'][number]['node'],
AllProgramsQueryVariables
AllProgramsForTableQuery['allPrograms']['edges'][number]['node'],
AllProgramsForTableQueryVariables
>
title={t('Programmes')}
headCells={headCells}
query={useAllProgramsQuery}
query={useAllProgramsForTableQuery}
queriedObjectName="allPrograms"
initialVariables={initialVariables}
renderRow={(row) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import TableCell from '@mui/material/TableCell';
import * as React from 'react';
import { useNavigate } from 'react-router-dom';
import { AllProgramsQuery, ProgrammeChoiceDataQuery } from '@generated/graphql';
import {
AllProgramsForTableQuery,
ProgrammeChoiceDataQuery,
} from '@generated/graphql';
import { BlackLink } from '@components/core/BlackLink';
import { StatusBox } from '@components/core/StatusBox';
import { ClickableTableRow } from '@components/core/Table/ClickableTableRow';
Expand All @@ -14,7 +17,7 @@ import {
} from '@utils/utils';

interface ProgrammesTableRowProps {
program: AllProgramsQuery['allPrograms']['edges'][number]['node'];
program: AllProgramsForTableQuery['allPrograms']['edges'][number]['node'];
choicesData: ProgrammeChoiceDataQuery;
}

Expand Down

0 comments on commit a0a22c1

Please sign in to comment.