Skip to content

Commit

Permalink
Fix support for URL params inside the URL of getting started samples …
Browse files Browse the repository at this point in the history
…definition (#1063)

* fix: handleSampleCardClick

Signed-off-by: Oleksii Orel <oorel@redhat.com>
  • Loading branch information
olexii4 authored Mar 8, 2024
1 parent 49efdad commit 583905d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const editorImage = 'custom-editor-image';

describe('Samples List', () => {
const sampleUrl = 'https://github.com/che-samples/quarkus-quickstarts/tree/devfilev2';
const origin = window.location.origin;
let storeBuilder: FakeStoreBuilder;

beforeEach(() => {
Expand All @@ -51,7 +52,7 @@ describe('Samples List', () => {
tags: ['Community', 'Java', 'Quarkus', 'OpenJDK', 'Maven', 'Debian'],
icon: '/images/quarkus.svg',
links: {
v2: sampleUrl,
v2: `${sampleUrl}?df=devfile2.yaml`,
devWorkspaces: {
'che-incubator/che-code/insiders':
'registry-url/devfile-registry/devfiles/quarkus/devworkspace-che-code-insiders.yaml',
Expand Down Expand Up @@ -106,9 +107,7 @@ describe('Samples List', () => {
userEvent.click(sampleCardButton);

expect(mockWindowOpen).toHaveBeenCalledWith(
`/load-factory?url=${encodeURIComponent(
sampleUrl,
)}&che-editor=che-incubator%2Fche-code%2Finsiders&devWorkspace=registry-url%2Fdevfile-registry%2Fdevfiles%2Fquarkus%2Fdevworkspace-che-code-insiders.yaml&editor-image=custom-editor-image&storageType=${preferredPvcStrategy}`,
`${origin}#${sampleUrl}?df=devfile2.yaml&che-editor=che-incubator%2Fche-code%2Finsiders&devWorkspace=registry-url%2Fdevfile-registry%2Fdevfiles%2Fquarkus%2Fdevworkspace-che-code-insiders.yaml&editor-image=custom-editor-image&storageType=${preferredPvcStrategy}`,
'_blank',
);
});
Expand All @@ -126,9 +125,7 @@ describe('Samples List', () => {
userEvent.click(sampleCardButton);

expect(mockWindowOpen).toHaveBeenCalledWith(
`/load-factory?url=${encodeURIComponent(
sampleUrl,
)}&che-editor=che-incubator%2Fche-code%2Finsiders&devWorkspace=registry-url%2Fdevfile-registry%2Fdevfiles%2Fquarkus%2Fdevworkspace-che-code-insiders.yaml&editor-image=custom-editor-image&storageType=ephemeral`,
`${origin}#${sampleUrl}?df=devfile2.yaml&che-editor=che-incubator%2Fche-code%2Finsiders&devWorkspace=registry-url%2Fdevfile-registry%2Fdevfiles%2Fquarkus%2Fdevworkspace-che-code-insiders.yaml&editor-image=custom-editor-image&storageType=ephemeral`,
'_blank',
);
expect(mockWindowOpen).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -169,9 +166,7 @@ describe('Samples List', () => {
userEvent.click(sampleCardButton);

expect(mockWindowOpen).toHaveBeenCalledWith(
`/load-factory?url=${encodeURIComponent(
sampleUrl,
)}&che-editor=che-incubator%2Fche-code%2Finsiders&devWorkspace=registry-url%2Fdevfile-registry%2Fdevfiles%2Fquarkus%2Fdevworkspace-che-code-insiders.yaml&editor-image=custom-editor-image&storageType=${preferredPvcStrategy}`,
`${origin}#${sampleUrl}?df=devfile2.yaml&che-editor=che-incubator%2Fche-code%2Finsiders&devWorkspace=registry-url%2Fdevfile-registry%2Fdevfiles%2Fquarkus%2Fdevworkspace-che-code-insiders.yaml&editor-image=custom-editor-image&storageType=${preferredPvcStrategy}`,
'_blank',
);
});
Expand All @@ -189,9 +184,7 @@ describe('Samples List', () => {
userEvent.click(sampleCardButton);

expect(mockWindowOpen).toHaveBeenCalledWith(
`/load-factory?url=${encodeURIComponent(
sampleUrl,
)}&che-editor=che-incubator%2Fche-code%2Finsiders&devWorkspace=registry-url%2Fdevfile-registry%2Fdevfiles%2Fquarkus%2Fdevworkspace-che-code-insiders.yaml&editor-image=custom-editor-image&storageType=persistent`,
`${origin}#${sampleUrl}?df=devfile2.yaml&che-editor=che-incubator%2Fche-code%2Finsiders&devWorkspace=registry-url%2Fdevfile-registry%2Fdevfiles%2Fquarkus%2Fdevworkspace-che-code-insiders.yaml&editor-image=custom-editor-image&storageType=persistent`,
'_blank',
);
expect(mockWindowOpen).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { connect, ConnectedProps } from 'react-redux';
import SamplesListGallery from '@/pages/GetStarted/SamplesList/Gallery';
import SamplesListToolbar from '@/pages/GetStarted/SamplesList/Toolbar';
import { EDITOR_ATTR, EDITOR_IMAGE_ATTR } from '@/services/helpers/factoryFlow/buildFactoryParams';
import { buildFactoryLocation, toHref } from '@/services/helpers/location';
import { che } from '@/services/models';
import { AppState } from '@/store';
import {
Expand Down Expand Up @@ -72,7 +71,9 @@ class SamplesList extends React.PureComponent<Props, State> {
private async handleSampleCardClick(metadata: DevfileRegistryMetadata): Promise<void> {
const { editorDefinition, editorImage } = this.props;

const factoryUrlParams = new URLSearchParams({ url: metadata.links.v2 });
const url = new URL(metadata.links.v2);

const factoryUrlParams = new URLSearchParams(url.searchParams);

if (editorDefinition !== undefined) {
factoryUrlParams.append(EDITOR_ATTR, editorDefinition);
Expand All @@ -90,10 +91,8 @@ class SamplesList extends React.PureComponent<Props, State> {
const storageType = this.getStorageType();
factoryUrlParams.append('storageType', storageType);

const factoryLocation = buildFactoryLocation();
factoryLocation.search = factoryUrlParams.toString();

const factoryLink = toHref(this.props.history, factoryLocation);
url.search = factoryUrlParams.toString();
const factoryLink = `${window.location.origin}#${url.toString()}`;

window.open(factoryLink, '_blank');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@
{
"displayName": "Empty Workspace",
"description": "Start an empty remote development environment and create files or clone a git repository afterwards",
"tags": [
"Empty"
],
"tags": ["Empty"],
"icon": "/images/empty.svg",
"links": {
"v2": "/devfiles/empty.yaml"
Expand All @@ -187,22 +185,14 @@
"displayName": ".NET 5.0",
"description": ".NET 5.0 application",
"type": "stack",
"tags": [
".NET",
".NET 5.0",
"Devfile.io"
],
"tags": [".NET", ".NET 5.0", "Devfile.io"],
"icon": "https://github.com/dotnet/brand/raw/main/logo/dotnet-logo.png",
"projectType": "dotnet",
"language": ".NET",
"links": {
"v2": "devfile-catalog/dotnet50:1.0.3"
},
"resources": [
"devfile.yaml"
],
"starterProjects": [
"dotnet50-example"
]
"resources": ["devfile.yaml"],
"starterProjects": ["dotnet50-example"]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@
"version": "latest",
"icon": "/v3/images/notebook.svg"
}
]
]
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6191,7 +6191,7 @@ inversify@^6.0.0, inversify@^6.0.1:
resolved "https://registry.yarnpkg.com/inversify/-/inversify-6.0.2.tgz#dc7fa0348213d789d35ffb719dea9685570989c7"
integrity sha512-i9m8j/7YIv4mDuYXUAcrpKPSaju/CIly9AHK5jvCBeoiM/2KEsuCQTTP+rzSWWpLYWRukdXFSl6ZTk2/uumbiA==

ip@2.0.1, ip@^2.0.0:
ip@^2.0.0, ip@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/ip/-/ip-2.0.1.tgz#e8f3595d33a3ea66490204234b77636965307105"
integrity sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ==
Expand Down Expand Up @@ -11495,7 +11495,7 @@ undici-types@~5.26.4:
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==

undici@5.28.3, undici@^5.19.1:
undici@^5.19.1, undici@^5.28.3:
version "5.28.3"
resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.3.tgz#a731e0eff2c3fcfd41c1169a869062be222d1e5b"
integrity sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA==
Expand Down

0 comments on commit 583905d

Please sign in to comment.