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

Add specification filter #509

Merged
merged 1 commit into from
Feb 21, 2024
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
12 changes: 11 additions & 1 deletion web/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,20 @@ export const FILTERS: FilterSection[] = [
},
],
},
{
value: FilterCategory.Extra,
title: 'Extra',
options: [
{
value: 'specification',
name: 'Specification',
},
],
},
];

export const FILTER_CATEGORIES_PER_TITLE: FilterCategoriesPerTitle = {
[FilterTitle.Project]: [FilterCategory.Maturity, FilterCategory.TAG, FilterCategory.License],
[FilterTitle.Project]: [FilterCategory.Maturity, FilterCategory.TAG, FilterCategory.License, FilterCategory.Extra],
[FilterTitle.Organization]: [
FilterCategory.Organization,
FilterCategory.OrgType,
Expand Down
33 changes: 30 additions & 3 deletions web/src/layout/common/ActiveFiltersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ const ActiveFiltersList = (props: Props) => {
const activeFiltersPerCategory = () => activeFilters()[f as FilterCategory];
if (isUndefined(activeFiltersPerCategory()) || isEmpty(activeFiltersPerCategory())) return null;

const allMatutirySelected = () =>
const allMaturitySelected = () =>
!isUndefined(props.maturityOptions) &&
f === FilterCategory.Maturity &&
props.maturityOptions.every((element) => activeFiltersPerCategory()!.includes(element));
const foundationLabel = getFoundationNameLabel();

return (
<Switch>
<Match when={allMatutirySelected()}>
<Match when={allMaturitySelected()}>
<span
role="listitem"
class={`badge badge-sm border rounded-0 me-3 my-1 d-flex flex-row align-items-center ${styles.filterBadge}`}
Expand All @@ -88,7 +88,34 @@ const ActiveFiltersList = (props: Props) => {
</span>
</Match>

<Match when={!allMatutirySelected()}>
<Match when={f === FilterCategory.Extra}>
<For each={activeFiltersPerCategory()}>
{(c: string) => {
return (
<span
role="listitem"
class={`badge badge-sm border rounded-0 me-3 my-1 d-flex flex-row align-items-center ${styles.filterBadge}`}
>
<div class="d-flex flex-row align-items-baseline">
<div>
<span class="text-uppercase">{c}</span>
</div>
<button
class="btn btn-link btn-sm text-reset lh-1 p-0 ps-2"
onClick={() => props.removeFilter(f as FilterCategory, c)}
aria-label={`Remove ${c} filter`}
title={`Remove ${c} filter`}
>
<SVGIcon kind={SVGIconKind.ClearCircle} />
</button>
</div>
</span>
);
}}
</For>
</Match>

<Match when={!allMaturitySelected()}>
<For each={activeFiltersPerCategory()}>
{(c: string) => {
return (
Expand Down
9 changes: 9 additions & 0 deletions web/src/layout/explore/filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,15 @@ const Filters = (props: Props) => {
updateActiveFilters={updateActiveFilters}
resetFilter={resetFilter}
/>

<Section
title="Extra"
section={getSection(FilterCategory.Extra)}
activeFilters={{ ...tmpActiveFilters() }[FilterCategory.Extra]}
updateActiveFilters={updateActiveFilters}
resetFilter={resetFilter}
sectionClass={styles.section}
/>
</div>
</Show>

Expand Down
18 changes: 17 additions & 1 deletion web/src/layout/explore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type LoadedContent = {

const TITLE_GAP = 40;
const CONTROLS_WIDTH = 102 + 49 + 160 + 101 + 24; // Filters + Group legend + View Mode + Zoom + Right margin
const EXTRA_FILTERS = ['specification'];

const Explore = (props: Props) => {
const navigate = useNavigate();
Expand Down Expand Up @@ -124,6 +125,14 @@ const Explore = (props: Props) => {
currentFilters[f] = [value];
}
}
} else {
if (EXTRA_FILTERS.includes(key)) {
if (currentFilters[f]) {
currentFilters[FilterCategory.Extra] = [...currentFilters[FilterCategory.Extra]!, key];
} else {
currentFilters[FilterCategory.Extra] = [key];
}
}
}
}
setVisibleItems(filterData(landscapeData() || props.initialData.items, currentFilters));
Expand Down Expand Up @@ -205,6 +214,9 @@ const Explore = (props: Props) => {
Object.values(FilterCategory).forEach((f: string) => {
params.delete(f);
});
EXTRA_FILTERS.forEach((f: string) => {
params.delete(f);
});

if (params.toString() === '') {
params.set(GROUP_PARAM, selectedGroup()!);
Expand All @@ -213,7 +225,11 @@ const Explore = (props: Props) => {

const filtersParams = getFiltersQuery(filters);
for (const [key, val] of filtersParams.entries()) {
params.append(key, val);
if (key === FilterCategory.Extra) {
params.append(val, 'true');
} else {
params.append(key, val);
}
}

const query = params.toString();
Expand Down
1 change: 1 addition & 0 deletions web/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export enum FilterCategory {
TAG = 'tag',
Membership = 'membership',
InvestmentType = 'investment-type',
Extra = 'extra',
}

export interface Stats {
Expand Down
10 changes: 10 additions & 0 deletions web/src/utils/filterData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import getFoundationNameLabel from './getFoundationNameLabel';
const filterData = (items: Item[], activeFilters: ActiveFilters): Item[] => {
if (Object.keys(activeFilters).length > 0) {
const filteredItems: Item[] = items.filter((item: Item) => {
// Filter Extra
if (activeFilters[FilterCategory.Extra]) {
if (
activeFilters[FilterCategory.Extra].includes('specification') &&
(isUndefined(item.specification) || !item.specification)
) {
return false;
}
}

// Filter Organization
if (activeFilters[FilterCategory.Organization]) {
if (isUndefined(item.crunchbase_data) || isUndefined(item.crunchbase_data.name)) {
Expand Down
18 changes: 18 additions & 0 deletions web/src/utils/prepareFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const prepareFilters = (items: Item[]): FilterSection[] => {
const licenses: string[] = [];
const countries: string[] = [];
const companyTypes: string[] = [];
const extraTypes: string[] = [];
let categories: string[] = [];

items.forEach((i: Item) => {
Expand All @@ -61,6 +62,10 @@ const prepareFilters = (items: Item[]): FilterSection[] => {
tags.push(i.tag);
}

if (i.specification) {
extraTypes.push('specification');
}

if (i.crunchbase_data) {
if (i.crunchbase_data.name) {
organizations.push(i.crunchbase_data.name);
Expand Down Expand Up @@ -163,6 +168,19 @@ const prepareFilters = (items: Item[]): FilterSection[] => {
})),
});
}

if (extraTypes.length > 0) {
filters.push({
value: FilterCategory.Extra,
title: 'Extra',
options: [
{
value: 'specification',
name: 'Specification',
},
],
});
}
}

return filters;
Expand Down
Loading