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

[4.6.x] fix: code preview component fix #10152

Open
wants to merge 1 commit into
base: 4.6.x
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--

Copyright (C) 2015 The Gravitee team (http://gravitee.io)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

<code>
<div class="editor code-area file-preview">
<div class="editor__copy-to-clipboard" gioClipboardCopyWrapper [alwaysVisible]="true" [contentToCopy]="payload"></div>
<div class="editor__lines">
@for (line of payload.split('\n'); track line + i; let i = $index) {
<div class="line">
<span class="line__number">{{ i + 1 }}</span>
<span class="line__code">{{ line | replaceSpaces }}</span>
</div>
}
</div>
</div>
</code>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ReplaceSpacesPipe } from './replace-spaces.pipe';

describe('ReplaceSpacesPipe', () => {
it('create an instance', () => {
const pipe = new ReplaceSpacesPipe();
expect(pipe).toBeTruthy();
});

it('should return modified spaces if there are more than one next to each other', () => {
const pipe = new ReplaceSpacesPipe();
expect(pipe.transform(' ')).toEqual('\xa0\xa0');
});

it('should return the same spaces if only one next to each other exists', () => {
const pipe = new ReplaceSpacesPipe();
expect(pipe.transform(' ')).toEqual(' ');
});

it('should not modify spaces if they are not next to each other', () => {
const pipe = new ReplaceSpacesPipe();
expect(pipe.transform(' A ')).toEqual(' A ');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'replaceSpaces',
standalone: true,
})
export class ReplaceSpacesPipe implements PipeTransform {
transform(line: string): string {
// Transform spaces if there are more than occurrence next to each other.
return line.replace(/\s{2,}/g, (match) => '\xa0'.repeat(match.length));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import lombok.Data;
import lombok.With;

<<<<<<< HEAD:gravitee-apim-rest-api/gravitee-apim-rest-api-service/src/main/java/io/gravitee/apim/core/analytics/model/EnvironmentAnalyticsQueryParameters.java
@Data
@Builder
public class EnvironmentAnalyticsQueryParameters {
Expand All @@ -29,4 +30,17 @@ public class EnvironmentAnalyticsQueryParameters {

long from;
long to;
=======
import { ReplaceSpacesPipe } from '../../pipes/replace-spaces.pipe';

@Component({
selector: 'file-preview',
standalone: true,
imports: [GioClipboardModule, ReplaceSpacesPipe],
templateUrl: './file-preview.component.html',
styleUrl: './file-preview.component.scss',
})
export class FilePreviewComponent {
@Input() payload: string;
>>>>>>> c7cb597a7c (fix: code preview component fix):gravitee-apim-console-webui/src/shared/components/file-preview/file-preview.component.ts
}