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

Fix editor selector cards #1246

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
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 @@ -18,3 +18,7 @@
.activeCard {
color: #000;
}

.provider {
font-size: 75%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Card,
CardActions,
CardBody,
CardFooter,
CardHeader,
Dropdown,
DropdownItem,
Expand Down Expand Up @@ -45,6 +46,8 @@
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 +62,38 @@
};
}

// 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 65 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 65 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 65 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 65 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 +210,7 @@
return (
<Card
hasSelectableInput={true}
id={'editor-selector-card-' + activeEditor.id}
id={this.id}
isCompact={true}
isFlat={true}
isSelectableRaised
Expand All @@ -202,12 +236,12 @@
</CardHeader>
<CardBody>
<span className={titleClassName}>{groupName}</span>
{activeEditor.provider && (
<div style={{ fontSize: '75%' }}>
<ReactMarkdown>{activeEditor.provider}</ReactMarkdown>
</div>
)}
</CardBody>
{activeEditor.provider && (
<CardFooter>
<ReactMarkdown className={styles.provider}>{activeEditor.provider}</ReactMarkdown>
</CardFooter>
)}
</Card>
);
}
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('1.0.0');
expect(sortedEditors[1].version).toEqual('insiders'); // Deprecated
});

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,23 +135,41 @@ 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);

if (aPriority !== -1 && bPriority !== -1) {
return aPriority - bPriority;
} else if (aPriority !== -1) {
return -1;
} else if (bPriority !== -1) {
return 1;
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);

if (aPriority !== -1 && bPriority !== -1) {
return aPriority - bPriority;
} else if (aPriority !== -1) {
return -1;
} else if (bPriority !== -1) {
return 1;
}
}

return a.id.localeCompare(b.id);
})
.sort((a, b) => {
if (a.name === b.name) {
const aPriority = a.tags?.includes(DEPRECATED_TAG) ? -1 : 1;
const bPriority = b.tags?.includes(DEPRECATED_TAG) ? -1 : 1;

if (aPriority !== -1 && bPriority !== -1) {
return 0;
} else if (aPriority !== -1) {
return -1;
} else if (bPriority !== -1) {
return 1;
}
}
}

return a.id.localeCompare(b.id);
});
return a.id.localeCompare(b.id);
});

return sorted;
}
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
Loading