Skip to content

Commit 0b89f91

Browse files
authored
Fix Viewer tags issue (#103) (#104)
* Add functions for devfile tags * Update detailed view and grid * Create new color in tailwind * Apply format --------- Signed-off-by: thepetk <[email protected]>
1 parent d164ea1 commit 0b89f91

File tree

5 files changed

+137
-10
lines changed

5 files changed

+137
-10
lines changed

apps/registry-viewer/tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ module.exports = {
4545
extend: {
4646
colors: {
4747
devfile: 'rgb(47, 154, 242, <alpha-value>)',
48+
deprecated: 'rgb(243, 46, 66, <alpha-value>)',
4849
},
4950
fontFamily: {
5051
sans: ['Inter', ...defaultTheme.fontFamily.sans],

libs/core/src/components/devfile-datalist/devfile-datalist.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import { useMemo } from 'react';
2121
import { StringParam, useQueryParam, withDefault } from 'use-query-params';
2222
import { compareSemanticVersions, type Devfile } from '../../functions';
2323
import type { DevfileSpec } from '../../types';
24+
import {
25+
getDevfileTags,
26+
getDevfileTagClasses,
27+
} from '../../functions/get-devfile-tags/get-devfile-tags';
2428

2529
export interface DevfileDatalistProps {
2630
devfile: Devfile;
@@ -45,6 +49,8 @@ export function DevfileDatalist(props: DevfileDatalistProps): JSX.Element {
4549
[devfile.versions, devfileVersion],
4650
);
4751

52+
const devfileTags = getDevfileTags(versionDevfile, devfile);
53+
4854
return (
4955
<div className={className}>
5056
<div className="border-b border-slate-200 pb-2 text-lg font-medium leading-8 text-slate-700 dark:border-slate-700 dark:text-sky-100">
@@ -118,17 +124,14 @@ export function DevfileDatalist(props: DevfileDatalistProps): JSX.Element {
118124
{devfile.language}
119125
</dd>
120126
</div>
121-
{devfile.tags && (
127+
{devfileTags && (
122128
<div className="grid grid-cols-2 py-2.5 lg:block">
123129
<dt className="text-base font-medium text-slate-700 dark:text-sky-100">Tags</dt>
124130
<dd className="mt-1 text-sm text-slate-500 dark:text-slate-400">
125131
<ul className="flex flex-wrap gap-2">
126-
{devfile.tags.map((tag) => (
132+
{devfileTags.map((tag) => (
127133
<li key={tag}>
128-
<Link
129-
href={`/?tags=${tag}`}
130-
className="bg-devfile/5 hover:bg-devfile/10 active:bg-devfile/20 border-devfile/50 text-devfile inline-flex items-center rounded border px-2.5 py-0.5 text-xs font-medium"
131-
>
134+
<Link href={`/?tags=${tag}`} className={getDevfileTagClasses(tag)}>
132135
{tag}
133136
</Link>
134137
</li>

libs/core/src/components/devfile-grid/devfile-grid.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import Link from 'next/link';
1919
import slugify from '@sindresorhus/slugify';
2020
import { Devfile } from '../../functions';
2121

22+
import { getDevfileTagClasses } from '../../functions/get-devfile-tags/get-devfile-tags';
23+
2224
export interface DevfileGridProps {
2325
devfiles: Devfile[];
2426
}
@@ -74,10 +76,7 @@ export function DevfileGrid(props: DevfileGridProps): JSX.Element {
7476
{devfile.tags && (
7577
<div className="mt-2 flex flex-wrap gap-2 md:mt-4">
7678
{devfile.tags.slice(0, 4).map((tag) => (
77-
<span
78-
key={tag}
79-
className="bg-devfile/5 border-devfile/50 text-devfile inline-flex items-center rounded border px-2.5 py-0.5 text-xs font-medium md:text-sm"
80-
>
79+
<span key={tag} className={getDevfileTagClasses(tag)}>
8180
{tag}
8281
</span>
8382
))}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright Red Hat
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { VersionDevfile, Devfile, Registry } from '../fetch-devfiles/fetch-devfiles';
18+
import { deprecatedTag, getDevfileTags, getDevfileTagClasses } from './get-devfile-tags';
19+
20+
let undefinedVersionDevfile: undefined;
21+
22+
let versionDevfile: VersionDevfile;
23+
24+
let devfile: Devfile;
25+
26+
let registry: Registry;
27+
28+
describe('getDevfileTags', () => {
29+
it('should execute successfully', () => {
30+
registry = {
31+
name: '',
32+
url: '',
33+
fqdn: '',
34+
};
35+
versionDevfile = {
36+
version: '2.2.1',
37+
schemaVersion: '2.1.0',
38+
tags: ['one', 'two'],
39+
default: true,
40+
description: 'some description',
41+
icon: '',
42+
starterProjects: [],
43+
};
44+
devfile = {
45+
_registry: registry,
46+
name: 'some devfile',
47+
displayName: 'display name',
48+
description: 'some description',
49+
type: 'stack',
50+
tags: ['three', 'four'],
51+
icon: '',
52+
projectType: 'python',
53+
language: 'python',
54+
versions: [],
55+
provider: 'provider',
56+
architectures: [],
57+
git: {
58+
remotes: {},
59+
},
60+
};
61+
expect(getDevfileTags(undefinedVersionDevfile, devfile)).toEqual(devfile.tags);
62+
expect(getDevfileTags(versionDevfile, devfile)).toEqual(versionDevfile.tags);
63+
});
64+
});
65+
66+
describe('getDevfileTags', () => {
67+
it('should execute successfully', () => {
68+
const devfileClassName =
69+
'bg-devfile/5 hover:bg-devfile/10 active:bg-devfile/20 border-devfile/50 text-devfile inline-flex items-center rounded border px-2.5 py-0.5 text-xs font-medium';
70+
const deprecatedClassName =
71+
'bg-deprecated/5 hover:bg-deprecated/10 active:bg-deprecated/20 border-deprecated/50 text-deprecated inline-flex items-center rounded border px-2.5 py-0.5 text-xs font-medium';
72+
expect(getDevfileTagClasses(deprecatedTag)).toEqual(deprecatedClassName);
73+
expect(getDevfileTagClasses('tag')).toEqual(devfileClassName);
74+
});
75+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright Red Hat
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { Devfile, VersionDevfile } from '../fetch-devfiles/fetch-devfiles';
18+
19+
export const deprecatedTag = 'Deprecated';
20+
/**
21+
* Checks if a versionDevfile exists and returns its tags. If
22+
* it doesn't exists returns the devfile tags
23+
*
24+
* @returns a list of tags
25+
*/
26+
export function getDevfileTags(
27+
versionDevfile: VersionDevfile | undefined,
28+
devfile: Devfile,
29+
): string[] {
30+
if (versionDevfile !== undefined) {
31+
return versionDevfile.tags;
32+
}
33+
return devfile.tags;
34+
}
35+
36+
/**
37+
* Checks if the given tag is equal to depracatedTag and returns the necessary css classes
38+
*
39+
* @returns the class names according to the given tag
40+
*/
41+
export function getDevfileTagClasses(tag: string): string {
42+
let colorTag = 'devfile';
43+
if (tag === deprecatedTag) {
44+
colorTag = deprecatedTag.toLowerCase();
45+
}
46+
return `bg-${colorTag}/5 hover:bg-${colorTag}/10 active:bg-${colorTag}/20 border-${colorTag}/50 text-${colorTag} inline-flex items-center rounded border px-2.5 py-0.5 text-xs font-medium`;
47+
}
48+
49+
export default getDevfileTags;

0 commit comments

Comments
 (0)