Skip to content

Commit

Permalink
feat(editor): simplify canDuplicate canDelete resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
LHBruneton-C2C committed Aug 14, 2024
1 parent 7c2c71c commit b046109
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ <h1 class="text-[16px] text-main font-title font-bold" translate>
>
<gn-ui-results-table
[records]="records$ | async"
[isDraft]="isDraft"
[isDraftWithoutRecord]="isDraftIdTemporary"
[canDuplicate]="canDuplicate"
[canDelete]="canDelete"
(recordClick)="editRecord($event)"
(deleteRecord)="deleteDraft($event)"
></gn-ui-results-table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export class MyDraftComponent {
startWith([])
)
hasDraft = () => true
isDraft = () => true
isDraftIdTemporary = (record: CatalogRecord): boolean =>
this.recordsRepository.isDraftIdTemporary(record.uniqueIdentifier)
canDuplicate = (): boolean => false
canDelete = (record: CatalogRecord): boolean =>
this.recordsRepository.isRecordNotYetSaved(record.uniqueIdentifier)

constructor(
private router: Router,
Expand Down
4 changes: 2 additions & 2 deletions libs/api/repository/src/lib/gn4/gn4-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ export class Gn4Repository implements RecordsRepositoryInterface {
)
}

isDraftIdTemporary(uniqueIdentifier: string): boolean {
return uniqueIdentifier.startsWith('TEMP-ID-')
isRecordNotYetSaved(uniqueIdentifier: string): boolean {
return uniqueIdentifier.startsWith(TEMPORARY_ID_PREFIX)
}

// generated by copilot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export abstract class RecordsRepositoryInterface {
abstract deleteRecord(uniqueIdentifier: string): Observable<void>

abstract generateTemporaryId(): string

/**
* @param record
* @param referenceRecordSource
Expand All @@ -71,7 +72,7 @@ export abstract class RecordsRepositoryInterface {

abstract clearRecordDraft(uniqueIdentifier: string): void
abstract recordHasDraft(uniqueIdentifier: string): boolean
abstract isDraftIdTemporary(uniqueIdentifier: string): boolean
abstract isRecordNotYetSaved(uniqueIdentifier: string): boolean

/** will return all pending drafts, both published and not published */
abstract getAllDrafts(): Observable<CatalogRecord[]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<div class="flex flex-row items-center gap-2 max-w-full">
<span class="overflow-hidden text-ellipsis">{{ item.title }}</span>
<gn-ui-badge
*ngIf="hasDraft(item) || isDraft(item)"
*ngIf="hasDraft(item)"
[style.--gn-ui-badge-padding]="'0.4em 0.6em'"
[style.--gn-ui-badge-text-color]="'#3d2006'"
[style.--gn-ui-badge-background-color]="'#ffbc7b'"
Expand Down Expand Up @@ -126,8 +126,8 @@
<ng-template #header> </ng-template>
<ng-template #cell let-item>
<gn-ui-action-menu
[canDuplicate]="!isDraft(item)"
[canDelete]="isDraftWithoutRecord(item) || !isDraft(item)"
[canDuplicate]="canDuplicate(item)"
[canDelete]="canDelete(item)"
(duplicate)="handleDuplicate(item)"
(delete)="handleDelete(item)"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ export class ResultsTableComponent {
@Input() selectedRecordsIdentifiers: string[] = []
@Input() sortOrder: SortByField = null
@Input() hasDraft: (record: CatalogRecord) => boolean = () => false
@Input() isDraft: (record: CatalogRecord) => boolean = () => false
@Input() isDraftWithoutRecord: (record: CatalogRecord) => boolean = () =>
false
@Input() canDuplicate: (record: CatalogRecord) => boolean = () => true
@Input() canDelete: (record: CatalogRecord) => boolean = () => true

// emits the column (field) as well as the order
@Output() sortByChange = new EventEmitter<[string, 'asc' | 'desc']>()
Expand Down

0 comments on commit b046109

Please sign in to comment.