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

[Analytics] Customization and preferences issue #1721

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,28 @@ const LocationsContentComponent = ({ selectedLocations }) => {
};

const handleLocationSelect = (item) => {
unSelectedLocations.includes(item)
? setUnSelectedLocations(unSelectedLocations.filter((location) => location._id !== item._id))
: null;
locationArray.includes(item)
? setLocationArray(locationArray.filter((location) => location._id !== item._id))
: setLocationArray((locations) => [...locations, item]);
const unSelectedIndex = unSelectedLocations.findIndex((location) => location._id === item._id);
if (unSelectedIndex !== -1) {
setUnSelectedLocations(unSelectedLocations.filter((location) => location._id !== item._id));
}
const locationIndex = locationArray.findIndex((location) => location._id === item._id);
if (locationIndex !== -1) {
setLocationArray(locationArray.filter((location) => location._id !== item._id));
} else {
const newLocationArray = [...locationArray, item];
setLocationArray(newLocationArray);
setDraggedLocations(newLocationArray);
}
setInputSelect(true);
setLocation('');
};

const removeLocation = (item) => {
setLocationArray(locationArray.filter((location) => location._id !== item._id));
const newLocationArray = locationArray.filter((location) => location._id !== item._id);
setLocationArray(newLocationArray);
setDraggedLocations(newLocationArray);
setUnSelectedLocations((locations) => [...locations, item]);
dispatch(setSelectedLocations(locationArray));
dispatch(setSelectedLocations(newLocationArray));
};

const onDragEnd = (result) => {
Expand Down Expand Up @@ -90,7 +98,7 @@ const LocationsContentComponent = ({ selectedLocations }) => {
while (unSelectedLocations.length < 8) {
const randomIndex = Math.floor(Math.random() * gridLocationsData.length);
const randomObject = gridLocationsData[randomIndex];
if (!unSelectedLocations.includes(randomObject)) {
if (!unSelectedLocations.find((location) => location._id === randomObject._id)) {
unSelectedLocations.push(randomObject);
}
}
Expand Down
3 changes: 2 additions & 1 deletion platform/src/common/components/Customise/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const CustomiseLocationsComponent = ({ toggleCustomise }) => {
});
const selectedLocations = useSelector((state) => state.grids.selectedLocations) || [];
const preferenceData = useSelector((state) => state.defaults.individual_preferences) || [];
const customisedLocations = preferenceData.length > 0 ? preferenceData[0].selected_sites : [];
const customisedLocations =
preferenceData.length > 0 ? preferenceData[0].selected_sites.slice(0, 4) : [];
const id = useSelector((state) => state.login.userInfo._id);
const chartData = useSelector((state) => state.chart);

Expand Down
2 changes: 1 addition & 1 deletion platform/src/common/components/Layout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Layout = ({ pageTitle = 'AirQo Analytics', children, topbarTitle, noBorder
? selected_sites.map((site) => site['_id'])
: chartData.chartSites;

await dispatch(setChartSites(chartSites));
await dispatch(setChartSites(chartSites.slice(0, 4)));
await dispatch(
setChartDataRange({
startDate: startDate || chartData.chartDataRange.startDate,
Expand Down
2 changes: 1 addition & 1 deletion platform/src/common/components/Modal/PrintReportModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const PrintReportModal = ({
tableRows.push(dataRow);
});

doc.autoTable({
autoTable(doc, {
columns: Object.keys(selectedColumns)
.filter((column) => selectedColumns[column])
.map((col) => ({
Expand Down
5 changes: 4 additions & 1 deletion platform/src/pages/_app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export default function App({ Component, ...rest }) {
const persistor = persistStore(store);

useEffect(() => {
if (process.env.NEXT_PUBLIC_ALLOW_DEV_TOOLS === 'staging') {
if (
process.env.NEXT_PUBLIC_ALLOW_DEV_TOOLS === 'staging' ||
process.env.NEXT_PUBLIC_ALLOW_DEV_TOOLS === 'production'
) {
return;
} else {
// Disable context menu (right click)
Expand Down
1 change: 1 addition & 0 deletions platform/src/pages/analytics/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ const AuthenticatedHomePage = () => {
<PrintReportModal
title='Share report'
open={openPrintModal}
handlePrintPDF={printFile}
onClose={() => setOpenPrintModal(false)}
data={data}
shareModel={false}
Expand Down
Loading