Skip to content

Implement searching and filtering for all records #55

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

Open
wants to merge 2 commits into
base: develop
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
.env.test.local
.env.production.local

debug.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
18 changes: 18 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tasks:
- init: npm install
command: echo DANGEROUSLY_DISABLE_HOST_CHECK=true >> .env
command: npm start
ports:
- port: 3000
onOpen: open-preview
github:
prebuilds:
master: true
branches: true
pullRequests: true
pullRequestsFromForks: true
addCheck: true
addComment: true
addBadge: false
addLabel: false

38 changes: 17 additions & 21 deletions src/components/applications/ApplicationList.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import React from "react";
import { useMediaQuery } from "@material-ui/core";
import {
List,
Datagrid,
TextField,
SimpleList,
Pagination,
ReferenceField,
} from "react-admin";

const ApplicationPagination = (props) => (
<Pagination rowsPerPageOptions={[10, 25, 50]} {...props} />
);
import { List, Datagrid, TextField, SimpleList } from "react-admin";
import Pagination from "../pagination/Pagination";
import Filter from "../pagination/Filter";

const ApplicationList = (props) => {
const isSmall = useMediaQuery((theme) => theme.breakpoints.down("sm"));
const filters = [
{
label: "Filter by name",
source: "applicationName",
alwaysOn: true,
},
{
label: "Filter by organization",
source: "organizationName",
},
];

return (
<List
label="Applications"
title="Applications"
pagination={<ApplicationPagination />}
pagination={<Pagination />}
filters={<Filter filters={filters} />}
{...props}
>
{isSmall ? (
Expand All @@ -31,14 +34,7 @@ const ApplicationList = (props) => {
) : (
<Datagrid rowClick="show">
<TextField label="Name" source="applicationName" />
<ReferenceField
link="show"
label="Organization"
source="orgId"
reference="Organizations"
>
<TextField label="Organization Name" source="organizationName" />
</ReferenceField>
Comment on lines -34 to -41
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reasoning behind this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

many thanks @simply-alliv I explained in PR description - background context..

<TextField label="Organization Name" source="organizationName" />
</Datagrid>
)}
</List>
Expand Down
12 changes: 12 additions & 0 deletions src/components/msadmins/AdminFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";
import { Filter, TextInput } from "react-admin";

const AdminFilter = (props) => (
<Filter {...props}>
<TextInput label="Search by Name" source="fullname" alwaysOn />
<TextInput label="Search by Email" source="email" />
<TextInput label="Search by Role" source="role" />
</Filter>
);

export default AdminFilter;
40 changes: 21 additions & 19 deletions src/components/msadmins/AdminList.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import React from "react";
import { useMediaQuery } from "@material-ui/core";
import {
List,
Datagrid,
TextField,
EmailField,
SimpleList,
TopToolbar,
ExportButton,
CreateButton,
} from "react-admin";

const AdminListActions = ({ basePath, data, resource }) => (
<TopToolbar>
<CreateButton basePath={basePath} />
<ExportButton basePath={basePath} record={data} resource={resource} />
</TopToolbar>
);
import { List, Datagrid, TextField, EmailField, SimpleList } from "react-admin";
import Pagination from "../pagination/Pagination";
import Filter from "../pagination/Filter";

const AdminList = (props) => {
const isSmall = useMediaQuery((theme) => theme.breakpoints.down("sm"));
const filters = [
{
label: "Filter by name",
source: "fullname",
alwaysOn: true,
},
{
label: "Filter by email",
source: "email",
},
{
label: "Filter by role",
source: "role",
},
];

return (
<List
label="Admins"
title="Admins"
actions={<AdminListActions />}
pagination={<Pagination />}
filters={<Filter filters={filters} />}
{...props}
>
{isSmall ? (
Expand All @@ -36,7 +38,7 @@ const AdminList = (props) => {
tertiaryText={(record) => record.role}
/>
) : (
<Datagrid rowClick="show" isRowSelectable={(record) => false}>
<Datagrid rowClick="show">
<TextField label="Name" source="fullname" />
<EmailField source="email" />
<TextField source="role" />
Expand Down
2 changes: 0 additions & 2 deletions src/components/msadmins/AdminShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import {
TextField,
TopToolbar,
DeleteButton,
EditButton,
} from "react-admin";

const AdminShowActions = ({ basePath, data, resource }) => (
<TopToolbar>
<EditButton basePath={basePath} record={data} />
<DeleteButton basePath={basePath} record={data} resource={resource} />
</TopToolbar>
);
Expand Down
11 changes: 11 additions & 0 deletions src/components/organizations/OrganizationFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";
import { Filter, TextInput } from "react-admin";

const OrganizationFilter = (props) => (
<Filter {...props}>
<TextInput label="Search by Name" source="organizationName" alwaysOn />
<TextInput label="Search by Email" source="organizationEmail" />
</Filter>
);

export default OrganizationFilter;
29 changes: 16 additions & 13 deletions src/components/organizations/OrganizationList.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import React from "react";
import { useMediaQuery } from "@material-ui/core";
import {
List,
Datagrid,
TextField,
EmailField,
SimpleList,
Pagination,
} from "react-admin";

const OrganizationPagination = (props) => (
<Pagination rowsPerPageOptions={[10, 25, 50]} {...props} />
);
import { List, Datagrid, TextField, EmailField, SimpleList } from "react-admin";
import Pagination from "../pagination/Pagination";
import Filter from "../pagination/Filter";

const OrganizationList = (props) => {
const isSmall = useMediaQuery((theme) => theme.breakpoints.down("sm"));
const filters = [
{
label: "Filter by name",
source: "organizationName",
alwaysOn: true,
},
{
label: "Filter by email",
source: "organizationEmail",
},
];

return (
<List
label="Organizations"
title="Organizations"
pagination={<OrganizationPagination />}
pagination={<Pagination />}
filters={<Filter filters={filters} />}
{...props}
>
{isSmall ? (
Expand Down
4 changes: 2 additions & 2 deletions src/components/organizations/OrganizationShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const OrganizationShow = (props) => {
<ReferenceManyField
link="show"
label=""
reference="Applications"
target="organizationId"
reference="Organizations"
target="id"
>
<SimpleList
className={classes.root}
Expand Down
14 changes: 14 additions & 0 deletions src/components/pagination/Filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import { Filter, TextInput } from "react-admin";

export default ({ filters, ...props }) => (
<Filter {...props}>
{filters.map((filter) => (
<TextInput
label={filter.label}
source={filter.source}
alwaysOn={filter.alwaysOn || false}
/>
))}
</Filter>
);
6 changes: 6 additions & 0 deletions src/components/pagination/Pagination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";
import { Pagination } from "react-admin";

export default (props) => (
<Pagination rowsPerPageOptions={[10, 25, 50]} {...props} />
);
10 changes: 10 additions & 0 deletions src/components/plans/PlanFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";
import { Filter, TextInput } from "react-admin";

const PlanFilter = (props) => (
<Filter {...props}>
<TextInput label="Search by Name" source="planName" alwaysOn />
</Filter>
);

export default PlanFilter;
34 changes: 16 additions & 18 deletions src/components/plans/PlanList.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import React from "react";
import { useMediaQuery } from "@material-ui/core";
import {
List,
Datagrid,
TextField,
SimpleList,
TopToolbar,
CreateButton,
ExportButton,
} from "react-admin";

const PlanListActions = ({ basePath, data, resource }) => (
<TopToolbar>
<CreateButton basePath={basePath} />
<ExportButton basePath={basePath} record={data} resource={resource} />
</TopToolbar>
);
import { List, Datagrid, TextField, SimpleList } from "react-admin";
import Pagination from "../pagination/Pagination";
import Filter from "../pagination/Filter";

const PlanList = (props) => {
const isSmall = useMediaQuery((theme) => theme.breakpoints.down("sm"));
const filters = [
{
label: "Filter by name",
source: "organizationName",
alwaysOn: true,
},
{
label: "Filter by email",
source: "organizationEmail",
},
];

return (
<List
label="Plans"
title="Plans"
actions={<PlanListActions />}
pagination={null}
pagination={<Pagination />}
filters={<Filter filters={filters} />}
{...props}
>
{isSmall ? (
Expand Down
24 changes: 16 additions & 8 deletions src/services/data-provider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fetchUtils } from "react-admin";
import endpoints from "../utils/endpoints";
import { stringify } from "querystring";
import getPaginateQuery from "../utils/pagination";
import getPaginateQuery, { filter } from "../utils/pagination";
import handleProfileData from "../utils/data/profile-data";
import {
GET_LIST,
Expand Down Expand Up @@ -29,7 +29,7 @@ export default {
const endpoint = endpoints(GET_LIST, resource, params);
return httpClient(`${endpoint.url}?${stringify(query)}`).then(
({ json }) => ({
data: endpoint.getData(json.data),
data: filter(endpoint.getData(json.data), params),
total: json.data.pageInfo
? json.data.pageInfo.totalRecord
: json.data.length,
Expand All @@ -56,12 +56,20 @@ export default {

getManyReference: (resource, params) => {
const endpoint = endpoints(GET_MANY_REFERENCE, resource, params);
return httpClient(endpoint.url).then(({ json }) => ({
data: endpoint.getData(json.data, endpoint.target, endpoint.targetId),
total: json.data.pageInfo
? json.data.pageInfo.totalRecord
: json.data.length,
}));
console.log("REFERENCE", params);
const query = {
limit: 50,
sort: "ASC",
page: 1,
};
return httpClient(`${endpoint.url}?${stringify(query)}`).then(
({ json }) => ({
data: endpoint.getData(json.data, endpoint.target, endpoint.targetId),
total: json.data.pageInfo
? json.data.pageInfo.totalRecord
: json.data.length,
})
);
},

update: (resource, params) => {
Expand Down
8 changes: 6 additions & 2 deletions src/utils/data/admin-data.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export default (data) => {
if (data.records && Array.isArray(data.records)) {
return data.records.map((item) => ({ id: item.msAdminId, ...item }));
if (Array.isArray(data.records)) {
const profile = localStorage.getItem("profile");
const currentUserId = JSON.parse(profile).msAdminId;
return data.records
.filter((admin) => admin.msAdminId !== currentUserId)
.map((item) => ({ id: item.msAdminId, ...item }));
} else if (data.msAdminId) {
return { id: data.msAdminId, ...data };
}
Expand Down
8 changes: 1 addition & 7 deletions src/utils/data/application-data.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
const getApplicationsData = (data, target, id) => {
const getApplicationsData = (data) => {
let mappedData = data;

if (Array.isArray(data.records) && data.records[0].applicationId) {
mappedData = data.records.map(mapApplicationIdToId);

if (target && id) {
mappedData = mappedData.filter((item) => {
return item[target]._id === id;
});
}
}

return mappedData;
Expand Down
Loading