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

COR-487: search page #395

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

COR-487: search page #395

wants to merge 15 commits into from

Conversation

internetti
Copy link
Member

@internetti internetti commented Mar 28, 2022

COR-487

list all recipients in table on search page.

used the Recipient.get function in the Recipient.list function, to be able to show the names in the table. turned off the fetching of the subforms for that usecase.

Copy link
Member

@neb42 neb42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the data loading and table data is wrong here. You're currently getting the ancestors of the leaf node and showing a table for each (with the wrong fields for them). I think it'll be best to merge in the leaf node pr and then change it to do this:

  1. Read leaf node forms from context
  2. Select first leaf node from list (temporary until we have a UI to choose between leaf nodes)
  3. List records for leaf node
  4. Render a single table for leaf node

We can also probably look at rendering less table columns. Maybe something like 5 columns, starting at the root of FormWithRecord and working down.


I don't think the table is growing to the full width. If you use a form with less columns they wont grow to fit the space.

export type RecordListRequest = {
databaseId: string;
formId: string;
subforms?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change this to something like fetchSubforms

import { RecordLookup } from './Record';

export type Recipient = Record;
export type RecipientList = RecordList;
export type RecipientListResponse = Response<FormLookup, RecipientList>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is used

Comment on lines +4 to +12
id: `record${index}`,
values: form.fields.map((f) => {
return {
value: `value-${f.id}`,
fieldId: f.id,
};
}),
formId: form.id,
databaseId: 'databaseId',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these fake ids it'd be good to be consistent with the format. My preference is for foo-${id} for ids and foo ${name} for named things (eg. name, description), but happy with whatever as long as it's consistent.

});
});

describe('error', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error test for when this.get fails

@@ -29,7 +29,7 @@ jest.mock('../../../components/Recipient/RecipientViewer', () => {
};
});

const makeFormWithRecord = (i: number): FormWithRecord<Recipient> => {
export const makeFormWithRecord = (i: number): FormWithRecord<Recipient> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be moved to the mock data rather than just exported?

@@ -10,11 +10,13 @@ import { RecipientListTableEntry, SortedFilteredTable } from './types';

type Props<T extends Record> = {
data: FormWithRecord<T>[][];
form: FormDefinition;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this needs to be passed in. We can calculate the columns from FormWithRecord

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought so initially too, but data might be an empty array, then we should still be able to show the table header, need the form for that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For that state I'd typically replace the table with some form of placeholder text (the subform table does something like this)

@internetti internetti changed the base branch from COR-491_tableComponent to main May 3, 2022 13:35
public list = async ({
formId,
databaseId,
}: FormLookup): Promise<FormWithRecord<Recipient>[][]> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is worth doing outside of this pr as a refactor later.

I'm thinking FormWithRecord<Recipient>[][] isn't the best return type here as we're duplicating a lot of data as the forms are the same for each record. We could probably reduce the api calls made by doing a list for each form and then connecting the records together.

Something like:

{
  forms: FormDefinition[];
  records: Record<string, Record>[]; // Different Record types
}

or

{
  forms: FormDefinition[];
  records: Record[][];
}

or maybe FormWithRecord<Recipient>[][] is the best return type as it's used by the frontend widely, but how we build it could be changed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, the current structure is definitely not ideal, we should do this when we find time

@internetti internetti changed the base branch from main to recipient-form-leaf-nodes May 5, 2022 09:49
Copy link
Member

@neb42 neb42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this yet as I'm having local tunnel issues

onRowClick: (id: string) => void;
handleRowClick: () => void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you renamed this prop? I think the name was correct.

I'd typically name event function props onSomething because it is what happens when that event occurs. The function being passed in I'd typically name handleSomething as it is handling the event.

<VStack>
<FlatList data={rows} renderItem={renderRow} />
</VStack>
<Box mb="63px">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a few spacing things in here that should use a spacing token. Here either mb={16} or mb="nrc_?". I do think we should move our nrc spacing to the proper spacing naming though.

Also I think if the designs use a number that isn't a multiple of 5 then we should just round.


import { RecipientListTableEntry } from './types';

export const createTableColumns = (
data: FormWithRecord<Record>[][],
recipientWithForm: FormWithRecord<Recipient>[] | null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just pass the form in here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because I need all of the forms of one recipient, this was the easiest way to get them

);
const memoizedColumns = React.useMemo(
() => createTableColumns(data),
[JSON.stringify(data)],
() => createTableColumns(recipientState.data && recipientState.data[0]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you just pass the form in then this can be the form from the props

<ScrollView bg="white">
<Box bg="secondary.100" width="100%" my="16px" alignItems="center">
<Box maxWidth={1180} width="100%">
<Box mr="auto" mt="26px" mb="42px" maxWidth={580} width="100%">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

px

</Styles.Container>
<ScrollView bg="white">
<Box bg="secondary.100" width="100%" my="16px" alignItems="center">
<Box maxWidth={1180} width="100%">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not need px?

</Box>

<Box maxWidth={1180} mx="auto" width="100%">
{forms?.map((form) => (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have !isLoading otherwise if we had some refresh functionality this would show both the table and skeleton.

@@ -2,10 +2,64 @@ import React from 'react';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests in this file seem out of date and aren't really testing anything

: [() => Promise.resolve(), { data, loading: false, error: null }],
);
const { toJSON } = render(<RecipientListScreenContainer />);
expect(toJSON()).toMatchSnapshot();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think snapshot tests are that useful for containers. What you want to test is that given "x" the component is rendered with the correct props. To do this I normally mock the component to return something like:

<View>
  <Text>{stringProps}</Text>
  <Text>{JSON.stringify(objectProp)}</Text>
</View>

@rational-terraforming-golem
Copy link
Contributor

@internetti: Adding label do-not-merge/contains-merge-commits because PR contains merge commits, which are not allowed in this repository.
Use git rebase to reapply your commits on top of the target branch. Detailed instructions for doing so can be found here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@rational-terraforming-golem
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: internetti

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sonarcloud
Copy link

sonarcloud bot commented May 11, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@internetti internetti marked this pull request as ready for review May 11, 2022 09:06
@internetti internetti changed the base branch from recipient-form-leaf-nodes to main May 11, 2022 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants