Skip to content

Commit

Permalink
fix: make save work again
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Dec 24, 2024
1 parent bf1d4aa commit 0fb05f5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ import { EditorFacade } from '@geonetwork-ui/feature/editor'
import { MatTooltipModule } from '@angular/material/tooltip'
import { TranslateModule, TranslateService } from '@ngx-translate/core'
import { combineLatest, Observable, of, Subject, Subscription } from 'rxjs'
import { catchError, first, map, skip, switchMap, take } from 'rxjs/operators'
import {
catchError,
concatMap,
distinctUntilChanged,
first,
map,
skip,
startWith,
switchMap,
take,
toArray,
} from 'rxjs/operators'
import { RecordsApiService } from '@geonetwork-ui/data-access/gn4'
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'
import {
Expand Down Expand Up @@ -153,18 +164,18 @@ export class PublishButtonComponent implements OnDestroy {
this.subscription.add(
this.facade.record$
.pipe(
switchMap((record) => {
take(1),
concatMap((record) => {
this.facade.checkHasRecordChanged(record)
return this.facade.hasRecordChanged$.pipe(
skip(1),
take(1),
catchError(() => of(null))
catchError(() => of({ user: undefined, date: undefined }))
)
}),
first()
})
)
.subscribe((hasChanged) => {
if (hasChanged !== null && hasChanged.date) {
console.log('Has Changed:', hasChanged)
if (hasChanged?.date) {
this.publishWarning = hasChanged
this.openConfirmationMenu()
} else {
Expand Down
63 changes: 33 additions & 30 deletions libs/api/repository/src/lib/gn4/gn4-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
switchMap,
throwError,
} from 'rxjs'
import { catchError, map, tap } from 'rxjs/operators'
import { catchError, map, startWith, tap } from 'rxjs/operators'
import { lt } from 'semver'
import { ElasticsearchService } from './elasticsearch'

Expand Down Expand Up @@ -366,36 +366,39 @@ export class Gn4Repository implements RecordsRepositoryInterface {
}

hasRecordChangedSinceDraft(localRecord: CatalogRecord) {
const isUnsaved = this.isRecordNotYetSaved(localRecord.uniqueIdentifier)
const hasDraft = this.recordHasDraft(localRecord.uniqueIdentifier)

if (isUnsaved || !hasDraft) {
return of(null)
}

return combineLatest([
this.getAllDrafts().pipe(
map((drafts) => {
const matchingRecord = drafts.find(
(draft) => draft.uniqueIdentifier === localRecord.uniqueIdentifier
)
return matchingRecord ? matchingRecord.recordUpdated : null
})
),
this.getRecord(localRecord.uniqueIdentifier),
]).pipe(
map(([draftRecordUpdated, recentRecord]) => {
if (recentRecord.recordUpdated > draftRecordUpdated) {
const user = recentRecord.extras?.['ownerInfo'].toString().split('|')
return {
user: `${user[2]} ${user[1]}`,
date: recentRecord.recordUpdated,
}
}
return {
user: undefined,
date: undefined,
return of({
isUnsaved: this.isRecordNotYetSaved(localRecord.uniqueIdentifier),
hasDraft: this.recordHasDraft(localRecord.uniqueIdentifier),
}).pipe(
switchMap(({ isUnsaved, hasDraft }) => {
if (isUnsaved || !hasDraft) {
return of({ user: undefined, date: undefined })
}
return combineLatest([
this.getAllDrafts().pipe(
map((drafts) => {
const matchingRecord = drafts.find(
(draft) =>
draft.uniqueIdentifier === localRecord.uniqueIdentifier
)
return matchingRecord?.recordUpdated || null
})
),
this.getRecord(localRecord.uniqueIdentifier),
]).pipe(
map(([draftRecordUpdated, recentRecord]) => {
if (recentRecord?.recordUpdated > draftRecordUpdated) {
const user = recentRecord.extras?.['ownerInfo']
?.toString()
?.split('|')
return {
user: `${user[2]} ${user[1]}`,
date: recentRecord.recordUpdated,
}
}
return { user: undefined, date: undefined }
})
)
})
)
}
Expand Down

0 comments on commit 0fb05f5

Please sign in to comment.