Skip to content

Commit

Permalink
Merge branch 'develop' into ME-checkbox-for-rcords-table
Browse files Browse the repository at this point in the history
  • Loading branch information
Angi-Kinas authored Oct 25, 2023
2 parents 41fe63b + a12b13c commit b0b387c
Show file tree
Hide file tree
Showing 50 changed files with 1,207 additions and 194 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
branches:
- main
- develop
release:
types: [published]
issue_comment:
Expand All @@ -20,7 +21,7 @@ concurrency:
env:
NODE_VERSION: 18.16.1
# a list of apps to build and publish on releases
APP_NAMES: datafeeder,datahub
APP_NAMES: datafeeder,datahub,metadata-editor

jobs:
checks:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ run-name: 🧹 Cleanup operations for 🌱 ${{github.event.ref}}

env:
# a list of apps to build and publish on releases
APP_NAMES: datafeeder,datahub
APP_NAMES: datafeeder,datahub,metadata-editor

on:
delete:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2 class="text-xl mr-4 font-title" translate>
></gn-ui-filter-dropdown>
<div
class="spatial-filter-toggle sm:col-span-2"
*ngIf="isOpen && searchFacade.hasSpatialFilter$ | async"
*ngIf="isOpen && (searchFacade.hasSpatialFilter$ | async)"
>
<gn-ui-check-toggle
[title]="'search.filters.useSpatialFilterHelp' | translate"
Expand All @@ -63,6 +63,30 @@ <h2 class="text-xl mr-4 font-title" translate>
(toggled)="toggleSpatialFilter($event)"
></gn-ui-check-toggle>
</div>
<div class="sm:col-span-2" *ngIf="userId && isOpen">
<gn-ui-check-toggle
[title]="'search.filters.myRecordsHelp' | translate"
[label]="'search.filters.myRecords' | translate"
[color]="'secondary'"
[value]="myRecordsFilterEnabled$ | async"
(toggled)="toggleMyRecordsFilter($event)"
></gn-ui-check-toggle>
</div>
<div
class="sm:col-span-2"
*ngIf="!userId && (myRecordsFilterEnabled$ | async) && isOpen"
>
<gn-ui-button
type="light"
extraClass="text-sm align-middle"
(buttonClick)="toggleMyRecordsFilter(false)"
>
<span>{{ 'search.filters.otherRecords' | translate }}</span>
<mat-icon class="material-symbols-outlined ml-3 opacity-40"
>close</mat-icon
>
</gn-ui-button>
</div>
</div>
<div
class="col-span-2 flex flex-col justify-between"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import { SearchFiltersComponent } from './search-filters.component'
import { TranslateModule } from '@ngx-translate/core'
import { By } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import {
AggregationsTypes,
FieldFilters,
} from '@geonetwork-ui/common/domain/search'
import { FieldFilters } from '@geonetwork-ui/common/domain/search'
import { USER_FIXTURE } from '@geonetwork-ui/common/fixtures'
import { AuthService } from '@geonetwork-ui/api/repository/gn4'

jest.mock('@geonetwork-ui/util/app-config', () => ({
getOptionalSearchConfig: () => ({
Expand Down Expand Up @@ -67,6 +66,7 @@ export class MockFilterDropdownComponent {
@Input() title: string
}
const state = { OrgForResource: { mel: true } } as FieldFilters
const user = USER_FIXTURE()
class SearchFacadeMock {
searchFilters$ = new BehaviorSubject(state)
hasSpatialFilter$ = new BehaviorSubject(false)
Expand Down Expand Up @@ -103,6 +103,12 @@ class FieldsServiceMock {
}
}

class AuthServiceMock {
user$ = new BehaviorSubject(user)
authReady = jest.fn(() => this._authSubject$)
_authSubject$ = new BehaviorSubject({})
}

describe('SearchFiltersComponent', () => {
let component: SearchFiltersComponent
let fixture: ComponentFixture<SearchFiltersComponent>
Expand Down Expand Up @@ -131,6 +137,10 @@ describe('SearchFiltersComponent', () => {
provide: FieldsService,
useClass: FieldsServiceMock,
},
{
provide: AuthService,
useClass: AuthServiceMock,
},
],
})
.overrideComponent(SearchFiltersComponent, {
Expand All @@ -155,7 +165,9 @@ describe('SearchFiltersComponent', () => {

describe('spatial filter button', () => {
function getCheckToggleDebugElement() {
return fixture.debugElement.query(By.directive(MockCheckToggleComponent))
return fixture.debugElement.queryAll(
By.directive(MockCheckToggleComponent)
)
}

describe('when panel is closed', () => {
Expand All @@ -164,7 +176,7 @@ describe('SearchFiltersComponent', () => {
fixture.detectChanges()
})
it('does not show up', () => {
expect(getCheckToggleDebugElement()).toBeFalsy()
expect(getCheckToggleDebugElement().length).toBeFalsy()
})
})
describe('when panel is opened & a spatial filter is unavailable', () => {
Expand All @@ -174,7 +186,7 @@ describe('SearchFiltersComponent', () => {
fixture.detectChanges()
})
it('does not show up', () => {
expect(getCheckToggleDebugElement()).toBeFalsy()
expect(getCheckToggleDebugElement().length).toBe(1)
})
})
describe('when panel is opened & a spatial filter is available', () => {
Expand All @@ -185,11 +197,11 @@ describe('SearchFiltersComponent', () => {
fixture.detectChanges()
})
it('does show up', () => {
expect(getCheckToggleDebugElement()).toBeTruthy()
expect(getCheckToggleDebugElement().length).toBe(2)
})
it('has the value set in the state', () => {
expect(
getCheckToggleDebugElement().componentInstance.value
getCheckToggleDebugElement()[0].componentInstance.value
).toBeTruthy()
})
})
Expand All @@ -201,7 +213,7 @@ describe('SearchFiltersComponent', () => {
})
it('emits a SetSpatialFilterEnabled action', () => {
const checkToggleComponent =
getCheckToggleDebugElement().componentInstance
getCheckToggleDebugElement()[0].componentInstance
checkToggleComponent.toggled.emit(false)
expect(searchFacade.setSpatialFilterEnabled).toHaveBeenCalledWith(false)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import {
QueryList,
ViewChildren,
} from '@angular/core'
import { AuthService } from '@geonetwork-ui/api/repository/gn4'
import {
FieldsService,
FilterDropdownComponent,
SearchFacade,
SearchService,
} from '@geonetwork-ui/feature/search'
import { getOptionalSearchConfig } from '@geonetwork-ui/util/app-config'
import { Observable, switchMap } from 'rxjs'
import { map } from 'rxjs/operators'

@Component({
selector: 'datahub-search-filters',
Expand All @@ -24,14 +27,28 @@ export class SearchFiltersComponent implements OnInit {
filters: QueryList<FilterDropdownComponent>
searchConfig: { fieldName: string; title: string }[]
isOpen = false
userId: string
myRecordsFilterEnabled$: Observable<boolean> =
this.searchFacade.searchFilters$.pipe(
switchMap((filters) => {
return this.fieldsService.readFieldValuesFromFilters(filters)
}),
map((fieldValues) =>
fieldValues['owner'] && Array.isArray(fieldValues['owner'])
? fieldValues['owner'].length > 0
: !!fieldValues['owner']
)
)

constructor(
public searchFacade: SearchFacade,
private searchService: SearchService,
private fieldsService: FieldsService
private fieldsService: FieldsService,
private authService: AuthService
) {}

ngOnInit(): void {
this.authService.user$.subscribe((user) => (this.userId = user?.id))
this.searchConfig = (
getOptionalSearchConfig().ADVANCED_FILTERS || [
'publisher',
Expand Down Expand Up @@ -70,6 +87,12 @@ export class SearchFiltersComponent implements OnInit {
this.searchFacade.setSpatialFilterEnabled(enabled)
}

toggleMyRecordsFilter(enabled: boolean) {
this.fieldsService
.buildFiltersFromFieldValues({ owner: enabled ? this.userId : [] })
.subscribe((filters) => this.searchService.updateFilters(filters))
}

clearFilters() {
const fieldNames = this.filters.map((component) => component.fieldName)
const fieldValues = fieldNames.reduce(
Expand Down
44 changes: 44 additions & 0 deletions apps/metadata-editor-e2e/src/e2e/my-org.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
describe('my-org', () => {
beforeEach(() => {
cy.loginGN('barbie', 'p4ssworD_', false)
cy.visit(`/records/my-org`)
cy.get('md-editor-dashboard-menu').find('a').first().click()
cy.get('main').children('div').first().children('div').eq(1).as('linkGroup')
})
describe('my-org display', () => {
it('should show my-org name and logo', () => {
cy.get('h1').should('not.have.text', '')
cy.get('gn-ui-thumbnail')
})
it('should show the user and record count', () => {
cy.get('@linkGroup')
.find('a')
.children('span')
.first()
.should('not.have.text', '')
cy.get('@linkGroup')
.find('gn-ui-button')
.children('span')
.first()
.should('not.have.text', '')
})
it('should show my-org records', () => {
cy.get('.grid').should('have.length.above', 0)
})
})
describe('routing', () => {
it('should access the datahub with a filter', () => {
cy.get('@linkGroup').find('a').click()
cy.url().should('include', 'search/publisher=')
})
it('should access the user list page and show my-org users', () => {
cy.visit(`/records/my-org`)
cy.get('md-editor-dashboard-menu').find('a').first().click()
cy.get('@linkGroup').find('gn-ui-button').click()
cy.url().should('include', '/users/my-org')
cy.get('.grid').should('have.length.above', 0)
cy.get('h1').should('not.have.text', '')
cy.get('gn-ui-thumbnail')
})
})
})
10 changes: 10 additions & 0 deletions apps/metadata-editor/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@
"jestConfig": "apps/metadata-editor/jest.config.ts",
"passWithNoTests": true
}
},
"docker-build": {
"executor": "nx:run-commands",
"options": {
"commands": [
"nx build metadata-editor --base-href='/metadata-editor/'",
"docker build --build-arg APP_NAME=metadata-editor -f ./tools/docker/Dockerfile.apps . -t $(tools/print-docker-tag.sh metadata-editor)"
],
"parallel": false
}
}
},
"tags": ["type:app"]
Expand Down
5 changes: 5 additions & 0 deletions apps/metadata-editor/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MyRecordsComponent } from './records/my-records/my-records.component'
import { MyDraftComponent } from './records/my-draft/my-draft.component'
import { MyLibraryComponent } from './records/my-library/my-library.component'
import { SearchRecordsComponent } from './records/search-records/search-records-list.component'
import { MyOrgUsersComponent } from './my-org-users/my-org-users.component'

export const appRoutes: Route[] = [
{ path: '', component: DashboardPageComponent, pathMatch: 'prefix' },
Expand Down Expand Up @@ -61,6 +62,10 @@ export const appRoutes: Route[] = [
},
],
},
{
path: 'users/my-org',
component: MyOrgUsersComponent,
},
{ path: 'sign-in', component: SignInPageComponent },
{ path: 'create', component: CreatePageComponent },
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.record-table-col {
@apply px-5 py-3 items-center truncate;
}

.record-table-header {
@apply record-table-col capitalize;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<md-editor-records-list
[users]="orgData.userList"
[logo]="orgData.logoUrl"
[title]="orgData.orgName"
>
</md-editor-records-list>
Loading

0 comments on commit b0b387c

Please sign in to comment.