Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.

Commit ff52c8b

Browse files
committed
fix(taboule): display many Taboule instances in tabs
1 parent ddd9ea9 commit ff52c8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1080
-698
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

packages/taboule/package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@
1616
"dependencies": {
1717
"@emotion/react": "^11.9.0",
1818
"@emotion/styled": "^11.8.1",
19-
"@material-ui/core": "^4.12.4",
20-
"@material-ui/icons": "^4.11.3",
21-
"@material-ui/styles": "^4.11.5",
22-
"@material-ui/x-license": "^4.0.0-alpha.37",
2319
"@mui/icons-material": "^5.8.0",
2420
"@mui/material": "^5.8.0",
2521
"@mui/styled-engine": "^5.8.0",
26-
"@mui/x-data-grid": "^5.11.1",
22+
"@mui/x-data-grid": "^5.17.11",
2723
"avenger": "^7.0.1",
2824
"axios": "^0.24.0",
2925
"date-fns": "^2.28.0",

packages/taboule/public/index.html

+69-34
Original file line numberDiff line numberDiff line change
@@ -13,88 +13,123 @@
1313
<div>
1414
<h2>Taboule</h2>
1515
<div>
16+
<div style="display: inline-block">
17+
<div id="taboule-show-inputs" style="display: inline">
18+
<label>Show Params Inputs</label>
19+
<input type="checkbox" checked="true" />
20+
</div>
21+
<div id="taboule-show-as-tabs">
22+
<label>Show As Tabbed</label>
23+
<input type="checkbox" />
24+
</div>
25+
</div>
26+
1627
<select id="taboule-query-value">
17-
<option value="YCAIYCAIccRelatedUsers">
28+
<option value="YCAIccRelatedUsers">
1829
YCAI Content creator Related Users
1930
</option>
20-
<option value="youtubePersonalSearches">
21-
Youtube Personal Searches
22-
</option>
23-
<option value="youtubePersonalVideos">Youtube Personal Videos</option>
24-
<option value="youtubePersonalHomes">Youtube Personal Homes</option>
25-
<option value="youtubePersonalAds">Youtube Personal ADS</option>
31+
<option value="youtubePersonalSearches">YT Personal Searches</option>
32+
<option value="youtubePersonalVideos">YT Personal Videos</option>
33+
<option value="youtubePersonalHomes">YT Personal Homes</option>
34+
<option value="youtubePersonalAds">YT Personal ADS</option>
2635
<option value="youtubeGetExperimentById">
27-
Youtube Compare Experiment
28-
</option>
29-
<option value="youtubeGetExperimentList">
30-
Youtube Experiment list
36+
YT Compare Experiment
3137
</option>
38+
<option value="youtubeGetExperimentList">YT Experiment list</option>
3239
<option value="tikTokPersonalHTMLSummary">
33-
TikTok Personal HTML Summary
40+
TK Personal HTML Summary
3441
</option>
3542
<option value="tikTokPersonalSearch">
36-
TikTok Personal Metadata: search
43+
TK Personal Metadata: search
3744
</option>
3845
<option value="tikTokPersonalNative">
39-
TikTok Personal Metadata: native
40-
</option>
41-
<option value="tikTokSearches" selected>
42-
TikTok (Collective) Searches
46+
TK Personal Metadata: native
4347
</option>
48+
<option value="tikTokPersonalForYou">TK Personal ForYou</option>
49+
<option value="tikTokPersonalFollowing">TK Personal Following</option>
4450
</select>
45-
<div id="taboule-show-inputs" style="display: inline">
46-
<label>Show Params Inputs</label>
47-
<input type="checkbox" checked="true" />
48-
</div>
4951
</div>
5052
<div id="main"></div>
5153
</div>
5254
</body>
5355
<script type="text/javascript" src="./taboule.js"></script>
5456
<script type="text/javascript">
55-
// var baseURL = 'http://localhost:9000/api/';
56-
var baseURL = 'http://localhost:14000/api/';
57+
var baseURL = 'http://localhost:9000/api/';
58+
// var baseURL = 'http://localhost:14000/api/';
5759
// var baseURL = 'https://tiktok.tracking.exposed/api/';
5860
// var baseURL = 'https://youtube.tracking.exposed/api/';
5961

6062
const querySelect = document.querySelector('#taboule-query-value');
6163
const showInputCheckbox = document.querySelector(
6264
'#taboule-show-inputs input'
6365
);
66+
const showsAsTabInput = document.querySelector(
67+
'#taboule-show-as-tabs input'
68+
);
6469

65-
const runTaboule = (query, showInput = false) => {
70+
const getSelectedQueries = () => {
71+
const els = querySelect.querySelectorAll('option:checked');
72+
return Array.from(els).map((el) => ({
73+
value: el.value,
74+
label: el.innerHTML,
75+
}));
76+
};
77+
78+
const runTaboule = (queries, showInput = false) => {
6679
window.Taboule({
6780
showInput: showInput,
6881
node: document.getElementById('main'),
6982
baseURL: baseURL,
70-
query: query,
7183
pageSize: 25,
7284
initialParams: {
7385
publicKey: 'H7AsuUszehN4qKTj2GYYwNNzkJVqUQBRo2wgKevzeUwx',
7486
},
87+
queries,
7588
});
7689
};
7790

91+
querySelect.setAttribute('multiple', 'true');
92+
showsAsTabInput.setAttribute('checked', 'true');
93+
7894
querySelect.addEventListener('change', (e) => {
79-
runTaboule(
80-
e.target.value,
81-
showInputCheckbox.getAttribute('checked') === 'true'
82-
);
95+
const values = getSelectedQueries();
96+
runTaboule(values, showInputCheckbox.getAttribute('checked') === 'true');
8397
});
8498

8599
showInputCheckbox.addEventListener('change', (e) => {
86100
const isChecked = e.currentTarget.getAttribute('checked') === 'true';
87101
e.currentTarget.setAttribute('checked', isChecked ? 'false' : 'true');
88-
runTaboule(querySelect.value, !isChecked);
102+
runTaboule(getSelectedQueries(), !isChecked);
103+
});
104+
105+
showsAsTabInput.addEventListener('change', (e) => {
106+
let isChecked = e.currentTarget.getAttribute('checked') === 'true';
107+
e.currentTarget.setAttribute('checked', isChecked ? 'false' : 'true');
108+
isChecked = e.currentTarget.getAttribute('checked') === 'true';
109+
if (isChecked) {
110+
querySelect.setAttribute('multiple', 'true');
111+
} else {
112+
querySelect.removeAttribute('multiple');
113+
}
89114
});
90115

91116
console.log(
92117
'show input checked?',
93118
showInputCheckbox.getAttribute('checked')
94119
);
95-
runTaboule(
96-
querySelect.value,
97-
showInputCheckbox.getAttribute('checked') === 'true'
98-
);
120+
121+
console.log('show tabs?', showsAsTabInput.getAttribute('checked'));
122+
123+
['youtubePersonalSearches', 'youtubePersonalVideos'].forEach((v) => {
124+
const option = querySelect.querySelector(`option[value="${v}"]`);
125+
option?.setAttribute('checked', 'true');
126+
});
127+
128+
setTimeout(() => {
129+
runTaboule(
130+
getSelectedQueries(),
131+
showInputCheckbox.getAttribute('checked') === 'true'
132+
);
133+
}, 1000);
99134
</script>
100135
</html>

packages/taboule/src/components/ErrorOverlay.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box } from '@material-ui/core';
1+
import { Box } from '@mui/material';
22
import { ErrorBox } from '@shared/components/Error/ErrorBox';
33
import * as React from 'react';
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Box from '@mui/material/Box';
2+
import Typography from '@mui/material/Typography';
3+
import * as React from 'react';
4+
5+
interface TabPanelProps {
6+
children?: React.ReactNode;
7+
index: number;
8+
value: number;
9+
}
10+
11+
export const TabPanel: React.FC<TabPanelProps> = (props) => {
12+
const { children, value, index, ...other } = props;
13+
14+
return (
15+
<div
16+
role="tabpanel"
17+
hidden={value !== index}
18+
id={`simple-tabpanel-${index}`}
19+
aria-labelledby={`simple-tab-${index}`}
20+
{...other}
21+
>
22+
{value === index && (
23+
<Box sx={{ p: 3 }}>
24+
<Typography>{children}</Typography>
25+
</Box>
26+
)}
27+
</div>
28+
);
29+
};
30+
31+
export function a11yProps(index: number): any {
32+
return {
33+
id: `simple-tab-${index}`,
34+
'aria-controls': `simple-tabpanel-${index}`,
35+
};
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import Box from '@mui/material/Box';
2+
import Tab from '@mui/material/Tab';
3+
import Tabs from '@mui/material/Tabs';
4+
import * as React from 'react';
5+
import { TabouleQueries } from '../state/queries';
6+
import { Taboule, TabouleProps } from './Taboule';
7+
import { a11yProps, TabPanel } from './TabPanel';
8+
9+
interface TabbedTabouleProps<Q extends keyof TabouleQueries>
10+
extends Omit<TabouleProps<Q>, 'query'> {
11+
queries: Array<{
12+
label: string;
13+
value: Q;
14+
}>;
15+
}
16+
17+
export const TabbedTaboule: React.FC<
18+
TabbedTabouleProps<keyof TabouleQueries>
19+
> = ({ queries: tabs, ...props }) => {
20+
const [value, setValue] = React.useState(0);
21+
22+
const handleChange = (
23+
event: React.SyntheticEvent,
24+
newValue: number
25+
): void => {
26+
setValue(newValue);
27+
};
28+
29+
return (
30+
<Box sx={{ width: '100%' }}>
31+
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
32+
<Tabs
33+
value={value}
34+
onChange={handleChange}
35+
aria-label="basic tabs example"
36+
>
37+
{tabs.map((t, i) => (
38+
<Tab
39+
key={t.value}
40+
label={t.label}
41+
{...a11yProps(i)}
42+
style={{ marginLeft: 10, marginR: 10 }}
43+
/>
44+
))}
45+
</Tabs>
46+
</Box>
47+
48+
{tabs.map((t, i) => (
49+
<TabPanel key={t.value} value={value} index={i}>
50+
<Taboule {...props} query={t.value} />
51+
</TabPanel>
52+
))}
53+
</Box>
54+
);
55+
};

0 commit comments

Comments
 (0)