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

task/WP-273: Category icon #874

Merged
merged 13 commits into from
Oct 25, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const AppBrowser = () => {
}
>
<span className="nav-content">
<AppIcon appId={app.appId} />
<AppIcon appId={app.appId} category={category} />
<span className="nav-text">{app.label || app.appId}</span>
</span>
</NavLink>
Expand Down
15 changes: 14 additions & 1 deletion client/src/components/Applications/AppForm/AppForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ const AdjustValuesWhenQueueChanges = ({ app }) => {
};

const AppInfo = ({ app }) => {
const categoryDict = useSelector((state) => state.apps.categoryDict);
const getAppCategory = (appId) => {
let category = null;
Object.entries(categoryDict).forEach(([cat, apps]) => {
if (apps.some((app) => app.appId === appId)) {
category = cat;
}
});
return category;
};
tjgrafft marked this conversation as resolved.
Show resolved Hide resolved

const appCategory = getAppCategory(app.definition.id);

return (
<div className="appInfo-wrapper">
<h5 className="appInfo-title">{app.definition.label}</h5>
Expand All @@ -163,7 +176,7 @@ const AppInfo = ({ app }) => {
target="_blank"
rel="noreferrer noopener"
>
<AppIcon appId={app.definition.id} />{' '}
<AppIcon appId={app.definition.id} category={appCategory} />{' '}
<span>{app.definition.notes.label} Documentation</span>
</a>
) : null}
Expand Down
13 changes: 11 additions & 2 deletions client/src/components/_common/AppIcon/AppIcon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import PropTypes from 'prop-types';
import Icon from '_common/Icon';
import './AppIcon.scss';

const AppIcon = ({ appId }) => {
const AppIcon = ({ appId, category }) => {
const appIcons = useSelector((state) => state.apps.appIcons);
const findAppIcon = (id) => {
let appIcon = 'applications';
if (!category) {
console.error('Category is undefined for appId:', id);
return 'applications';
wesleyboar marked this conversation as resolved.
Show resolved Hide resolved
rstijerina marked this conversation as resolved.
Show resolved Hide resolved
}
let appIcon = category.replace(' ', '-').toLowerCase();
Object.keys(appIcons).forEach((appName) => {
if (id.includes(appName)) {
appIcon = appIcons[appName].toLowerCase();
Expand All @@ -27,6 +31,11 @@ const AppIcon = ({ appId }) => {
};
AppIcon.propTypes = {
appId: PropTypes.string.isRequired,
category: PropTypes.string,
};

AppIcon.defaultProps = {
category: 'applications',
};

export default AppIcon;
16 changes: 10 additions & 6 deletions client/src/components/_common/AppIcon/AppIcon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,30 @@ const store = mockStore({
jupyter: 'jupyter',
},
},
categories: {
'test-apps': ['vasp'],
'data-processing': ['jupyter'],
},
});

expect.extend({ toHaveAttribute });

function renderAppIcon(appId) {
function renderAppIcon(appId, category = 'default') {
return render(
<Provider store={store}>
<AppIcon appId={appId} />
<AppIcon appId={appId} category={category} />
</Provider>
);
}

describe('AppIcon', () => {
it('should render icons for known app IDs', () => {
const { getByRole } = renderAppIcon('jupyter');
const { getByRole } = renderAppIcon('jupyter', 'data-processing');
expect(getByRole('img')).toHaveAttribute('class', 'icon icon-jupyter');
});
it('should show generic icons for apps with no appIcon', () => {
const { getByRole } = renderAppIcon('vasp');
expect(getByRole('img')).toHaveAttribute('class', 'icon icon-applications');
it('should show category icons for apps with no appIcon', () => {
const { getByRole } = renderAppIcon('vasp', 'test-apps');
expect(getByRole('img')).toHaveAttribute('class', 'icon icon-test-apps');
});
it('should render icons for prtl.clone apps', () => {
const { getByRole } = renderAppIcon(
Expand Down
8 changes: 8 additions & 0 deletions client/src/styles/trumps/icon.fonts.css

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