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

Me/record field license #860

Merged
merged 5 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(editor): share field wrapper logic
  • Loading branch information
LHBruneton-C2C committed Apr 30, 2024
commit 3b6d108f458e219623c90ddc3961e52038c1125a
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
<div class="flex flex-col h-full">
<div class="mb-2 flex flex-row">
<label class="grow">
<span class="font-medium field-label">{{
config.labelKey | translate
}}</span>
<span *ngIf="config.hintKey" class="text-gray-900 text-sm">
- {{ config.hintKey | translate }}
</span>
</label>
<mat-icon
*ngIf="isFieldOk"
class="material-symbols-outlined text-[#c6d950] icon-ok"
>check_circle</mat-icon
>
<mat-icon
*ngIf="isFieldLocked"
class="material-symbols-outlined text-blue-400 icon-locked"
>lock</mat-icon
>
<mat-icon
*ngIf="isFieldInvalid"
class="material-symbols-outlined text-pink-500 icon-invalid"
>cancel</mat-icon
<ng-container *ngIf="withoutWrapper; else withGenericWrapper">
<ng-container *ngTemplateOutlet="fieldContent"></ng-container>
</ng-container>
<ng-template #withGenericWrapper>
<gn-ui-form-field-wrapper
[label]="config.labelKey | translate"
[hint]="config.hintKey | translate"
>
</div>
<ng-container *ngTemplateOutlet="fieldContent"></ng-container>
</gn-ui-form-field-wrapper>
</ng-template>
</div>

<ng-template #fieldContent>
<ng-container *ngIf="isTitle">
<div class="flex justify-between items-center gap-3">
<h2
Expand All @@ -48,6 +37,14 @@
</span>
</div>
</ng-container>
<ng-container *ngIf="isAbstract">
<gn-ui-form-field-rich
class="h-[8rem]"
[control]="formControl"
[label]="config.labelKey | translate"
[hint]="config.hintKey | translate"
></gn-ui-form-field-rich>
</ng-container>
<ng-container *ngIf="isSimpleField">
<gn-ui-form-field-simple
[type]="simpleType"
Expand All @@ -63,14 +60,6 @@
[invalid]="isFieldInvalid"
></gn-ui-form-field-file>
</ng-container>
<ng-container *ngIf="isAbstract">
<gn-ui-form-field-rich
class="h-[8rem]"
[control]="formControl"
[label]="config.labelKey | translate"
[hint]="config.hintKey | translate"
></gn-ui-form-field-rich>
</ng-container>
<ng-container *ngIf="isArrayField">
<gn-ui-form-field-array></gn-ui-form-field-array>
</ng-container>
Expand All @@ -89,4 +78,4 @@
>
{{ config.invalidHintKey | translate }}
</div>
</div>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { FormFieldSimpleComponent } from './form-field-simple/form-field-simple.
import { FormFieldSpatialExtentComponent } from './form-field-spatial-extent/form-field-spatial-extent.component'
import { FormFieldTemporalExtentComponent } from './form-field-temporal-extent/form-field-temporal-extent.component'
import { FormFieldComponent } from './form-field.component'
import { FormFieldWrapperComponent } from '@geonetwork-ui/ui/layout'
import { EditableLabelDirective } from '@geonetwork-ui/ui/inputs'

describe('FormFieldComponent', () => {
let component: FormFieldComponent
Expand All @@ -32,12 +34,30 @@ describe('FormFieldComponent', () => {
expect(component).toBeTruthy()
})

describe('abstract field', () => {
let formField
beforeEach(() => {
component.model = 'abstract'
component.value = 'Some rich abstract value'
fixture.detectChanges()
formField = fixture.debugElement.query(
By.directive(FormFieldRichComponent)
).componentInstance
})
it('creates a rich text form field', () => {
expect(formField).toBeTruthy()
})
})
describe('simple field', () => {
let fieldWrapper
let formField
beforeEach(async () => {
component.config.type = 'url'
fixture.detectChanges()
await fixture.whenStable()
fieldWrapper = fixture.debugElement.query(
By.directive(FormFieldWrapperComponent)
).componentInstance
formField = fixture.debugElement.query(
By.directive(FormFieldSimpleComponent)
).componentInstance
Expand All @@ -48,13 +68,8 @@ describe('FormFieldComponent', () => {
expect(formField.readonly).toEqual(component.config.locked)
expect(formField.invalid).toEqual(component.config.invalid)
})
it('shows the label', () => {
const label = fixture.debugElement.query(By.css('.field-label'))
expect(label.nativeElement.textContent).toEqual(component.config.labelKey)
})
it('shows the ok icon', () => {
const icon = fixture.debugElement.query(By.css('.icon-ok'))
expect(icon).toBeTruthy()
it('creates a form field wrapper', () => {
expect(fieldWrapper).toBeTruthy()
})
})
describe('simple field (invalid)', () => {
Expand All @@ -74,10 +89,6 @@ describe('FormFieldComponent', () => {
expect(formField.type).toEqual(component.config.type)
expect(formField.invalid).toEqual(true)
})
it('shows the invalid icon', () => {
const icon = fixture.debugElement.query(By.css('.icon-invalid'))
expect(icon).toBeTruthy()
})
it('shows the invalid hint key', () => {
const hint = fixture.debugElement.query(By.css('.field-invalid-hint'))
expect(hint.nativeElement.textContent).toContain(
Expand All @@ -103,24 +114,6 @@ describe('FormFieldComponent', () => {
expect(formField.readonly).toEqual(true)
expect(formField.invalid).toEqual(false)
})
it('shows the locked icon', () => {
const icon = fixture.debugElement.query(By.css('.icon-locked'))
expect(icon).toBeTruthy()
})
})
describe('abstract field', () => {
let formField
beforeEach(() => {
component.model = 'abstract'
component.value = 'Some rich abstract value'
fixture.detectChanges()
formField = fixture.debugElement.query(
By.directive(FormFieldRichComponent)
).componentInstance
})
it('creates a rich text form field', () => {
expect(formField).toBeTruthy()
})
})
describe('file field', () => {
let formField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { FormControl, ReactiveFormsModule } from '@angular/forms'
import { MatIconModule } from '@angular/material/icon'
import { MatTooltipModule } from '@angular/material/tooltip'
import { EditableLabelDirective } from '@geonetwork-ui/ui/inputs'
import { FormFieldWrapperComponent } from '@geonetwork-ui/ui/layout'
import { TranslateModule } from '@ngx-translate/core'
import { Observable } from 'rxjs'
import { FormFieldArrayComponent } from './form-field-array/form-field-array.component'
Expand All @@ -34,6 +35,7 @@ import { FormFieldConfig } from './form-field.model'
EditableLabelDirective,
MatIconModule,
MatTooltipModule,
FormFieldWrapperComponent,
FormFieldSimpleComponent,
FormFieldRichComponent,
FormFieldObjectComponent,
Expand Down Expand Up @@ -118,4 +120,8 @@ export class FormFieldComponent {
get isAbstract() {
return this.model === 'abstract'
}

get withoutWrapper() {
return this.model === 'title' || this.model === 'abstract'
}
}