Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dh): add include related filter to message archive #3592

Merged
merged 12 commits into from
Oct 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ type Query {
gridAreas: [GridAreaDto!]!
imbalancePricesOverview: ImbalancePricesOverview!
imbalancePricesForMonth(year: Int! month: Int! areaCode: PriceAreaCode!): [ImbalancePriceDaily!]!
archivedMessages(created: DateRange! senderNumber: String receiverNumber: String documentTypes: [DocumentType!] businessReasons: [BusinessReason!] filter: String "Returns the first _n_ elements from the list." first: Int "Returns the elements in the list that come after the specified cursor." after: String "Returns the last _n_ elements from the list." last: Int "Returns the elements in the list that come before the specified cursor." before: String order: [ArchivedMessageSortInput!]): ArchivedMessagesConnection
archivedMessages(created: DateRange! senderNumber: String receiverNumber: String documentTypes: [DocumentType!] businessReasons: [BusinessReason!] includeRelated: Boolean filter: String "Returns the first _n_ elements from the list." first: Int "Returns the elements in the list that come after the specified cursor." after: String "Returns the last _n_ elements from the list." last: Int "Returns the elements in the list that come before the specified cursor." before: String order: [ArchivedMessageSortInput!]): ArchivedMessagesConnection
organizationAuditLogs(organizationId: UUID!): [OrganizationAuditedChangeAuditLogDto!]!
organizationById(id: UUID!): Organization!
organizations: [Organization!]!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ public async Task<IEnumerable<ArchivedMessageResult>> GetArchivedMessagesAsync(
string? receiverNumber,
DocumentType[]? documentTypes,
BusinessReason[]? businessReasons,
bool? includeRelated,
string? filter,
[Service] IEdiB2CWebAppClient_V1 client)
{
var search = !string.IsNullOrWhiteSpace(filter)
? new SearchArchivedMessagesCriteria() { MessageId = filter, IncludeRelatedMessages = true }
? new SearchArchivedMessagesCriteria()
{
MessageId = filter,
IncludeRelatedMessages = includeRelated ?? false,
}
: new SearchArchivedMessagesCriteria()
{
CreatedDuringPeriod = new MessageCreationPeriod()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@
"new": "Ny søgning",
"results": "Resultater",
"searchById": "Søg på ID",
"filters": {
"includeRelated": "Inkluder relaterede"
},
"drawer": {
"message": "Besked",
"sender": "Afsender",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@
"new": "New search",
"results": "Results",
"searchById": "Search by ID",
"filters": {
"includeRelated": "Include related"
},
"drawer": {
"message": "Message",
"receiver": "Receiver",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ query GetArchivedMessages(
$receiverNumber: String
$documentTypes: [DocumentType!]
$businessReasons: [BusinessReason!]
$includeRelated: Boolean
$first: Int
$last: Int
$after: String
Expand All @@ -17,6 +18,7 @@ query GetArchivedMessages(
receiverNumber: $receiverNumber
documentTypes: $documentTypes
businessReasons: $businessReasons
includeRelated: $includeRelated
first: $first
last: $last
after: $after
Expand Down
44 changes: 39 additions & 5 deletions libs/dh/message-archive/feature-search/src/lib/table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, output, signal } from '@angular/core';
import { Component, OnInit, output, signal, viewChild } from '@angular/core';
import { TranslocoDirective } from '@ngneat/transloco';

import { VaterUtilityDirective } from '@energinet-datahub/watt/vater';
import { WattButtonComponent } from '@energinet-datahub/watt/button';
import { WattDataTableComponent } from '@energinet-datahub/watt/data';
import { WattDataTableComponent, WattDataFiltersComponent } from '@energinet-datahub/watt/data';
import { WattDatePipe } from '@energinet-datahub/watt/date';
import { WattEmptyStateComponent } from '@energinet-datahub/watt/empty-state';
import { WattTableColumnDef, WATT_TABLE } from '@energinet-datahub/watt/table';
Expand All @@ -30,18 +30,28 @@ import {
} from '@energinet-datahub/dh/shared/domain/graphql';
import { GetArchivedMessagesDataSource } from '@energinet-datahub/dh/shared/domain/graphql/data-source';
import { ArchivedMessage } from '@energinet-datahub/dh/message-archive/domain';
import { WattFilterChipComponent } from '@energinet-datahub/watt/chip';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { WattFormChipDirective } from '@energinet-datahub/watt/field';

type Variables = Partial<GetArchivedMessagesQueryVariables>;

@Component({
selector: 'dh-message-archive-search-table',
standalone: true,
imports: [
ReactiveFormsModule,
TranslocoDirective,
VaterUtilityDirective,
WATT_TABLE,
WattButtonComponent,
WattDataFiltersComponent,
WattDataTableComponent,
WattDatePipe,
WattEmptyStateComponent,
WattFilterChipComponent,
WattFormChipDirective,
],
template: `
<watt-data-table
Expand All @@ -57,6 +67,15 @@ import { ArchivedMessage } from '@energinet-datahub/dh/message-archive/domain';
<watt-button variant="secondary" icon="plus" (click)="new.emit()">
{{ t('new') }}
</watt-button>
@if (dataSource.filter) {
<watt-data-filters>
<form [formGroup]="form">
<watt-filter-chip [formControl]="this.form.controls.includeRelated">
{{ t('filters.includeRelated') }}
</watt-filter-chip>
</form>
</watt-data-filters>
}
<watt-table
*transloco="let resolveHeader; read: 'messageArchive.columns'"
#table
Expand Down Expand Up @@ -92,10 +111,13 @@ import { ArchivedMessage } from '@energinet-datahub/dh/message-archive/domain';
</watt-data-table>
`,
})
export class DhMessageArchiveSearchTableComponent {
export class DhMessageArchiveSearchTableComponent implements OnInit {
new = output();
open = output<ArchivedMessage>();
selection = signal<ArchivedMessage | undefined>(undefined);
dataTable = viewChild.required(WattDataTableComponent);
form = new FormGroup({ includeRelated: new FormControl(false) });
filterChanges = this.form.valueChanges.pipe(takeUntilDestroyed());
mimse marked this conversation as resolved.
Show resolved Hide resolved

columns: WattTableColumnDef<ArchivedMessage> = {
messageId: { accessor: 'messageId' },
Expand All @@ -113,10 +135,22 @@ export class DhMessageArchiveSearchTableComponent {
},
});

fetch = (variables: GetArchivedMessagesQueryVariables) => this.dataSource.refetch(variables);
reset = () => this.dataSource.reset();
ngOnInit() {
this.filterChanges.subscribe((variables) => this.dataSource.refetch(variables));
}

clearSelection = () => this.selection.set(undefined);

fetch = (variables: Variables) => {
this.dataTable().reset();
this.dataSource.refetch(variables);
};

reset = () => {
this.dataTable().reset();
this.dataSource.reset();
};

onRowClick = (row: ArchivedMessage) => {
this.selection.set(row);
this.open.emit(row);
Expand Down
4 changes: 2 additions & 2 deletions libs/dh/shared/util-apollo/src/lib/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class ApolloDataSource<TResult, TVariables extends ConnectionVariables, T
{
private _query: QueryResult<TResult, TVariables>;
private _connection: Observable<Connection<TNode>>;
private _inputChange: ReplaySubject<TVariables | undefined> = new ReplaySubject(1);
private _inputChange: ReplaySubject<Partial<TVariables> | undefined> = new ReplaySubject(1);
private _subscription?: Subscription;

private _totalCount = signal(0);
Expand Down Expand Up @@ -125,7 +125,7 @@ export class ApolloDataSource<TResult, TVariables extends ConnectionVariables, T
if (!options?.skip) this._inputChange.next(options?.variables);
}

refetch = (variables?: TVariables) => this._inputChange.next(variables);
refetch = (variables?: Partial<TVariables>) => this._inputChange.next(variables);
subscribeToMore: QueryResult<TResult, TVariables>['subscribeToMore'] = (options) =>
this._query.subscribeToMore(options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class WattFilterChipComponent<T = string> {
isFirstRender = useIsFirstRender();

onChange(input: HTMLInputElement): void {
this.selectionChange.emit(input.value as T);
const value = this.choice ? input.value : input.checked;
this.selectionChange.emit(value as T);
}
}
13 changes: 12 additions & 1 deletion libs/watt/src/lib/components/data/watt-data-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, ViewEncapsulation, contentChild, inject, input, output } from '@angular/core';
import {
Component,
ViewEncapsulation,
contentChild,
inject,
input,
output,
viewChild,
} from '@angular/core';

import {
VaterFlexComponent,
Expand Down Expand Up @@ -127,6 +135,9 @@ export class WattDataTableComponent {

table = contentChild.required(WattTableComponent<unknown>, { descendants: true });

search = viewChild(WattSearchComponent);
reset = () => this.search()?.clear();

onSearch(value: string) {
this.table().dataSource.filter = value;
if (!value) this.clear.emit();
Expand Down
Loading