Skip to content

Commit

Permalink
Add locations key to resources json
Browse files Browse the repository at this point in the history
  • Loading branch information
julianguyen committed May 9, 2022
1 parent 6248620 commit 347901b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 6 additions & 1 deletion app/controllers/concerns/pages_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ def load_dashboard_data
def modify_resources
resources = JSON.parse(File.read('doc/pages/resources.json'))
resources.each do |item|
item['tags'].map! { |tag| t("pages.resources.tags.#{tag}") }
pr = 'pages.resources'
item['tags'].map! { |tag| t("#{pr}.tags.#{tag}") }
item['languages'].map! { |language| t("languages.#{language}") }
item['locations']&.map! { |location| t("#{pr}.locations.#{location}") }
item['tags'].sort_by!(&:downcase)
item['languages'].sort_by!(&:downcase)
item['locations']&.sort_by! { |location| location.downcase }
end
resources
end
Expand Down
19 changes: 16 additions & 3 deletions client/app/widgets/Resources/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ResourceProp = {
link: string,
tags: string[],
languages: string[],
locations?: string[],
};

export type Props = {
Expand Down Expand Up @@ -100,7 +101,11 @@ const createCheckboxes = (resources: ResourceProp[], keywords: string[]) => {
const tagsList = [
...new Set(
resources
.map((resource: ResourceProp) => resource.tags.concat(resource.languages))
.map((resource: ResourceProp) => [
...resource.tags,
...resource.languages,
...(resource.locations || []),
])
.reduce((acc, val) => acc.concat(val), []),
),
];
Expand All @@ -127,7 +132,11 @@ const filterList = (
return resources.filter((resource: ResourceProp) => {
const tagCheck = selectedCheckboxes.map((checkbox: Checkbox) =>
// eslint-disable-next-line implicit-arrow-linebreak
resource.tags.concat(resource.languages).includes(checkbox.id));
[
...resource.tags,
...resource.languages,
...(resource.locations || []),
].includes(checkbox.id));
return selectedCheckboxes.length > 0 ? tagCheck.includes(true) : true;
});
};
Expand Down Expand Up @@ -213,7 +222,11 @@ export const Resources = ({
>
<Resource
tagged
tags={resource.languages.concat(resource.tags)}
tags={[
...resource.tags,
...resource.languages,
...(resource.locations || []),
]}
title={resource.name}
link={resource.link}
updateTagFilter={(tagLabel) => {
Expand Down

0 comments on commit 347901b

Please sign in to comment.