Skip to content

Commit

Permalink
Feature/xml json beautifier component (#1929)
Browse files Browse the repository at this point in the history
* Started on hightlight.js

* syntax highlight on xml

* syntax highlight for xml and json

* Not needed

* Not needed

* chore: add license

* pin version

* out of sync

* chore: Update PRODUCTION_DEPENDENCIES.md

* style: format

* Chore: bump version to 0.3.309 for build/infrastructure/eo/chart/Chart.yaml

* Chore: bump version to 0.3.309 for build/infrastructure/eo/chart/values.yaml

* Fixed code smell

* Feedback changes

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and ManBearTM committed Aug 8, 2023
1 parent ef98ab8 commit 9e67b08
Show file tree
Hide file tree
Showing 20 changed files with 348 additions and 10 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions PRODUCTION_DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
| [inputmask](https://github.com/RobinHerbots/Inputmask) | 5.0.7 | MIT |
| [jwt-decode](https://github.com/auth0/jwt-decode) | 3.1.2 | MIT |
| [ng2-charts](https://github.com/valor-software/ng2-charts) | 3.0.11 | ISC |
| [ngx-highlightjs](https://github.com/murhafsousli/ngx-highlightjs) | 10.0.0 | MIT |
| [ngx-mat-select-search](https://github.com/bithost-gmbh/ngx-mat-select-search) | 6.0.0 | MIT |
| [rxjs](https://github.com/reactivex/rxjs) | 7.5.7 | Apache-2.0 |
| [tslib](https://github.com/Microsoft/tslib) | 2.4.0 | 0BSD |
Expand Down
1 change: 1 addition & 0 deletions apps/dh/app-dh/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
*/
/* You can add global styles to this file, and also import other style files */
@use "@energinet-datahub/watt";
@import "~highlight.js/styles/github.css";
2 changes: 1 addition & 1 deletion build/infrastructure/eo/chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v2
name: eo-frontend
description: A Helm chart for Kubernetes
type: application
version: 0.3.308
version: 0.3.309
2 changes: 1 addition & 1 deletion build/infrastructure/eo/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ app:
replicaCount: 2
image:
name: ghcr.io/energinet-datahub/eo-frontend-app
tag: 0.3.308
tag: 0.3.309
12 changes: 12 additions & 0 deletions libs/dh/core/shell/src/lib/dh-core-shell.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { danishDatetimeProviders } from '@energinet-datahub/watt/danish-date-tim
import { applicationInsightsProviders } from '@energinet-datahub/dh/shared/util-application-insights';
import { dhAuthorizationInterceptor } from '@energinet-datahub/dh/shared/feature-authorization';
import { danishLocalProviders } from '@energinet-datahub/gf/configuration-danish-locale';
import { HIGHLIGHT_OPTIONS, HighlightOptions } from 'ngx-highlightjs';

export const dhCoreShellProviders = [
importProvidersFrom([
Expand Down Expand Up @@ -78,4 +79,15 @@ export const dhCoreShellProviders = [
useFactory: MSALInterceptorConfigFactory,
deps: [dhB2CEnvironmentToken],
},
{
provide: HIGHLIGHT_OPTIONS,
useValue: <HighlightOptions>{
coreLibraryLoader: () => import('highlight.js/lib/core'),
lineNumbersLoader: () => import('ngx-highlightjs/line-numbers'),
languages: {
xml: () => import('highlight.js/lib/languages/xml'),
json: () => import('highlight.js/lib/languages/json'),
},
},
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ <h1 class="heading-message-id">{{ message?.messageId }}</h1>
<watt-spinner *ngIf="isLoading; else documentContentTmpl" />

<ng-template #documentContentTmpl>
<pre>{{ documentContent }}</pre>
<watt-code
[code]="documentContent"
[languages]="['xml', 'json']"
[lineNumbers]="true"
/>
</ng-template>
</div>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
}

.message-content {
padding: var(--watt-space-ml);

&--loading {
display: flex;
justify-content: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { WattDatePipe } from '@energinet-datahub/watt/date';
import { WattDrawerComponent, WATT_DRAWER, WattDrawerSize } from '@energinet-datahub/watt/drawer';
import { WattIconComponent } from '@energinet-datahub/watt/icon';
import { WattButtonComponent } from '@energinet-datahub/watt/button';
import { WattCodeComponent } from '@energinet-datahub/watt/code';
import { WattDropdownOptions } from '@energinet-datahub/watt/dropdown';
import { DhMessageArchiveDocumentStore } from '@energinet-datahub/dh/message-archive/data-access-api';
import { DhEmDashFallbackPipe } from '@energinet-datahub/dh/shared/ui-util';
Expand Down Expand Up @@ -65,6 +66,7 @@ import { DocumentTypeNamePipe } from '../shared/dh-message-archive-documentTypeN
RxLet,
WattDescriptionListComponent,
WattDescriptionListItemComponent,
WattCodeComponent,
],
providers: [provideComponentStore(DhMessageArchiveDocumentStore)],
})
Expand Down
1 change: 1 addition & 0 deletions libs/ui-watt/.storybook/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
*/
/* You can add global styles to this file, and also import other style files */
@use "@energinet-datahub/watt";
@import "~highlight.js/styles/github.css";
5 changes: 3 additions & 2 deletions libs/ui-watt/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
"executor": "@storybook/angular:start-storybook",
"options": {
"port": 4400,
"host": "0.0.0.0",
"host": "localhost",
"configDir": "libs/ui-watt/.storybook",
"browserTarget": "ui-watt:build-storybook",
"compodoc": true,
"compodocArgs": ["-e", "json", "-d", "./libs/ui-watt"]
},
"configurations": {
"ci": {
"quiet": true
"quiet": true,
"open": false
}
}
},
Expand Down
17 changes: 17 additions & 0 deletions libs/ui-watt/src/lib/components/code/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @license
* Copyright 2020 Energinet DataHub A/S
*
* Licensed under the Apache License, Version 2.0 (the "License2");
* 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.
*/
export { WattCodeComponent } from './watt-code.component';
60 changes: 60 additions & 0 deletions libs/ui-watt/src/lib/components/code/watt-code.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @license
* Copyright 2020 Energinet DataHub A/S
*
* Licensed under the Apache License, Version 2.0 (the "License2");
* 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.
*/
watt-code {
display: block;
overflow: auto;

pre {
display: flex;
margin-top: 0;
margin-bottom: 0;
word-wrap: break-word;

code {
flex: 1;
line-height: 1.8em;
font-size: 14px;
min-height: 100%;
padding: 1em 1.2em;

table.hljs-ln {
border-collapse: separate;
border-spacing: 0;
border: 1px solid var(--watt-color-neutral-grey-300);
border-radius: 4px;
}

td.hljs-ln-line.hljs-ln-code {
padding-left: var(--watt-space-ml);
}

td.hljs-ln-line.hljs-ln-numbers {
user-select: none;
border-left: 1px solid var(--watt-color-neutral-grey-300);
border-right: 1px solid var(--watt-color-neutral-grey-300);
padding-right: var(--watt-space-l);
padding-left: var(--watt-space-m);
background: var(--watt-color-primary-ultralight);
color: var(--watt-color-primary-dark);
}

span.hljs-tag span.hljs-attr::before {
content: "\a";
}
}
}
}
39 changes: 39 additions & 0 deletions libs/ui-watt/src/lib/components/code/watt-code.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @license
* Copyright 2020 Energinet DataHub A/S
*
* Licensed under the Apache License, Version 2.0 (the "License2");
* 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 { Component, ChangeDetectionStrategy, Input, ViewEncapsulation } from '@angular/core';
import { HighlightModule } from 'ngx-highlightjs';

type languages = 'xml' | 'json';

@Component({
selector: 'watt-code',
template: `
<pre>
<code [highlight]="code" [lineNumbers]="lineNumbers" [languages]="languages"></code>
</pre>
`,
styleUrls: ['./watt-code.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
standalone: true,
imports: [HighlightModule],
})
export class WattCodeComponent {
@Input({ required: true }) code: string | null = null;
@Input() languages!: languages[];
@Input() lineNumbers = true;
}
165 changes: 165 additions & 0 deletions libs/ui-watt/src/lib/components/code/watt-code.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/**
* @license
* Copyright 2020 Energinet DataHub A/S
*
* Licensed under the Apache License, Version 2.0 (the "License2");
* 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 { Meta, StoryFn, applicationConfig } from '@storybook/angular';

import { WattCodeComponent } from './watt-code.component';
import { HIGHLIGHT_OPTIONS } from 'ngx-highlightjs';

const meta: Meta<WattCodeComponent> = {
title: 'Components/Code',
component: WattCodeComponent,
decorators: [
applicationConfig({
providers: [
{
provide: HIGHLIGHT_OPTIONS,
useValue: {
coreLibraryLoader: () => import('highlight.js/lib/core'),
lineNumbersLoader: () => import('ngx-highlightjs/line-numbers'),
languages: {
xml: () => import('highlight.js/lib/languages/xml'),
json: () => import('highlight.js/lib/languages/json'),
},
},
},
],
}),
],
};

export default meta;

const Template: StoryFn = (args) => ({
props: args,
template: `
<watt-code
[code]=code
[languages]=languages
[lineNumbers]=lineNumbers
/>
`,
});

export const XmlWithLineNumbers = Template.bind({});

XmlWithLineNumbers.args = {
code: `<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2021 (x64) (http://www.altova.com)-->
<cim:RequestChangeAccountingPointCharacteristics_MarketDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cim="urn:ebix:org:ChangeAccountingPointCharacteristics:0:1" xsi:schemaLocation="urn:ebix:org:ChangeAccountingPointCharacteristics:0:1 urn-ediel-org-RSM-021-ChangeOfAccountingPointCharacteristics-RequestChangeOfAccountingPointCharacteristics-0-1.xsd">
<cim:mRID>String</cim:mRID>
<cim:type>E58</cim:type>
<cim:process.processType>E02</cim:process.processType>
<cim:businessSector.type>E16</cim:businessSector.type>
<cim:sender_MarketParticipant.mRID codingScheme="NMK">a</cim:sender_MarketParticipant.mRID>
<cim:sender_MarketParticipant.marketRole.type>A08</cim:sender_MarketParticipant.marketRole.type>
<cim:receiver_MarketParticipant.mRID codingScheme="NFI">a</cim:receiver_MarketParticipant.mRID>
<cim:receiver_MarketParticipant.marketRole.type>A33</cim:receiver_MarketParticipant.marketRole.type>
<cim:createdDateTime>2001-12-17T09:30:47Z</cim:createdDateTime>
<cim:MktActivityRecord>
<cim:mRID>whateverasdasd</cim:mRID>
<cim:MarketEvaluationPoint>
<cim:mRID codingScheme="NNL">571313180400012882</cim:mRID>
<cim:type>E17</cim:type>
<cim:description>String</cim:description>
<cim:settlementMethod>D01</cim:settlementMethod>
<cim:meteringMethod>D01</cim:meteringMethod>
<cim:meteredDataCollectionMethod>D01</cim:meteredDataCollectionMethod>
<cim:netSettlementGroup>0</cim:netSettlementGroup>
<cim:productionObligation>false</cim:productionObligation>
<cim:mPConnectionType>D01</cim:mPConnectionType>
<cim:readCycle>PT1H</cim:readCycle>
<cim:disconnectionMethod>D01</cim:disconnectionMethod>
<cim:nextReadingDate></cim:nextReadingDate>
<cim:ratedCurrent unit="AMP">1000</cim:ratedCurrent>
<cim:connectionState>D03</cim:connectionState>
<cim:physicalConnectionCapacity>
<cim:value>1000</cim:value>
<cim:unit>KWH</cim:unit>
</cim:physicalConnectionCapacity>
<cim:firstCustomer_MarketParticipant.mRID codingScheme="NLU">a</cim:firstCustomer_MarketParticipant.mRID>
<cim:firstCustomer_MarketParticipant.name>String</cim:firstCustomer_MarketParticipant.name>
<cim:secondCustomer_MarketParticipant.mRID codingScheme="NRU">a</cim:secondCustomer_MarketParticipant.mRID>
<cim:secondCustomer_MarketParticipant.name>String</cim:secondCustomer_MarketParticipant.name>
<cim:marketAgreement.contractedConnectionCapacity>
<cim:value>500</cim:value>
<cim:unit>KWH</cim:unit>
<cim:multiplier>k</cim:multiplier>
</cim:marketAgreement.contractedConnectionCapacity>
<cim:meter.mRID>012345678912345</cim:meter.mRID>
<cim:Series>
<cim:estimatedAnnualVolume_Quantity.quantity>110</cim:estimatedAnnualVolume_Quantity.quantity>
<cim:quantity_Measure_Unit.name>KWH</cim:quantity_Measure_Unit.name>
<cim:product>8716867000030</cim:product>
</cim:Series>
<cim:register.rightDigitCount>100</cim:register.rightDigitCount>
<cim:register.leftDigitCount>100</cim:register.leftDigitCount>
<cim:register.channels.readingType.accumulation>D01</cim:register.channels.readingType.accumulation>
<cim:register.channels.readingType.multiplier>0</cim:register.channels.readingType.multiplier>
<cim:register.channels.readingType.unit>MTQ</cim:register.channels.readingType.unit>
<cim:inMeteringGridArea_Domain.mRID codingScheme="NLV">870</cim:inMeteringGridArea_Domain.mRID>
<cim:usagePointLocation.mainAddress>
<cim:streetDetail>
<cim:number>String</cim:number>
<cim:name>String</cim:name>
<cim:type>String</cim:type>
<cim:code>String</cim:code>
<cim:buildingName>String</cim:buildingName>
<cim:suiteNumber>String</cim:suiteNumber>
<cim:floorIdentification>String</cim:floorIdentification>
</cim:streetDetail>
<cim:townDetail>
<cim:code>String</cim:code>
<cim:section>String</cim:section>
<cim:name>String</cim:name>
<cim:stateOrProvince>String</cim:stateOrProvince>
<cim:country>AA</cim:country>
</cim:townDetail>
<cim:status>
<cim:value>String</cim:value>
<cim:dateTime>2021-06-17T09:30:47Z</cim:dateTime>
<cim:remark>String</cim:remark>
<cim:reason>String</cim:reason>
</cim:status>
<cim:postalCode>String</cim:postalCode>
<cim:poBox>String</cim:poBox>
<cim:language>String</cim:language>
</cim:usagePointLocation.mainAddress>
<cim:usagePointLocation.officialAddressIndicator>true</cim:usagePointLocation.officialAddressIndicator>
<cim:usagePointLocation.geoInfoReference>a</cim:usagePointLocation.geoInfoReference>
<cim:meteringGridArea_Domain.mRID codingScheme="NKZ">870</cim:meteringGridArea_Domain.mRID>
<cim:outMeteringGridArea_Domain.mRID codingScheme="NAT">871</cim:outMeteringGridArea_Domain.mRID>
<cim:parent_MarketEvaluationPoint.mRID codingScheme="NSE">a</cim:parent_MarketEvaluationPoint.mRID>
<cim:parent_MarketEvaluationPoint.description>E17</cim:parent_MarketEvaluationPoint.description>
<cim:linked_MarketEvaluationPoint.mRID codingScheme="NNL">571234567891234636</cim:linked_MarketEvaluationPoint.mRID>
<cim:mktPSRType.psrType>B14</cim:mktPSRType.psrType>
<cim:accountingPointResponsible_MarketParticipant.mRID codingScheme="NNO">a</cim:accountingPointResponsible_MarketParticipant.mRID>
</cim:MarketEvaluationPoint>
<cim:businessProcessReference_MktActivityRecord.mRID>String</cim:businessProcessReference_MktActivityRecord.mRID>
<cim:start_DateAndOrTime.dateTime>2021-07-01T22:00:00Z</cim:start_DateAndOrTime.dateTime>
</cim:MktActivityRecord>
</cim:RequestChangeAccountingPointCharacteristics_MarketDocument>`,
languages: ['xml'],
lineNumbers: true,
};

export const JsonWithLineNumbers = Template.bind({});

JsonWithLineNumbers.args = {
code: `{ "foo": "bar" }`,
languages: ['json'],
lineNumbers: true,
};
Loading

0 comments on commit 9e67b08

Please sign in to comment.