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

OCLOMRS-1044:Bug Fix: Pick Concepts from Source and Dictionaries #746

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jwnasambu
Copy link
Contributor

@jwnasambu jwnasambu commented Sep 22, 2021

JIRA TICKET NAME:

Bug Fix: Pick Concepts from Source and Dictionaries

Summary of what I worked on:

  1. I added a toggle to toggle between sources and dictionaries and only show one at a time.
  2. Introduced a search box, i.e., a blank text field that we can used to filter the shown sources and dictionaries
  3. Ensured all the dictionaries/sources are pulled from the backed.
  4. created a ConceptSourceSwitcher component

@jwnasambu jwnasambu marked this pull request as draft September 22, 2021 19:58
@coveralls
Copy link

coveralls commented Sep 22, 2021

Coverage Status

Coverage decreased (-0.6%) to 45.838% when pulling 3b1ecf2 on jwnasambu:OCLOMRS-1044 into 0de0c31 on openmrs:master.

@jwnasambu
Copy link
Contributor Author

This is a screenshot of what is implemented in the first part of this ticket.
https://user-images.githubusercontent.com/33891016/134416217-d542cec4-9f0c-4f1c-ae70-0edb801a6e77.mp4

color="primary"
onClick={() => setShowSources(!showSources)}
>
{showSources ? "Choose a source/dictionary" : "Select a different source/dictionary"}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this?

Suggested change
{showSources ? "Choose a source/dictionary" : "Select a different source/dictionary"}
{showSources ? "Select a recommended source" : "Select an alternative source"}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ibacher thanks for the review.

Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

@jwnasambu Thanks for this initial step. A few small adjustments and this button should be good.

<Button
variant="contained"
color="primary"
onClick={() => setShowSources(!showSources)}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
onClick={() => setShowSources(!showSources)}
onClick={() => setShowSources(!showSources)}

/>
<Button
variant="contained"
color="primary"
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a "primary" button... in fact, we probably don't really want any color for it, so the default is probably good enough.

Suggested change
color="primary"

onClick={() => setShowSources(!showSources)}
/>
<Button
variant="contained"
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to use the text variant here so it keeps the same UX

Suggested change
variant="contained"
variant="text"

@jwnasambu
Copy link
Contributor Author

@ibacher kindly I implemented the proposed changes above and I tried to introduce a search box, i.e., a blank text field that we can use to filter the shown sources and dictionaries but am stack and I kindly need your help! I want to use a stack which is from '@mui/material/Stack' am wondering if its same framework with materialUI and only differentiated by the tag.

@ibacher
Copy link
Member

ibacher commented Sep 29, 2021

mui is the rebrand of Material UI for their 5.x release. The documentation for the version we use can be found here. There's no Stack in Material UI v4, but you can use a column-oriented Grid, e.g.,

<Grid
  container
  direction="column"
  justifyContent="center"
  alignItems="center"
>
</Grid>

@jwnasambu
Copy link
Contributor Author

@ibacher thanks so so much! I really appreciate your help

@jwnasambu
Copy link
Contributor Author

@ibacher with the current changes this is what I have
Screenshot 2021-09-29 at 11 26 29 PM
Kindly feel free to comment.

@jwnasambu
Copy link
Contributor Author

@ibacher With the current changes this is the output kindly feel free to comment.

screencast.2021-09-30.8.AM-45-54.mp4

Comment on lines 133 to 192
{/* <Button
variant="text"
onClick={() => setShowSources(!showSources)}
>
{showSources ? "Select a recommended source" : "Select an alternative source"}
</Button> */}
<Input
// onChange={e => setQ(e.target.value)}
// value={q}
color="secondary"
type="search"
fullWidth
placeholder={`choose a source`}
data-testid="searchInput"
endAdornment={
<InputAdornment position="end">
<IconButton
onClick={() => setShowSources(!showSources)}
data-testid="searchButton"
>
<SearchIcon />
</IconButton>
</InputAdornment>
}
/>
Copy link
Member

Choose a reason for hiding this comment

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

@jwnasambu I can see where you're going here, but we really do want two independent elements that have relatively independent functions. Part of this is because it's very counter-intuitive (I think) to switch the list based on the icon in the search bar when that has... no obvious connection to the two lists displayed.

The onClick handler in the IconButton should trigger a search against the current list of sources (and we should only display the search bar when looking at the alternative sources, not the default sources.

Copy link
Member

Choose a reason for hiding this comment

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

I mentioned on Talk, I think, that we should use a Grid component to keep everything here orientated in a single column. So I would wrap both the Button and the Input in an element like this:

<Grid
  container
  direction="column">
// content
</Grid>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ibacher kindly ignore my current changes for I made without reading through your comment.

@jwnasambu
Copy link
Contributor Author

jwnasambu commented Oct 4, 2021

@ibacher just to ensure I don't take a wrong direction kindly help me review this work please!

@jwnasambu jwnasambu force-pushed the OCLOMRS-1044 branch 3 times, most recently from d59aba1 to a3aa7d6 Compare October 5, 2021 12:19
@jwnasambu
Copy link
Contributor Author

@ibacher Am scared of diverting from the workflow you gave me. With the changes made this is what I have

screencast.2021-10-05.3.PM-24-37.mp4

@ibacher
Copy link
Member

ibacher commented Oct 5, 2021

@jwnasambu We always want the button to switch between recommended and alternative sources to be visible (and the first thing in the list). It's only the Input field whose visibility should be toggled by which view we're on. So, rather than placing things in a big ternary (... ? ... : ...), we should have:

<Grid>
  <Button />
  {showSources && <Input />}
</Grid>

@jwnasambu
Copy link
Contributor Author

@ibacher I desire to be with you on the same page. Kindly review my changes please!

@jwnasambu jwnasambu force-pushed the OCLOMRS-1044 branch 2 times, most recently from 5365eca to 50effd5 Compare October 6, 2021 12:43
@jwnasambu
Copy link
Contributor Author

jwnasambu commented Oct 6, 2021

@ibacher kindly help me review this PR please!(thought still fixing the issue)

@jwnasambu
Copy link
Contributor Author

jwnasambu commented Oct 6, 2021

@iabcher when I use this format

<Grid>     
  <Button />
  {showSources && <Input />      
</Grid>

I'm unable to see the search box, but when I remove the button this is what I have

screencast.2021-10-07.12.AM-23-28.mp4

@jwnasambu jwnasambu force-pushed the OCLOMRS-1044 branch 5 times, most recently from bf1d1fd to d85ff7a Compare October 13, 2021 20:58
@jwnasambu
Copy link
Contributor Author

jwnasambu commented Oct 13, 2021

@ibacher this is the current output locally though the build is failing on the PR.

screencast.2021-10-14.12.AM-07-18.mp4

@jwnasambu jwnasambu marked this pull request as ready for review October 14, 2021 15:56
src/apps/concepts/components/ViewConceptsHeader.tsx Outdated Show resolved Hide resolved
@@ -381,7 +381,7 @@ export const recursivelyAddConceptsToDictionaryAction = (
}

if (!concept.hasOwnProperty("source_url") || !!!concept.source_url) {
concept.source_url = concept.url.split("/", 5).join("/") + "/";
return{...concept,source_url: concept.url.split("/", 5).join("/") + "/"}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return{...concept,source_url: concept.url.split("/", 5).join("/") + "/"}
return {...concept, source_url: concept.url.split("/", 5).join("/") + "/"};

@@ -231,7 +232,8 @@ const ViewConceptsPage: React.FC<Props> = ({
generalFilters: generalFilters,
sourceFilters: sourceFilters,
page: 1,
q
q,

Copy link
Member

Choose a reason for hiding this comment

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

Why the empty line here?

dictionaries={dictionaries}
showOnlyVerified={showOnlyVerified}
toggleShowVerified={(e)=>setShowOnlyVerified(e.target.checked)}

Copy link
Member

Choose a reason for hiding this comment

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

Why the empty line here?

@@ -84,6 +97,27 @@ const ViewConceptsHeader: React.FC<Props> = ({
} else setPreferredSources(defaultSources);
}, [showSources, sources, dictionaries]);

const fetchMoreData = () =>{
setTimeout(()=>{
const previousSources =preferredSources?.filter(Boolean).concat(Array.from({length:10}));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const previousSources =preferredSources?.filter(Boolean).concat(Array.from({length:10}));
const previousSources = preferredSources?.filter(Boolean).concat(Array.from({length: 10}));

Comment on lines 101 to 112
setTimeout(()=>{
const previousSources =preferredSources?.filter(Boolean).concat(Array.from({length:10}));
setPreferredSources(previousSources)

},1000);
Copy link
Member

Choose a reason for hiding this comment

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

This looks like some sort of simulated code? I think before we get all of these elements looped in we need to start smaller, with just either the search or the toggle. It might be easiest, oddly to just start with a search box and show a default page of 10 results or w/e.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ibacher I have just commended out the code for now!

@jwnasambu
Copy link
Contributor Author

@ibacher kindly feel free to review what I have though still flopping.

placeholder= {"Select an alternative source"}
value={q}
onChange = {e => setQ(e.target.value)}
data-testid="switch-source"
Copy link
Member

Choose a reason for hiding this comment

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

data-testid is just used to supply an id to identify something with via tests. It should only be used as a last resort. Since we don't need it here, we shouldn't have it. If we do need to assign a testid to this element, it must not be one that we've used elsewhere. This probably also applies to the other data-testid attributes in this PR.

Suggested change
data-testid="switch-source"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ibacher I have removed all the data-testid="switch-source" that I added. Kindly feel free to review my PR again.

Copy link
Member

Choose a reason for hiding this comment

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

@jwnasambu Since there's a unit test looking for the data-testid="switch-source", we can leave it in, we just need to have it assigned to as single element as it was before.

@jwnasambu jwnasambu force-pushed the OCLOMRS-1044 branch 2 times, most recently from b15f9f8 to 9b34f06 Compare October 25, 2021 19:49
@ibacher
Copy link
Member

ibacher commented Oct 26, 2021

Cool! We've got all the existing tests passing. So, one thing: would you mind reformatting the code? You should be able to do this by running npx prettier --write src/apps/concepts/components/ViewConceptsHeader.tsx.

Then we need to work on getting the data properly.

So what we've been trying to do with this is change the menu to select sources so that when you are selecting from "all available" you have a list either filtered to sources or dictionaries. This allows us to provide (I hope) a better experience.

The first thing we need is an accurate count of the number of sources and / or dictionaries to fill into the InfiniteScroll component's dataLength field. To get this, the process is roughly the same as getting the number of counts in a source / dictionary. For this, @merovingienne's great work in this PR can serve as an example. Note that it basically involves reading the num_found header in the results.

So what we want to do is issue a query to the backend to get all the sources / dictionaries and use the num_found header to populate the dataLength field.

@jwnasambu
Copy link
Contributor Author

@ibacher thanks so so much am going to do it after the call and share the experience. Thanks for the review!

@merovingienne
Copy link
Contributor

merovingienne commented Oct 27, 2021

@ibacher thank you for your kind words!

@jwnasambu let me know if you want to get anything clarified from PR 754.

@jwnasambu
Copy link
Contributor Author

@merovingienne Thanks so much! I will surely do it. Am so humbled for your wiliness to help.

@jwnasambu jwnasambu requested a review from ibacher October 28, 2021 17:30
@jwnasambu jwnasambu force-pushed the OCLOMRS-1044 branch 2 times, most recently from 9f84dab to fe7a7bb Compare November 9, 2021 09:29
@jwnasambu
Copy link
Contributor Author

@ibacher kindly help me review the changes made at your convenient time please!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants