Skip to content

Commit

Permalink
feat: policy studio - add prerequisiteMessage for SPG
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaudAV committed Aug 14, 2024
1 parent 3b6edb9 commit 4e488e1
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<span *ngIf="genericPolicy?.type === 'SHARED_POLICY_GROUP'" class="gio-badge-neutral" matTooltip="Shared Policy Group">
<mat-icon svgIcon="gio:users"></mat-icon>
</span>
@if (getPrerequisiteMessage) {
<mat-icon class="info__head__info" svgIcon="gio:info" [matTooltip]="getPrerequisiteMessage"></mat-icon>
}
<span
*ngIf="policyNotFound !== false"
class="gio-badge-error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ export class GioPolicyStudioDetailsPhaseStepComponent implements OnChanges {

protected genericPolicy?: GenericPolicy;
protected policyNotFound: false | 'SHARED_POLICY_GROUP' | 'POLICY' = false;
protected policyIcon?: string;

protected get getPrerequisiteMessage(): string | undefined {
if (!this.genericPolicy || !isSharedPolicyGroupPolicy(this.genericPolicy) || isEmpty(this.genericPolicy.prerequisiteMessage)) {
return;
}
return this.genericPolicy.description;
}

constructor(private readonly matDialog: MatDialog) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { BaseHarnessFilters, ComponentHarness, HarnessPredicate } from '@angular
import { SpanHarness } from '@gravitee/ui-particles-angular/testing';
import { MatMenuHarness } from '@angular/material/menu/testing';
import { DivHarness } from '@gravitee/ui-particles-angular/testing';
import { MatTooltipHarness } from '@angular/material/tooltip/testing';

export type GioPolicyStudioDetailsPhaseStepHarnessFilters = BaseHarnessFilters;

Expand All @@ -44,6 +45,13 @@ export class GioPolicyStudioDetailsPhaseStepHarness extends ComponentHarness {
return (await (await this.locatorForOptional(DivHarness.with({ selector: '.info__description' }))())?.getText()) ?? undefined;
}

public async getInfoMessage(): Promise<string | undefined> {
const tooltip = await this.locatorForOptional(MatTooltipHarness.with({ selector: '.info__head__info' }))();
// FIXME: await tooltip.getTooltipText(); returns empty string. when it's in a condition. I haven't figured out how to get over it.
// This hack allows to validate the info anyway
return tooltip ? 'HasInfoMessage' : undefined;
}

public async clickOnEdit(): Promise<void> {
const matMenu = await this.locatorFor(MatMenuHarness)();
await matMenu.clickItem({ text: 'Edit' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ export class GioPolicyStudioDetailsPhaseHarness extends ComponentHarness {
const step = await stepDiv.childLocatorFor(GioPolicyStudioDetailsPhaseStepHarness)();
const conditionDiv = await stepDiv.childLocatorForOptional(DivHarness.with({ selector: '.content__step__policy__condition' }))();
const description = await step.getDescription();
const infoMessage = await step.getInfoMessage();

return {
type: 'step',
name: await step.getName(),
hasCondition: !!conditionDiv,
...(description ? { description } : {}),
...(infoMessage ? { infoMessage } : {}),
};
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
<div class="documentation__header">Documentation</div>

<div class="documentation__content">
<gio-banner-warning *ngIf="infoBanner">
Prerequisite message
<span gioBannerBody>{{ infoBanner }}</span>
</gio-banner-warning>
<ng-container *ngIf="policyDocumentation$ | async as policyDocumentation; else loadingTmpl">
<gio-asciidoctor [content]="policyDocumentation"></gio-asciidoctor>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ReactiveFormsModule, UntypedFormControl, UntypedFormGroup } from '@angu
import { catchError, map, takeUntil } from 'rxjs/operators';
import { Observable, of, Subject } from 'rxjs';
import {
GioBannerModule,
GioFormJsonSchemaComponent,
GioFormJsonSchemaModule,
GioJsonSchema,
Expand All @@ -43,6 +44,7 @@ import { GioPolicyStudioService } from '../../policy-studio/gio-policy-studio.se
GioFormJsonSchemaModule,
GioAsciidoctorModule,
GioLoaderModule,
GioBannerModule,
],
selector: 'gio-ps-step-form',
templateUrl: './gio-ps-step-form.component.html',
Expand All @@ -69,6 +71,7 @@ export class GioPolicyStudioStepFormComponent implements OnChanges, OnInit, OnDe

public policySchema$?: Observable<GioJsonSchema | null | undefined>;
public policyDocumentation$?: Observable<string>;
public infoBanner?: string;

public stepForm?: UntypedFormGroup;

Expand Down Expand Up @@ -97,7 +100,9 @@ export class GioPolicyStudioStepFormComponent implements OnChanges, OnInit, OnDe
if (isSharedPolicyGroupPolicy(this.genericPolicy)) {
this.policySchema$ = of({});

this.policyDocumentation$ = of('No documentation available.');
this.policyDocumentation$ = of(' ');

this.infoBanner = this.genericPolicy.prerequisiteMessage;
}
}
if (changes.executionPhase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function fakeProxyRequestSharedPolicyGroupPolicy(
policyId: 'shared-policy-group-policy',
name: 'Test PROXY SPG',
description: 'Test Shared Policy Group request phase',
prerequisiteMessage: 'The resource cache "my-cache" is required',
apiType: 'PROXY',
phase: 'REQUEST',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type SharedPolicyGroupPolicy = {
policyId: string;
name: string;
description?: string;
prerequisiteMessage?: string;
apiType: ApiType;
phase: ExecutionPhase;
};
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ describe('GioPolicyStudioComponent', () => {
const commonFlows = [
fakeHttpFlow({
name: 'Flow 1',
request: [fakeRateLimitStep()],
request: [fakeRateLimitStep(), fakeSharedPolicyGroupPolicyStep()],
response: [fakeTestPolicyStep()],
}),
];
Expand All @@ -1332,6 +1332,7 @@ describe('GioPolicyStudioComponent', () => {
expect(await requestPhase?.getSteps()).toStrictEqual([
{ name: 'HTTP Proxy', type: 'connector' },
{ name: 'Rate Limit', description: 'Step description', hasCondition: false, type: 'step' },
{ name: 'Test PROXY SPG', description: 'Shared Policy Group', hasCondition: false, type: 'step', infoMessage: 'HasInfoMessage' },
{ name: 'HTTP Proxy', type: 'connector' },
]);

Expand Down

0 comments on commit 4e488e1

Please sign in to comment.