Skip to content

Commit

Permalink
Merge pull request #655 from CodeForAfrica/chore/add-collection-filter
Browse files Browse the repository at this point in the history
Add column for collection to tools, organisation and contributors.
  • Loading branch information
koechkevin authored Dec 5, 2023
2 parents a0f81d9 + 06da9f6 commit 128ae9c
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { ControlledSearchInput } from "@/charterafrica/components/SearchInput";

const EcosystemFilter = React.forwardRef(function EcosystemFilter(props, ref) {
const { onChange, searchPlaceholder, values, filterOptions = [] } = props;

// Search input field spans 3 columns, so divide 9 by the filter options
const spans = Math.floor(9 / filterOptions.length);
return (
<Box sx={{ pb: 3.75 }} bgcolor="common.white" ref={ref}>
<Grid
Expand All @@ -17,8 +18,9 @@ const EcosystemFilter = React.forwardRef(function EcosystemFilter(props, ref) {
justifyContent="space-between"
columnGap={1.25}
rowGap={1.25}
sx={{ flexWrap: { lg: "nowrap" } }}
>
<Grid item xs={12} lg={2}>
<Grid item xs={12} lg={3}>
<ControlledSearchInput
value={values.search}
onChange={(e) => onChange({ search: e.target.value })}
Expand All @@ -31,15 +33,15 @@ const EcosystemFilter = React.forwardRef(function EcosystemFilter(props, ref) {
/>
</Grid>
{filterOptions.map((option) => {
if (option.type === "select" && option.options.length) {
if (option?.type === "select" && option.options.length) {
const value = values[option.name] || "";
const optValue = option.options.find((opt) => value === opt.value);

const onItemChange = (_, v) => {
onChange({ [option.name]: v });
};
return (
<Grid key={option.name} item xs={12} lg={3}>
<Grid key={option.name} item xs={12} lg={spans}>
<ComboBox
size="small"
options={option.options}
Expand Down
3 changes: 2 additions & 1 deletion apps/charterafrica/src/components/Tool/Tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Tool = React.forwardRef(function Tool(props, ref) {
tools,
toolsTitle,
externalLink,
classification,
} = props;
return (
<Box bgcolor="common.white" ref={ref}>
Expand Down Expand Up @@ -145,7 +146,7 @@ const Tool = React.forwardRef(function Tool(props, ref) {
Collection
</RichTypography>
<RichTypography sx={{ mt: 1 }} variant="p3">
Tool
{classification}
</RichTypography>
</Box>
<Contributors
Expand Down
5 changes: 0 additions & 5 deletions apps/charterafrica/src/components/Tool/Tool.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,6 @@ exports[`<Tool /> renders unchanged 1`] = `
>
Collection
</div>
<div
class="MuiTypography-root MuiTypography-p3 css-1s3vopo-MuiTypography-root"
>
Tool
</div>
</div>
<div
class="MuiBox-root css-46b038"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import formatDateTime from "@/charterafrica/utils/formatDate";
import labelsPerLocale from "@/charterafrica/utils/translationConstants";

const queryBuilder = (query) => {
const { search, location } = query;
const { search, location, classification } = query;
const fields = ["description", "fullName", "location", "externalId"];
const where = {};
if (search) {
Expand All @@ -17,6 +17,9 @@ const queryBuilder = (query) => {
if (location) {
where.location = { equals: location };
}
if (classification) {
where.classification = { equals: classification };
}
return where;
};

Expand Down Expand Up @@ -128,6 +131,12 @@ async function processPageContributors(page, api, context) {
}
const { filters, title } = blocks[foundIndex];
const filterLabels = labelsPerLocale[locale];
const collections = [
...new Set(results.map((item) => item.classification)),
].map((value) => ({
value: value ?? null,
label: value ?? null,
}));
const filterOptions =
filters?.map((filter) => {
if (filter === "sort") {
Expand All @@ -154,6 +163,15 @@ async function processPageContributors(page, api, context) {
})),
};
}
if (filter === "classification") {
return {
type: "select",
name: "classification",
label: filterLabels.collection,
multiple: true,
options: collections,
};
}
return null;
}) ?? [];
const people = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import formatDateTime from "@/charterafrica/utils/formatDate";
import labelsPerLocale from "@/charterafrica/utils/translationConstants";

const queryBuilder = (query) => {
const { search, location } = query;
const { search, location, classification } = query;
const fields = ["description", "location", "name", "externalId", "slug"];
const where = {};
if (search) {
Expand All @@ -14,6 +14,9 @@ const queryBuilder = (query) => {
if (location) {
where.location = { equals: location };
}
if (classification) {
where.classification = { equals: classification };
}
return where;
};

Expand Down Expand Up @@ -117,6 +120,12 @@ async function processPageOrganisations(page, api, context) {
}
const { filters, title } = blocks[foundIndex];
const filterLabels = labelsPerLocale[locale];
const collections = [
...new Set(results.map((item) => item.classification)),
].map((value) => ({
value: value ?? null,
label: value ?? null,
}));
const filterOptions =
filters?.map((filter) => {
if (filter === "sort") {
Expand All @@ -143,6 +152,15 @@ async function processPageOrganisations(page, api, context) {
})),
};
}
if (filter === "classification") {
return {
type: "select",
name: "classification",
label: filterLabels.collection,
multiple: true,
options: collections,
};
}
return null;
}) ?? [];

Expand Down
24 changes: 22 additions & 2 deletions apps/charterafrica/src/lib/data/common/processPageTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import formatDateTime from "@/charterafrica/utils/formatDate";
import labelsPerLocale from "@/charterafrica/utils/translationConstants";

const queryBuilder = (query) => {
const { search, theme, homeCountry } = query;
const { search, theme, homeCountry, classification } = query;
const where = {};
if (search) {
const fields = [
Expand All @@ -19,6 +19,7 @@ const queryBuilder = (query) => {
"id",
"slug",
"homeCountry",
"classification",
];
where.or = fields.map((field) => ({ [field]: { like: search } }));
}
Expand All @@ -30,6 +31,9 @@ const queryBuilder = (query) => {
if (theme) {
where.theme = { equals: theme };
}
if (classification) {
where.classification = { equals: classification };
}
return where;
};

Expand Down Expand Up @@ -104,6 +108,7 @@ async function processPageSingleTool(page, api, context) {
commitText: filterLabels.lastCommit,
forksText: filterLabels.forks,
starsText: filterLabels.stars,
collection: tool.classification,
externalLink: {
href: tool.docLink ?? null,
},
Expand Down Expand Up @@ -159,6 +164,12 @@ async function processPageTools(page, api, context) {
value,
label: value,
}));
const collections = [...new Set(docs.map((item) => item.classification))].map(
(value) => ({
value: value ?? null,
label: value ?? null,
}),
);
const filterLabels = labelsPerLocale[locale];
const filterOptions = filters.map((filter) => {
if (filter === "sort") {
Expand Down Expand Up @@ -197,6 +208,15 @@ async function processPageTools(page, api, context) {
options: themes,
};
}
if (filter === "classification") {
return {
type: "select",
name: "classification",
label: filterLabels.collection,
multiple: true,
options: collections,
};
}
return null;
});
const tool = {
Expand All @@ -212,7 +232,7 @@ async function processPageTools(page, api, context) {

const { slugs, ...queryParams } = context.query;
let swrKey = `/api/v1/resources/ecosystem`;
const qs = queryString({ ...queryParams, collection: "tools" });
const qs = queryString({ ...queryParams });
if (qs) {
swrKey = `${swrKey}?${qs}`;
}
Expand Down
3 changes: 3 additions & 0 deletions apps/charterafrica/src/lib/ecosystem/airtable/processData.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export function processTool(item, config, { partnersData }) {
link: getValue(data, toolTableColumns.url),
operatingCountries,
contributors: getValue(data, toolTableColumns.contributors),
classification: getValue(data, toolTableColumns.classification),
source,
supporters,
partners,
Expand Down Expand Up @@ -168,6 +169,7 @@ export function processContributor(item, config) {
);
return {
airtableId: data.id,
classification: getValue(data, contributorTableColumns.classification),
externalId,
repoLink,
socialMedia,
Expand Down Expand Up @@ -231,6 +233,7 @@ export function processOrganisation(item, config, { partnersData }) {
externalId,
type: getValue(data, organisationTableColumns.type)?.replace(/&/g, "and"),
repoLink: getValue(data, organisationTableColumns.source.url),
classification: getValue(data, organisationTableColumns.classification),
supporters,
partners,
socialMedia,
Expand Down
8 changes: 8 additions & 0 deletions apps/charterafrica/src/payload/blocks/Contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ const Contributors = {
fr: "Emplacement",
},
},
{
value: "classification",
label: {
en: "Collection",
fr: "Collection",
pt: "Coleção",
},
},
],
},
{
Expand Down
8 changes: 8 additions & 0 deletions apps/charterafrica/src/payload/blocks/Organisations.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ const Contributors = {
fr: "Emplacement",
},
},
{
value: "classification",
label: {
en: "Collection",
fr: "Collection",
pt: "Coleção",
},
},
],
},
{
Expand Down
8 changes: 8 additions & 0 deletions apps/charterafrica/src/payload/blocks/Tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ const Tools = {
fr: "Emplacement",
},
},
{
value: "classification",
label: {
en: "Collection",
fr: "Collection",
pt: "Coleção",
},
},
],
},
],
Expand Down
13 changes: 13 additions & 0 deletions apps/charterafrica/src/payload/collections/Contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ const Contributors = {
readOnly: true,
},
},
{
name: "classification",
type: "text",
admin: {
readOnly: true,
},
localized: true,
label: {
en: "Collection",
fr: "Collection",
pt: "Coleção",
},
},
{
name: "description",
type: "textarea",
Expand Down
9 changes: 9 additions & 0 deletions apps/charterafrica/src/payload/collections/Organisations.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ const Organisations = {
readOnly: true,
},
},
{
name: "classification",
type: "text",
admin: {
readOnly: true,
},
localized: true,
label: { en: "Collection", fr: "Collection", pt: "Collection" },
},
// Can either be Non-Profit, For- Profit, Donor/ Investor, Charter Grantee
{
name: "type",
Expand Down
13 changes: 13 additions & 0 deletions apps/charterafrica/src/payload/collections/Tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ const Tools = {
localized: true,
label: { en: "Theme", fr: "Thème", pt: "Tema" },
},
{
name: "classification",
type: "text",
admin: {
readOnly: true,
},
localized: true,
label: {
en: "Collection",
fr: "Collection",
pt: "Coleção",
},
},
{
name: "techSkills",
type: "array",
Expand Down
Loading

0 comments on commit 128ae9c

Please sign in to comment.