David Pomerenke
commited on
Commit
·
f723129
1
Parent(s):
dd24d65
Search field
Browse files- frontend/src/App.js +24 -7
- frontend/src/components/AutoComplete.js +50 -0
- frontend/src/index.css +8 -0
frontend/src/App.js
CHANGED
@@ -4,10 +4,14 @@ import 'primereact/resources/themes/lara-light-cyan/theme.css'
|
|
4 |
import ModelTable from './components/ModelTable'
|
5 |
import LanguageTable from './components/LanguageTable'
|
6 |
import DatasetTable from './components/DatasetTable'
|
|
|
|
|
7 |
function App () {
|
8 |
const [data, setData] = useState(null)
|
9 |
const [loading, setLoading] = useState(true)
|
10 |
const [error, setError] = useState(null)
|
|
|
|
|
11 |
|
12 |
useEffect(() => {
|
13 |
fetch('/results.json')
|
@@ -27,7 +31,18 @@ function App () {
|
|
27 |
})
|
28 |
}, [])
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
return (
|
|
|
31 |
<div style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
|
32 |
<header
|
33 |
style={{
|
@@ -53,12 +68,9 @@ function App () {
|
|
53 |
<p style={{ fontSize: '1.15rem', color: '#555', marginTop: '0' }}>
|
54 |
Tracking language proficiency of AI models for every language
|
55 |
</p>
|
|
|
56 |
</header>
|
57 |
-
<
|
58 |
-
{loading && <p>...</p>}
|
59 |
-
{error && <p>Error: {error}</p>}
|
60 |
-
{data && (
|
61 |
-
<div
|
62 |
style={{
|
63 |
display: 'flex',
|
64 |
flexDirection: 'row',
|
@@ -71,6 +83,10 @@ function App () {
|
|
71 |
paddingBottom: '5vh'
|
72 |
}}
|
73 |
>
|
|
|
|
|
|
|
|
|
74 |
<div
|
75 |
style={{
|
76 |
flex: '60vw 100vw 40vw',
|
@@ -95,10 +111,11 @@ function App () {
|
|
95 |
>
|
96 |
<DatasetTable data={data} />
|
97 |
</div>
|
98 |
-
|
99 |
)}
|
100 |
-
</
|
101 |
</div>
|
|
|
102 |
)
|
103 |
}
|
104 |
|
|
|
4 |
import ModelTable from './components/ModelTable'
|
5 |
import LanguageTable from './components/LanguageTable'
|
6 |
import DatasetTable from './components/DatasetTable'
|
7 |
+
import AutoComplete from './components/AutoComplete'
|
8 |
+
|
9 |
function App () {
|
10 |
const [data, setData] = useState(null)
|
11 |
const [loading, setLoading] = useState(true)
|
12 |
const [error, setError] = useState(null)
|
13 |
+
const [allSuggestions, setAllSuggestions] = useState([])
|
14 |
+
const [filters, setFilters] = useState([])
|
15 |
|
16 |
useEffect(() => {
|
17 |
fetch('/results.json')
|
|
|
31 |
})
|
32 |
}, [])
|
33 |
|
34 |
+
useEffect(() => {
|
35 |
+
if (data) {
|
36 |
+
const models = data.model_table.map(item => ({ type: 'Model', value: item.model, searchText: item.provider.toLowerCase() + ' ' + item.model.toLowerCase() }))
|
37 |
+
const languages = data.language_table.map(item => ({ type: 'Language', value: item.language_name, searchText: item.language_name.toLowerCase() }))
|
38 |
+
const datasets = data.dataset_table.map(item => ({ type: 'Dataset', value: item.name, searchText: item.author.toLowerCase() + ' ' + item.name.toLowerCase() + ' ' + item.tasks.map(task => task.toLowerCase()).join(' ') }))
|
39 |
+
const allSuggestions = [...models, ...languages, ...datasets]
|
40 |
+
setAllSuggestions(allSuggestions)
|
41 |
+
}
|
42 |
+
}, [data])
|
43 |
+
|
44 |
return (
|
45 |
+
<PrimeReactProvider>
|
46 |
<div style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
|
47 |
<header
|
48 |
style={{
|
|
|
68 |
<p style={{ fontSize: '1.15rem', color: '#555', marginTop: '0' }}>
|
69 |
Tracking language proficiency of AI models for every language
|
70 |
</p>
|
71 |
+
<AutoComplete allSuggestions={allSuggestions} onComplete={item => setFilters(prevFilters => [item])} />
|
72 |
</header>
|
73 |
+
<main
|
|
|
|
|
|
|
|
|
74 |
style={{
|
75 |
display: 'flex',
|
76 |
flexDirection: 'row',
|
|
|
83 |
paddingBottom: '5vh'
|
84 |
}}
|
85 |
>
|
86 |
+
{loading && <p>...</p>}
|
87 |
+
{error && <p>Error: {error}</p>}
|
88 |
+
{data && (
|
89 |
+
<>
|
90 |
<div
|
91 |
style={{
|
92 |
flex: '60vw 100vw 40vw',
|
|
|
111 |
>
|
112 |
<DatasetTable data={data} />
|
113 |
</div>
|
114 |
+
</>
|
115 |
)}
|
116 |
+
</main>
|
117 |
</div>
|
118 |
+
</PrimeReactProvider>
|
119 |
)
|
120 |
}
|
121 |
|
frontend/src/components/AutoComplete.js
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { AutoComplete as PrimeAutoComplete } from 'primereact/autocomplete'
|
2 |
+
import { useState } from 'react'
|
3 |
+
const AutoComplete = ({ allSuggestions, onComplete }) => {
|
4 |
+
const [autoComplete, setAutoComplete] = useState('')
|
5 |
+
const [suggestions, setSuggestions] = useState([])
|
6 |
+
|
7 |
+
const search = e => {
|
8 |
+
console.log(allSuggestions)
|
9 |
+
const matches = allSuggestions.filter(suggestion =>
|
10 |
+
suggestion.searchText.includes(e.query.toLowerCase())
|
11 |
+
)
|
12 |
+
setSuggestions(matches)
|
13 |
+
}
|
14 |
+
|
15 |
+
const itemTemplate = item => {
|
16 |
+
return (
|
17 |
+
<div
|
18 |
+
style={{
|
19 |
+
display: 'flex',
|
20 |
+
flexDirection: 'row',
|
21 |
+
justifyContent: 'space-between'
|
22 |
+
}}
|
23 |
+
>
|
24 |
+
<div>{item.value}</div>
|
25 |
+
<div style={{ color: 'gray' }}>{item.type}</div>
|
26 |
+
</div>
|
27 |
+
)
|
28 |
+
}
|
29 |
+
|
30 |
+
return (
|
31 |
+
<PrimeAutoComplete
|
32 |
+
placeholder='Search for model, language, or dataset'
|
33 |
+
value={autoComplete}
|
34 |
+
onChange={e => setAutoComplete(e.value)}
|
35 |
+
onSelect={e => {
|
36 |
+
setAutoComplete(e.value.value)
|
37 |
+
onComplete(e.value.value)
|
38 |
+
}}
|
39 |
+
suggestions={suggestions}
|
40 |
+
completeMethod={search}
|
41 |
+
virtualScrollerOptions={{ itemSize: 50 }}
|
42 |
+
delay={500}
|
43 |
+
autoHighlight
|
44 |
+
autoFocus
|
45 |
+
itemTemplate={itemTemplate}
|
46 |
+
/>
|
47 |
+
)
|
48 |
+
}
|
49 |
+
|
50 |
+
export default AutoComplete
|
frontend/src/index.css
CHANGED
@@ -57,3 +57,11 @@ html, body, #root {
|
|
57 |
background: linear-gradient(to bottom, #ffaa00, #ff8000);
|
58 |
color: white;
|
59 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
background: linear-gradient(to bottom, #ffaa00, #ff8000);
|
58 |
color: white;
|
59 |
}
|
60 |
+
|
61 |
+
.p-autocomplete-input {
|
62 |
+
width: max(100%, 40vw);
|
63 |
+
margin-top: 2vh;
|
64 |
+
border-radius: 0px;
|
65 |
+
border: 1px solid rgba(0, 0, 0, 0.7);
|
66 |
+
box-shadow: 3px 3px 1px 0px rgba(0, 0, 0, 0.2);;
|
67 |
+
}
|