Skip to content

Enhance Institution Type Display with Standardized Components and Sty… #36

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 1 commit into
base: main
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
133 changes: 94 additions & 39 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@types/react-dom": "^19.0.4",
"@typescript-eslint/eslint-plugin": "^8.29.1",
"@typescript-eslint/parser": "^8.29.1",
"@vitejs/plugin-react": "^4.3.4",
"@vitejs/plugin-react": "^4.4.1",
"eslint": "^9.24.0",
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-prettier": "^5.2.6",
Expand All @@ -32,6 +32,6 @@
"prettier": "^3.5.3",
"typescript": "~5.7.2",
"typescript-eslint": "^8.24.1",
"vite": "^6.2.0"
"vite": "^6.3.5"
}
}
56 changes: 56 additions & 0 deletions frontend/src/components/InstitutionType.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import {
getInstitutionTypeDisplayName,
getInstitutionTypeIcon,
INSTITUTION_TYPES
} from '../constants/institutionTypes';

interface InstitutionTypeProps {
type: string | null | undefined;
showIcon?: boolean;
className?: string;
showTooltip?: boolean;
}

/**
* A component for displaying institution types with consistent formatting and styling
* based on the OpenAlex institution type vocabulary.
*
* @param props.type - The institution type (from OpenAlex)
* @param props.showIcon - Whether to show an icon (default: true)
* @param props.className - Additional CSS classes to apply
* @param props.showTooltip - Whether to show a tooltip with the description (default: true)
*/
const InstitutionType: React.FC<InstitutionTypeProps> = ({
type,
showIcon = true,
className = '',
showTooltip = true
}) => {
if (!type) return <span className="text-muted">N/A</span>;

// Get display name and icon from constants
const displayName = getInstitutionTypeDisplayName(type);
const icon = getInstitutionTypeIcon(type);

// Apply specific styling based on institution type
const typeKey = type.toLowerCase();
const baseClassName = `institution-type institution-type-${typeKey in INSTITUTION_TYPES ? typeKey : 'unknown'}`;

// Get description for tooltip
const description = typeKey in INSTITUTION_TYPES ?
INSTITUTION_TYPES[typeKey].description :
'Unknown institution type';

return (
<span
className={`${baseClassName} ${className}`}
title={showTooltip ? description : undefined}
>
{showIcon && <span className="institution-type-icon">{icon}</span>}
{displayName}
</span>
);
};

export default InstitutionType;
41 changes: 41 additions & 0 deletions frontend/src/components/InstitutionTypeFilter.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.institution-type-filter {
margin: 16px 0;
}

.institution-type-filter h4 {
margin-bottom: 8px;
}

.institution-type-list {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 16px;
}

.institution-type-filter-item {
cursor: pointer;
padding: 6px 12px;
border-radius: 4px;
background-color: #f5f5f5;
transition: all 0.2s ease;
display: flex;
align-items: center;
user-select: none;
}

.institution-type-filter-item:hover {
background-color: #e0e0e0;
}

.institution-type-filter-item.selected {
background-color: #e3f2fd;
border: 1px solid #2196f3;
}

/* Override the default institution type styling within filter items */
.institution-type-filter-item .institution-type {
background-color: transparent !important;
padding: 0 !important;
margin: 0 !important;
}
Loading