Skip to content

Commit

Permalink
feat(): add delete mix db
Browse files Browse the repository at this point in the history
  • Loading branch information
develite98 committed Sep 16, 2023
1 parent e8784bd commit f2c36da
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
[rowSelection]="'multiple'"
[suppressMoveWhenRowDragging]="true"
(gridReady)="onGridReady($event)"
(selectionChanged)="onSelectionChanged()"
style="width: 100%; height: 100%">
</ag-grid-angular>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { TuiReorderModule, TuiTableModule } from '@taiga-ui/addon-table';
import { TuiDestroyService } from '@taiga-ui/cdk';
import { TuiCheckboxModule, TuiPaginationModule } from '@taiga-ui/kit';
import { AgGridModule } from 'ag-grid-angular';
import { ColDef, GridReadyEvent } from 'ag-grid-community';
import { ColDef, GridApi, GridReadyEvent } from 'ag-grid-community';
import {
Observable,
Subject,
Expand Down Expand Up @@ -136,8 +136,10 @@ export class DatabaseDataComponent
public columnNames: string[] = [];
public displayColumns: string[] = [];
public displayColumns$ = new Subject<string[]>();
public gridApi!: GridApi<MixDynamicData>;

onGridReady(params: GridReadyEvent) {
public onGridReady(params: GridReadyEvent) {
this.gridApi = params.api;
this.rowData$ = this.store.vm$.pipe(
filter((s) => s.status === 'Success'),
tap((s) => {
Expand All @@ -164,14 +166,19 @@ export class DatabaseDataComponent
];
}
}),
map((s) => s.data)
map((s) => s.data),
takeUntil(this.destroy$)
);

this.displayColumns$
.pipe(distinctUntilChanged(), debounceTime(0))
.subscribe((v) => this.reUpdateColumnDef());
}

public onSelectionChanged() {
this.selectedItems = this.gridApi.getSelectedRows();
}

public actions = [
{
label: 'Insert',
Expand Down Expand Up @@ -238,11 +245,16 @@ export class DatabaseDataComponent
this.mixApi.databaseApi.deleteData(this.dbSysName, d.id!)
);

forkJoin(requests).subscribe({
next: () => {
this.modal.success('Successfully delete your data').subscribe();
},
});
forkJoin(requests)
.pipe(toastObserverProcessing(this.toast))
.subscribe({
next: () => {
this.modal.success('Successfully delete your data').subscribe();
this.store.removeData(selectedData.map((x) => x.id!));
this.selectedItems = [];
this.gridApi.deselectAll();
},
});
});
}

Expand Down
7 changes: 7 additions & 0 deletions apps/mix-cms/src/app/stores/database-data.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,11 @@ export class DatabaseDataStore extends ComponentStore<DatabaseDataState> {
data: [...s.data, data],
}));
}

public removeData(dataId: number[]) {
this.patchState((s) => ({
...s,
data: s.data.filter((x) => !dataId.includes(x.id!)),
}));
}
}

1 comment on commit f2c36da

@vercel
Copy link

@vercel vercel bot commented on f2c36da Sep 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.