Skip to content

Commit

Permalink
fix: editor selector cards
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <oorel@redhat.com>
  • Loading branch information
olexii4 committed Nov 1, 2024
1 parent bd75e93 commit c496147
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 7 deletions.
1 change: 1 addition & 0 deletions .deps/EXCLUDED/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This file lists dependencies that do not need CQs or auto-detection does not wor
| `blueimp-md5@2.19.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/blueimp-md5/2.19.0) |
| `codemirror@5.65.16` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/codemirror/5.65.16) |
| `cookie-signature@1.2.1` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/cookie-signature/1.2.1) |
| `ecc-jsbn@0.1.2` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/ecc-jsbn/0.1.2) |
| `fast-uri@2.4.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/fast-uri/2.4.0) |
| `fastify@4.28.1` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/fastify/4.28.1) |
| `jsep@1.3.9` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/jsep/1.3.9) |
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard-frontend/jest.setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ jest.mock('@/components/CheTooltip', () => {

jest.mock('react-markdown', () => {
return jest.fn(props => {
return React.createElement('div', null, props.children, props.content);
return React.createElement('a', null, props.children, props.content);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ exports[`Editor Selector Entry snapshot 1`] = `
</div>
</div>
<div
className="pf-c-card__body"
className="pf-c-card__body cardBody"
>
<span
className=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@
.activeCard {
color: #000;
}

.cardBody {
min-height: 65px;
padding-bottom: 35px;
}

.provider {
position: absolute;
bottom: var(--pf-c-card--child--PaddingBottom);
font-size: 75%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export type State = {
const allowedTags = ['Tech Preview', 'Deprecated'];

export class EditorSelectorEntry extends React.PureComponent<Props, State> {
private timerId: number | undefined;

constructor(props: Props) {
super(props);

Expand All @@ -59,7 +61,38 @@ export class EditorSelectorEntry extends React.PureComponent<Props, State> {
};
}

// TODO temporary solution for making links open in a new browser tab (should be fixed with https://github.com/eclipse-che/che/issues/23219)

Check warning on line 64 in packages/dashboard-frontend/src/components/EditorSelector/Gallery/Entry/index.tsx

View workflow job for this annotation

GitHub Actions / build-and-test (18.x)

Unexpected 'todo' comment: 'TODO temporary solution for making links...'

Check warning on line 64 in packages/dashboard-frontend/src/components/EditorSelector/Gallery/Entry/index.tsx

View workflow job for this annotation

GitHub Actions / build-and-test (20.x)

Unexpected 'todo' comment: 'TODO temporary solution for making links...'

Check warning on line 64 in packages/dashboard-frontend/src/components/EditorSelector/Gallery/Entry/index.tsx

View workflow job for this annotation

GitHub Actions / build-and-test-yarn-v1 (18.x)

Unexpected 'todo' comment: 'TODO temporary solution for making links...'

Check warning on line 64 in packages/dashboard-frontend/src/components/EditorSelector/Gallery/Entry/index.tsx

View workflow job for this annotation

GitHub Actions / build-and-test-yarn-v1 (20.x)

Unexpected 'todo' comment: 'TODO temporary solution for making links...'
private setAttribute(
widgetId: string,
querySelector: string = 'a',
attributeName: string = 'target',
attributeValue: string = '_blank',
): void {
clearTimeout(this.timerId);
this.timerId = window.setTimeout(() => {
const widget = document.getElementById(widgetId);
if (widget) {
widget.querySelectorAll(querySelector).forEach(targetElement => {
targetElement.setAttribute(attributeName, attributeValue);
});
}
}, 500);
}

private get id(): string {
return `editor-selector-card-${this.state.activeEditor.id}`;
}

public componentDidMount(): void {
if (this.state.activeEditor.provider) {
this.setAttribute(this.id);
}
}

public componentDidUpdate(prevProps: Props): void {
if (this.state.activeEditor.provider) {
this.setAttribute(this.id);
}
if (prevProps.selectedId !== this.props.selectedId) {
const selectedEditor = this.props.editorsGroup.find(
editor => editor.id === this.props.selectedId,
Expand Down Expand Up @@ -176,7 +209,7 @@ export class EditorSelectorEntry extends React.PureComponent<Props, State> {
return (
<Card
hasSelectableInput={true}
id={'editor-selector-card-' + activeEditor.id}
id={this.id}
isCompact={true}
isFlat={true}
isSelectableRaised
Expand All @@ -200,10 +233,10 @@ export class EditorSelectorEntry extends React.PureComponent<Props, State> {
/>
</CardActions>
</CardHeader>
<CardBody>
<CardBody className={styles.cardBody}>
<span className={titleClassName}>{groupName}</span>
{activeEditor.provider && (
<div style={{ fontSize: '75%' }}>
<div className={styles.provider}>
<ReactMarkdown>{activeEditor.provider}</ReactMarkdown>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,34 @@ describe('EditorGallery', () => {
expect(sortedEditors[1].version).toEqual('1.0.0');
});

test('1.0.0(Deprecated) <=> latest', () => {
const editorA = editors[0];
editorA.tags = ['Deprecated'];
editorA.version = '1.0.0';
editorA.id = `${editorA.publisher}/${editorA.name}/${editorA.version}`;

const editorB = editors[1]; // latest

const sortedEditors = sortEditors([editorA, editorB]);

expect(sortedEditors[0].version).toEqual('latest');
expect(sortedEditors[1].version).toEqual('1.0.0'); // Deprecated
});

test('1.0.0 <=> latest(Deprecated)', () => {
const editorA = editors[0];
editorA.version = '1.0.0';
editorA.id = `${editorA.publisher}/${editorA.name}/${editorA.version}`;

const editorB = editors[1]; // latest
editorB.tags = ['Deprecated'];

const sortedEditors = sortEditors([editorA, editorB]);

expect(sortedEditors[0].version).toEqual('1.0.0');
expect(sortedEditors[1].version).toEqual('latest'); // Deprecated
});

test('insiders <=> 1.0.0', () => {
const editorA = editors[0]; // insiders
const editorB = editors[1];
Expand All @@ -141,6 +169,34 @@ describe('EditorGallery', () => {
expect(sortedEditors[0].version).toEqual('insiders');
expect(sortedEditors[1].version).toEqual('1.0.0');
});

test('insiders(Deprecated) <=> 1.0.0', () => {
const editorA = editors[0]; // insiders
editorA.id = `${editorA.publisher}/${editorA.name}/${editorA.version}`;
editorA.tags = ['Deprecated'];

const editorB = editors[1];
editorB.version = '1.0.0';

const sortedEditors = sortEditors([editorA, editorB]);

expect(sortedEditors[0].version).toEqual('insiders');
expect(sortedEditors[1].version).toEqual('1.0.0');
});

test('insiders <=> 1.0.0(Deprecated)', () => {
const editorA = editors[0]; // insiders
editorA.id = `${editorA.publisher}/${editorA.name}/${editorA.version}`;

const editorB = editors[1];
editorB.version = '1.0.0';
editorB.tags = ['Deprecated'];

const sortedEditors = sortEditors([editorA, editorB]);

expect(sortedEditors[0].version).toEqual('insiders');
expect(sortedEditors[1].version).toEqual('1.0.0'); // Deprecated
});
});

describe('select editor', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ export class EditorGallery extends React.PureComponent<Props, State> {
}

const VERSION_PRIORITY: ReadonlyArray<string> = ['insiders', 'next', 'latest'];
const DEPRECATED_TAG = 'Deprecated';
export function sortEditors(editors: che.Plugin[]) {
const sorted = editors.sort((a, b) => {
if (a.name === b.name) {
const aPriority = VERSION_PRIORITY.indexOf(a.version);
const bPriority = VERSION_PRIORITY.indexOf(b.version);
const aPriority =
!a.tags || !a.tags.includes(DEPRECATED_TAG) ? VERSION_PRIORITY.indexOf(a.version) : -1;
const bPriority =
!b.tags || !b.tags.includes(DEPRECATED_TAG) ? VERSION_PRIORITY.indexOf(b.version) : -1;

if (aPriority !== -1 && bPriority !== -1) {
return aPriority - bPriority;
Expand Down
1 change: 1 addition & 0 deletions scripts/yarn/old_version/.deps/EXCLUDED/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This file lists dependencies that do not need CQs or auto-detection does not wor
| `blueimp-md5@2.19.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/blueimp-md5/2.19.0) |
| `codemirror@5.65.16` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/codemirror/5.65.16) |
| `cookie-signature@1.2.1` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/cookie-signature/1.2.1) |
| `ecc-jsbn@0.1.2` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/ecc-jsbn/0.1.2) |
| `fast-uri@2.4.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/fast-uri/2.4.0) |
| `fastify@4.28.1` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/fastify/4.28.1) |
| `jsep@1.3.9` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/jsep/1.3.9) |
Expand Down

0 comments on commit c496147

Please sign in to comment.