Skip to content

Commit 50effd5

Browse files
committed
OCLOMRS-1044:Bug Fix: Pick Concepts from Source and Dictionaries
1 parent 2840ebc commit 50effd5

File tree

2 files changed

+72
-20
lines changed

2 files changed

+72
-20
lines changed

src/apps/concepts/components/ViewConceptsHeader.tsx

+65-18
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@ import { getContainerIdFromUrl } from "../utils";
1010
import {
1111
Button,
1212
createStyles,
13+
FormControlLabel,
14+
Grid,
15+
IconButton,
16+
Input,
17+
InputAdornment,
1318
makeStyles,
1419
Menu,
1520
MenuItem,
16-
TextField,
21+
Switch,
1722
Theme
1823
} from "@material-ui/core";
1924
import {
2025
PREFERRED_SOURCES_VIEW_ONLY,
2126
useAnchor
2227
} from "../../../utils";
2328
import { APISource } from "../../sources";
24-
import { AccountTreeOutlined, FolderOpen } from "@material-ui/icons";
29+
import { AccountTreeOutlined, FolderOpen, Search as SearchIcon } from "@material-ui/icons";
2530
import { APIDictionary } from '../../dictionaries/types';
31+
import { VerifiedSource } from "../../../components/VerifiedSource";
2632

2733
interface Props {
2834
containerType: string;
@@ -32,6 +38,8 @@ interface Props {
3238
children?: React.ReactNode[];
3339
sources: APISource[];
3440
dictionaries: APIDictionary[];
41+
showOnlyVerified: boolean;
42+
toggleShowVerified: React.ChangeEventHandler<HTMLInputElement>;
3543
}
3644

3745
const useStyles = makeStyles((theme: Theme) =>
@@ -60,6 +68,10 @@ const useStyles = makeStyles((theme: Theme) =>
6068
marginRight: "0.2rem",
6169
fill: "#8080809c"
6270
},
71+
searchInput: {
72+
textAlign: "center",
73+
fontSize: "larger"
74+
},
6375
})
6476
);
6577

@@ -70,9 +82,12 @@ const ViewConceptsHeader: React.FC<Props> = ({
7082
addConceptToDictionary,
7183
children,
7284
sources,
73-
dictionaries
85+
dictionaries,
86+
showOnlyVerified,
87+
toggleShowVerified
7488
}) => {
7589
const [showSources, setShowSources] = useState(false);
90+
const [search, setSearch] = useState("");
7691
const [preferredSources, setPreferredSources] = useState< { name: string; url: string }[] >();
7792
useEffect(() => {
7893
const defaultSources = Object.entries( PREFERRED_SOURCES_VIEW_ONLY).map(([key, value]) => ({ name: key, url: value }));
@@ -84,6 +99,7 @@ const ViewConceptsHeader: React.FC<Props> = ({
8499
} else setPreferredSources(defaultSources);
85100
}, [showSources, sources, dictionaries]);
86101

102+
87103
const classes = useStyles();
88104
const isSourceContainer = containerType === SOURCE_CONTAINER;
89105
const isAddToDictionary = isSourceContainer && !!addConceptToDictionary;
@@ -92,7 +108,6 @@ const ViewConceptsHeader: React.FC<Props> = ({
92108
handleSwitchSourceClick,
93109
handleSwitchSourceClose
94110
] = useAnchor();
95-
96111
const getTitleBasedOnContainerType = () => {
97112
return isAddToDictionary
98113
? `Import existing concept from ${getContainerIdFromUrl(containerUrl)}`
@@ -125,21 +140,53 @@ const ViewConceptsHeader: React.FC<Props> = ({
125140
keepMounted
126141
open={Boolean(switchSourceAnchor)}
127142
onClose={handleSwitchSourceClose}
128-
>
129-
<TextField
130-
multiline
131-
className={classes.textField}
132-
InputProps={{
133-
className: classes.underline
134-
}}
135-
inputProps={{
136-
className: classes.input
137-
}}
138-
value={
139-
showSources ? "Choose a source/dictionary" : "Select a different source/dictionary"
140-
}
141-
onClick={() => setShowSources(!showSources)}
143+
>
144+
<Grid
145+
container
146+
direction="column">
147+
<Button
148+
variant="text"
149+
onClick={() => setShowSources(!showSources)}
150+
>
151+
{/* {showSources ? "Select a recommended source" : "Select an alternative source"} */}
152+
</Button>
153+
{showSources &&
154+
<Input
155+
color="primary"
156+
type="search"
157+
fullWidth
158+
placeholder= {"Select an alternative source"}
159+
value={search}
160+
onChange = {event => setSearch(event.target.value)}
161+
data-testid="switch-source"
162+
endAdornment={
163+
<InputAdornment position="end">
164+
<IconButton
165+
onClick={() => setShowSources(!showSources)}
166+
data-testid="searchButton"
167+
>
168+
<SearchIcon />
169+
</IconButton>
170+
</InputAdornment>
171+
}
172+
/>
173+
}
174+
175+
<FormControlLabel
176+
control={
177+
<Switch
178+
checkedIcon={<VerifiedSource />}
179+
checked={showOnlyVerified}
180+
onChange={toggleShowVerified}
181+
color="primary"
182+
name="displayVerified"
142183
/>
184+
}
185+
label={
186+
showOnlyVerified ? `Showing verified S only` : `Show verified Sources only`
187+
}
188+
/>
189+
</Grid>
143190
{preferredSources?.map(({ name, url }) => (
144191
<MenuItem
145192
// replace because we want to keep the back button useful

src/apps/concepts/pages/ViewConceptsPage.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ const ViewConceptsPage: React.FC<Props> = ({
221221
const isImporting = dictionaryToAddTo !== undefined;
222222

223223
const [q, setQ] = useState(initialQ);
224+
const [showOnlyVerified, setShowOnlyVerified] = useState(false);
224225

225226
const gimmeAUrl = (params: QueryParams = {}, conceptsUrl: string = url) => {
226227
const newParams: QueryParams = {
@@ -231,7 +232,8 @@ const ViewConceptsPage: React.FC<Props> = ({
231232
generalFilters: generalFilters,
232233
sourceFilters: sourceFilters,
233234
page: 1,
234-
q
235+
q,
236+
235237
},
236238
...params
237239
};
@@ -305,7 +307,10 @@ const ViewConceptsPage: React.FC<Props> = ({
305307
gimmeAUrl={gimmeAUrl}
306308
addConceptToDictionary={dictionaryToAddTo}
307309
sources={sources}
308-
dictionaries={dictionaries}
310+
dictionaries={dictionaries}
311+
showOnlyVerified={showOnlyVerified}
312+
toggleShowVerified={(e)=>setShowOnlyVerified(e.target.checked)}
313+
309314
>
310315
<Grid
311316
container

0 commit comments

Comments
 (0)