-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(me): Add contacts for resource field
- Loading branch information
Romuald Caplier
committed
Jul 31, 2024
1 parent
e397bff
commit 3609c85
Showing
31 changed files
with
890 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
apps/metadata-editor/src/app/edit/components/page-selector/page-selector.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
libs/feature/editor/src/lib/components/contact-card/contact-card.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
import { ContactCardComponent } from './contact-card.component' | ||
import { | ||
Individual, | ||
Organization, | ||
} from '@geonetwork-ui/common/domain/model/record' | ||
import { MatIconModule } from '@angular/material/icon' | ||
import { CommonModule } from '@angular/common' | ||
import { ButtonComponent } from '@geonetwork-ui/ui/inputs' | ||
|
||
describe('ContactCardComponent', () => { | ||
let component: ContactCardComponent | ||
let fixture: ComponentFixture<ContactCardComponent> | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
CommonModule, | ||
MatIconModule, | ||
ButtonComponent, | ||
ContactCardComponent, | ||
], | ||
}).compileComponents() | ||
}) | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ContactCardComponent) | ||
component = fixture.componentInstance | ||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create the component', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
|
||
it('should have a defined contact input', () => { | ||
const mockContact: Individual = { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
organization: { name: 'Org1' } as Organization, | ||
email: '[email protected]', | ||
role: 'admin', | ||
address: '', | ||
phone: '', | ||
position: '', | ||
} | ||
component.contact = mockContact | ||
fixture.detectChanges() | ||
expect(component.contact).toEqual(mockContact) | ||
}) | ||
|
||
it('should have a defined organization input', () => { | ||
const mockOrganization: Organization = { | ||
name: 'Org1', | ||
} | ||
component.organization = mockOrganization | ||
fixture.detectChanges() | ||
expect(component.organization).toEqual(mockOrganization) | ||
}) | ||
|
||
it('should emit contactRemoved event with the correct contact', () => { | ||
const mockContact: Individual = { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
organization: { name: 'Org1' } as Organization, | ||
email: '[email protected]', | ||
role: 'admin', | ||
address: '', | ||
phone: '', | ||
position: '', | ||
} | ||
component.contact = mockContact | ||
|
||
const contactRemovedSpy = jest.spyOn(component.contactRemoved, 'emit') | ||
component.removeContact(mockContact) | ||
expect(contactRemovedSpy).toHaveBeenCalledWith(mockContact) | ||
}) | ||
}) |
54 changes: 54 additions & 0 deletions
54
libs/feature/editor/src/lib/components/contact-card/contact-card.component.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
applicationConfig, | ||
componentWrapperDecorator, | ||
Meta, | ||
moduleMetadata, | ||
StoryObj, | ||
} from '@storybook/angular' | ||
import { ContactCardComponent } from './contact-card.component' | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations' | ||
import { importProvidersFrom } from '@angular/core' | ||
import { MatIconModule } from '@angular/material/icon' | ||
import { CommonModule } from '@angular/common' | ||
import { ButtonComponent } from '@geonetwork-ui/ui/inputs' | ||
|
||
export default { | ||
title: 'Elements/ContactCardComponent', | ||
component: ContactCardComponent, | ||
decorators: [ | ||
moduleMetadata({ | ||
imports: [ | ||
CommonModule, | ||
MatIconModule, | ||
ButtonComponent, | ||
ContactCardComponent, | ||
], | ||
}), | ||
applicationConfig({ | ||
providers: [importProvidersFrom(BrowserAnimationsModule)], | ||
}), | ||
componentWrapperDecorator( | ||
(story) => `<div style="max-width: 400px; margin: auto;">${story}</div>` | ||
), | ||
], | ||
} as Meta<ContactCardComponent> | ||
|
||
export const Primary: StoryObj<ContactCardComponent> = { | ||
args: { | ||
contact: { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
organization: { | ||
name: 'Example Organization', | ||
}, | ||
email: '[email protected]', | ||
role: 'Developer', | ||
address: '123 Main St', | ||
phone: '123-456-7890', | ||
position: 'Senior Developer', | ||
}, | ||
organization: { | ||
name: 'Example Organization', | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
52 changes: 52 additions & 0 deletions
52
...rm-field/form-field-contacts-for-resource/form-field-contacts-for-resource.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<div class="flex flex-col gap-3"> | ||
<div class="flex flex-row flex-wrap gap-2" data-test="rolesToPick"> | ||
<ng-container *ngFor="let role of rolesToPick"> | ||
<gn-ui-button | ||
extraClass="px-2 py-1.5" | ||
(buttonClick)="addRoleToDisplay(role)" | ||
> | ||
<div class="flex flex-row gap-1 items-center"> | ||
<span class="text-primary text-[20px] leading-[0] font-bold pb-[5px]" | ||
>₊</span | ||
> | ||
<span class="font-bold" translate>{{ roleToLabel(role) }}</span> | ||
</div> | ||
</gn-ui-button> | ||
</ng-container> | ||
</div> | ||
<div | ||
class="mt-8" | ||
*ngIf="rolesToDisplay && rolesToDisplay.length > 0" | ||
data-test="displayedRoles" | ||
> | ||
<div | ||
*ngFor="let role of rolesToDisplay; let index = index; let isLast = last" | ||
class="flex flex-col gap-4" | ||
> | ||
<div class="flex flex-row justify-between"> | ||
<span class="font-bold text-base" translate>{{ | ||
roleToLabel(role) | ||
}}</span> | ||
</div> | ||
|
||
<gn-ui-autocomplete | ||
[placeholder]="'Choose a contact'" | ||
[action]="autoCompleteAction" | ||
(itemSelected)="addContact($event, role)" | ||
[displayWithFn]="displayWithFn" | ||
[minCharacterCount]="1" | ||
[clearOnSelection]="true" | ||
> | ||
</gn-ui-autocomplete> | ||
|
||
<ng-container *ngFor="let contact of getContactsByRole(role)"> | ||
<gn-ui-contact-card | ||
[contact]="contact" | ||
[organization]="getOrganizationByName(contact.organization.name)" | ||
(contactRemoved)="removeContact(index)" | ||
></gn-ui-contact-card> | ||
</ng-container> | ||
<hr class="border-t-[#D6D3D1] mt-4 mb-6" *ngIf="!isLast" /> | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.