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

Fix ecosystem filters. #618

Merged
merged 2 commits into from
Oct 3, 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
2 changes: 1 addition & 1 deletion apps/charterafrica/contrib/dokku/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM codeforafrica/charterafrica-ui:0.1.8
FROM codeforafrica/charterafrica-ui:0.1.9
2 changes: 1 addition & 1 deletion apps/charterafrica/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "charterafrica",
"version": "0.1.8",
"version": "0.1.9",
"private": true,
"author": "Code for Africa <[email protected]>",
"description": "This is the official code for https://charter.africa site",
Expand Down
63 changes: 35 additions & 28 deletions apps/charterafrica/src/components/EcosystemList/EcosystemList.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ const EcosystemList = React.forwardRef(function EcosystemList(props, ref) {
if (loading && listRef.current) {
listRef.current.scrollIntoView({ behavior: "smooth" });
}
if (!results.length && !values.search) {
return null;
}

return (
<Box ref={ref} sx={{ backgroundColor: "common.white" }}>
<Section
Expand All @@ -109,32 +107,41 @@ const EcosystemList = React.forwardRef(function EcosystemList(props, ref) {
filterOptions={filterOptions}
onQuerySearch={onQuerySearch}
/>
<RichTypography
textAlign={{ xs: "center", sm: "left" }}
color="neutral.dark"
variant="h2SemiBold"
sx={{ mt: 6.25 }}
>
{title}
</RichTypography>
{loading ? <LinearProgress color="secondary" /> : null}
<Grid sx={{ py: 6.25 }} container columnSpacing={2.5} rowSpacing={5}>
{results.map((item) => (
<Grid key={item.id} item xs={12} sm={6} md={4} lg={3}>
<Component key={item.id} {...item} />
{results.length ? (
<>
<RichTypography
textAlign={{ xs: "center", sm: "left" }}
color="neutral.dark"
variant="h2SemiBold"
sx={{ mt: 6.25 }}
>
{title}
</RichTypography>
{loading ? <LinearProgress color="secondary" /> : null}
<Grid
sx={{ py: 6.25 }}
container
columnSpacing={2.5}
rowSpacing={5}
>
{results.map((item) => (
<Grid key={item.id} item xs={12} sm={6} md={4} lg={3}>
<Component key={item.id} {...item} />
</Grid>
))}
</Grid>
))}
</Grid>
<NextPrevPagination
count={totalPages}
onChange={(_, p) => onPageChange(p)}
page={page}
sx={{
backgroundColor: "common.white",
mt: 5,
pb: 8,
}}
/>
<NextPrevPagination
count={totalPages}
onChange={(_, p) => onPageChange(p)}
page={page}
sx={{
backgroundColor: "common.white",
mt: 5,
pb: 8,
}}
/>
</>
) : null}
</Box>
</Section>
</Box>
Expand Down
27 changes: 14 additions & 13 deletions apps/charterafrica/src/lib/data/common/processPageContributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,33 @@ import queryString from "@/charterafrica/utils/ecosystem/queryString";
import formatDateTime from "@/charterafrica/utils/formatDate";
import labelsPerLocale from "@/charterafrica/utils/translationConstants";

const orQueryBuilder = (fields, search) => {
return fields.map((field) => ({ [field]: { like: search } }));
const queryBuilder = (query) => {
const { search, location } = query;
const fields = ["description", "fullName", "location", "externalId"];
const where = {};
if (search) {
where.or = fields.map((field) => ({ [field]: { like: search } }));
}
if (location) {
where.location = { equals: location };
}
return where;
};

export async function getContributors(page, api, context) {
const {
locale,
query: { page: pageNumber = 1, limit = 12, search, sort = "fullName" } = {},
query: { page: pageNumber = 1, limit = 12, sort = "fullName" } = {},
} = context;

const fields = ["description", "fullName", "location", "externalId"];
const toolQueries = orQueryBuilder(fields, search);
const query = {
or: toolQueries,
};

const where = queryBuilder(context.query);
const { docs, ...pagination } = await api.getCollection(
CONTRIBUTORS_COLLECTION,
{
locale,
page: parseInt(pageNumber, 10) || 1,
limit,
sort,
where: {
...query,
},
where,
},
);
const results = docs.map((person) => {
Expand Down
25 changes: 14 additions & 11 deletions apps/charterafrica/src/lib/data/common/processPageOrganisations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ import queryString from "@/charterafrica/utils/ecosystem/queryString";
import formatDateTime from "@/charterafrica/utils/formatDate";
import labelsPerLocale from "@/charterafrica/utils/translationConstants";

const orQueryBuilder = (fields, search) => {
return fields.map((field) => ({ [field]: { like: search } }));
const queryBuilder = (query) => {
const { search, location } = query;
const fields = ["description", "location", "name", "externalId", "slug"];
const where = {};
if (search) {
where.or = fields.map((field) => ({ [field]: { like: search } }));
}
if (location) {
where.location = { equals: location };
}
return where;
};

async function processPageSingleOrganisation(page, api, context) {
Expand Down Expand Up @@ -65,13 +74,9 @@ async function processPageSingleOrganisation(page, api, context) {
export async function getOrganisations(page, api, context) {
const {
locale,
query: { page: pageNumber = 1, limit = 12, search, sort = "name" } = {},
query: { page: pageNumber = 1, limit = 12, sort = "name" } = {},
} = context;
const fields = ["description", "location", "name", "externalId", "slug"];
const toolQueries = orQueryBuilder(fields, search);
const query = {
or: toolQueries,
};
const where = queryBuilder(context.query);
const filterLabels = labelsPerLocale[locale];
const { docs, ...pagination } = await api.getCollection(
ORGANIZATION_COLLECTION,
Expand All @@ -80,9 +85,7 @@ export async function getOrganisations(page, api, context) {
page: pageNumber,
limit,
sort,
where: {
...query,
},
where,
},
);
const results = docs.map((tool) => {
Expand Down
44 changes: 27 additions & 17 deletions apps/charterafrica/src/lib/data/common/processPageTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,30 @@ import queryString from "@/charterafrica/utils/ecosystem/queryString";
import formatDateTime from "@/charterafrica/utils/formatDate";
import labelsPerLocale from "@/charterafrica/utils/translationConstants";

const orQueryBuilder = (fields, search) => {
return fields.map((field) => ({ [field]: { like: search } }));
const queryBuilder = (query) => {
const { search, theme, homeCountry } = query;
const where = {};
if (search) {
const fields = [
"description",
"theme",
"operatingCountries",
"name",
"id",
"slug",
"homeCountry",
];
where.or = fields.map((field) => ({ [field]: { like: search } }));
}
if (homeCountry) {
where.homeCountry = {
equals: homeCountry,
};
}
if (theme) {
where.theme = { equals: theme };
}
return where;
};

const getRepoLink = (tool) => {
Expand Down Expand Up @@ -99,27 +121,15 @@ async function processPageSingleTool(page, api, context) {
export async function getTools(page, api, context) {
const {
locale,
query: { page: pageNumber = 1, limit = 12, search, sort = "name" } = {},
query: { page: pageNumber = 1, limit = 12, sort = "name" } = {},
} = context;
const fields = [
"description",
"theme",
"operatingCountries",
"name",
"id",
"slug",
];
const toolQueries = orQueryBuilder(fields, search);
const query = {
or: toolQueries,
};

const where = queryBuilder(context.query);
const { docs, ...pagination } = await api.getCollection(TOOL_COLLECTION, {
locale,
page: pageNumber,
limit,
sort,
where: query,
where,
});

const results = docs.map((tool) => {
Expand Down
Loading