Skip to content

Commit

Permalink
feat(editor): Simplify logic of formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Angi-Kinas committed Sep 7, 2023
1 parent 1e09348 commit d436483
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
28 changes: 16 additions & 12 deletions libs/ui/search/src/lib/record-table/record-table.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,25 @@
<div [title]="record.title" class="record-table-col text-16">
{{ record.title }}
</div>
<div class="flex items-center">
<div class="record-table-col text-16 basis-1/2">
<div
class="record-table-col flex items-center"
[title]="formats.join(', ')"
*ngIf="getRecordFormats(record) as formats"
>
<div class="text-16 basis-2/3">
<span
class="flex badge-btn text-sm text-white"
[style.background-color]="getBadgeColor(firstFormat(record))"
*ngIf="firstFormat(record)"
>{{ firstFormat(record) }}</span
class="badge-btn text-sm text-white mr-2"
[style.background-color]="getBadgeColor(formats[0])"
*ngIf="formats[0]"
>
{{ formats[0] }}
</span>
</div>
<div class="record-table-col text-16 basis-1/2">
<span
*ngIf="secondToLastFormat(record).length > 0"
[title]="secondToLastFormat(record).join(', ')"
>+ ({{ secondToLastFormat(record).length }})</span
>
<div
class="text-16 basis-1/3 flex-shrink-0"
*ngIf="formats.slice(1).length > 0"
>
<span>+ {{ formats.slice(1).length }}</span>
</div>
</div>
<div class="record-table-col flex items-center gap-2 text-16">
Expand Down
17 changes: 3 additions & 14 deletions libs/ui/search/src/lib/record-table/record-table.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,12 @@ describe('RecordTableComponent', () => {
])
})
})
describe('get the first format', () => {
it('returns the first format of the list', () => {
expect(component.firstFormat(DATASET_RECORDS[0])).toEqual('pdf')
})
})
describe('get the remaining formats', () => {
it('returns the first format of the list', () => {
expect(component.secondToLastFormat(DATASET_RECORDS[0])).toEqual([
'shp',
'geojson',
])
})
})
describe('get the badge color for given format', () => {
it('returns the color for its format', () => {
expect(
component.getBadgeColor(component.firstFormat(DATASET_RECORDS[0]))
component.getBadgeColor(
component.getRecordFormats(DATASET_RECORDS[0])[0]
)
).toEqual('#db544a')
})
})
Expand Down
9 changes: 0 additions & 9 deletions libs/ui/search/src/lib/record-table/record-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,4 @@ export class RecordTableComponent {
getBadgeColor(format: FileFormat): string {
return getBadgeColor(format)
}

firstFormat(record: CatalogRecord): FileFormat {
return this.getRecordFormats(record)[0]
}

secondToLastFormat(record: CatalogRecord): FileFormat[] {
const formats = this.getRecordFormats(record)
return formats.slice(formats.length - 2)
}
}

0 comments on commit d436483

Please sign in to comment.