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

16882 user saved views UI #1544

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions moped-database/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5074,8 +5074,8 @@
permission:
check: {}
set:
created_by_user_id: x-hasura-x-hasura-user-db-id
updated_by_user_id: x-hasura-x-hasura-user-db-id
created_by_user_id: x-hasura-user-db-id
updated_by_user_id: x-hasura-user-db-id
columns:
- description
- is_deleted
Expand All @@ -5086,8 +5086,8 @@
permission:
check: {}
set:
created_by_user_id: x-hasura-x-hasura-user-db-id
updated_by_user_id: x-hasura-x-hasura-user-db-id
created_by_user_id: x-hasura-user-db-id
updated_by_user_id: x-hasura-user-db-id
columns:
- description
- is_deleted
Expand Down Expand Up @@ -5148,7 +5148,7 @@
filter: {}
check: null
set:
updated_by_user_id: x-hasura-x-hasura-user-db-id
updated_by_user_id: x-hasura-user-db-id
comment: ""
- role: moped-editor
permission:
Expand All @@ -5160,7 +5160,7 @@
filter: {}
check: null
set:
updated_by_user_id: x-hasura-x-hasura-user-db-id
updated_by_user_id: x-hasura-user-db-id
comment: ""
- table:
name: moped_users
Expand Down
57 changes: 55 additions & 2 deletions moped-editor/src/components/GridTable/FiltersChips.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React from "react";
import { Box, Typography, Chip, Grid } from "@mui/material";
import React, { useState } from "react";
import { useLocation } from "react-router-dom";
import { useMutation } from "@apollo/client";
import { Box, Typography, Chip, Grid, Button } from "@mui/material";
import makeStyles from "@mui/styles/makeStyles";
import {
advancedSearchFilterParamName,
advancedSearchIsOrParamName,
} from "src/views/projects/projectsListView/useProjectListViewQuery/useAdvancedSearch";
import { formatDateType } from "src/utils/dateAndTime";
import { FILTERS_COMMON_OPERATORS } from "./FiltersCommonOperators";
import { ADD_USER_SAVED_VIEW } from "src/queries/project";

const useStyles = makeStyles((theme) => ({
filtersList: {
Expand All @@ -19,6 +22,10 @@ const useStyles = makeStyles((theme) => ({
fontSize: ".9rem",
color: theme.palette.text.secondary,
},
saveViewButton: {
margin: theme.spacing(0.5),
marginTop: theme.spacing(1),
},
}));

/**
Expand All @@ -36,9 +43,15 @@ const FiltersChips = ({
filtersConfig,
setSearchParams,
setIsOr,
handleSnackbar
}) => {
const classes = useStyles();

const [saveView] = useMutation(ADD_USER_SAVED_VIEW);
const [IsViewSaved, setIsViewSaved] = useState(false);

let { pathname, search } = useLocation();

const filtersCount = Object.keys(filters).length;

const filtersLabels = filters.map((filter) => {
Expand Down Expand Up @@ -84,6 +97,7 @@ const FiltersChips = ({
prevSearchParams.set(advancedSearchFilterParamName, jsonParamString);
return prevSearchParams;
});
setIsViewSaved(false);
} else {
// no filters left, clear search params
setSearchParams((prevSearchParams) => {
Expand All @@ -105,12 +119,51 @@ const FiltersChips = ({
prevSearchParams.set(advancedSearchIsOrParamName, !isOr);
return prevSearchParams;
});
setIsViewSaved(false);
};

const handleSaveView = () => {
const defaultDescription = filtersLabels
.map(
(filter) =>
`${filter.filterLabel} ${filter.operatorLabel} ${filter.filterValue}`
)
.join(", ");
saveView({
variables: {
object: {
description: defaultDescription,
url: `${pathname}${search}`,
query_filters: filters,
},
},
})
.then(() => {
setIsViewSaved(true);
handleSnackbar(true, "View saved to Dashboard", "success");
})
.catch((error) => {
handleSnackbar(true, "Error saving view to Dashboard", "error", error);
});
};

return (
<Box className={classes.filtersList}>
<Typography className={classes.filtersText} component="span">
<Grid container alignItems={"center"} spacing={0.5}>
<Grid>
<Button
onClick={() => {
handleSaveView();
}}
variant="outlined"
color="primary"
className={classes.saveViewButton}
disabled={IsViewSaved}
>
SAVE VIEW
</Button>
</Grid>
{filtersCount > 1 && (
<Grid item>
<Chip
Expand Down
2 changes: 2 additions & 0 deletions moped-editor/src/components/GridTable/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const Search = ({
loading,
showMapView,
setShowMapView,
handleSnackbar
}) => {
const classes = useStyles();
const divRef = React.useRef();
Expand Down Expand Up @@ -184,6 +185,7 @@ const Search = ({
resetSimpleSearch={resetSimpleSearch}
setIsOr={setIsOr}
setSearchParams={setSearchParams}
handleSnackbar={handleSnackbar}
/>
</Grid>
<Grid item xs={12} md="auto" className={classes.downloadButtonGrid}>
Expand Down
2 changes: 2 additions & 0 deletions moped-editor/src/components/GridTable/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const SearchBar = ({
resetSimpleSearch,
setSearchParams,
setIsOr,
handleSnackbar
}) => {
const classes = useStyles();

Expand Down Expand Up @@ -173,6 +174,7 @@ const SearchBar = ({
setIsOr={setIsOr}
isOr={isOr}
setSearchParams={setSearchParams}
handleSnackbar={handleSnackbar}
/>
)}
</>
Expand Down
10 changes: 10 additions & 0 deletions moped-editor/src/queries/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -1012,3 +1012,13 @@ export const GET_PROJECTS_GEOGRAPHIES = gql`
}
}
`;

export const ADD_USER_SAVED_VIEW = gql`
mutation AddUserSavedView($object: moped_user_saved_views_insert_input!) {
insert_moped_user_saved_views_one(object: $object) {
description
url
query_filters
}
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import { useCurrentData } from "./useProjectListViewQuery/useCurrentData";
import ProjectsListViewMap from "./ProjectsListViewMap";
import dataGridProStyleOverrides from "src/styles/dataGridProStylesOverrides";
import ActivityMetrics from "src/components/ActivityMetrics";
import FeedbackSnackbar, {
useFeedbackSnackbar,
} from "src/components/FeedbackSnackbar";

export const mapSearchParamName = "map";

Expand Down Expand Up @@ -196,6 +199,9 @@ const ProjectsListViewTable = () => {
[setQueryLimit, setQueryOffset]
);

const { snackbarState, handleSnackbar, handleSnackbarClose } =
useFeedbackSnackbar();

/**
* Store the most recent version of the query in app context so that it
* can be refetched elswhere
Expand Down Expand Up @@ -231,6 +237,7 @@ const ProjectsListViewTable = () => {
loading={loading || isMapDataLoading}
showMapView={showMapView}
setShowMapView={setShowMapView}
handleSnackbar={handleSnackbar}
/>
{/*Main Table Body*/}
<Paper className={classes.paper}>
Expand Down Expand Up @@ -295,6 +302,10 @@ const ProjectsListViewTable = () => {
</Box>
</Paper>
</Container>
<FeedbackSnackbar
snackbarState={snackbarState}
handleSnackbarClose={handleSnackbarClose}
/>
</ApolloErrorHandler>
);
};
Expand Down