Skip to content

Commit

Permalink
Filtering on user ID in history tab
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Sep 17, 2023
1 parent f71aef4 commit a7d5492
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 4 deletions.
21 changes: 21 additions & 0 deletions backend/files/system/magic/ml_requests-count.get.hl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

// Endpoint counting items in your ml_requests table in your magic database
.arguments
filter:string
ml_requests.id.eq:long
ml_requests.created.eq:date
ml_requests.type.like:string
Expand All @@ -19,6 +20,26 @@ auth.ticket.verify:root

// Opening up our database connection.
data.connect:[generic|magic]

// Checking if user provided a [filter]
if
exists:x:@.arguments/*/filter
.lambda

// Adding filter and removing it from arguments collection.
strings.concat
.:%
get-value:x:@.arguments/*/filter
.:%
unwrap:x:+/*/*/*
add:x:@data.connect/*/data.read/*/where/*/and
.
or
ml_requests.prompt.like:x:@strings.concat
ml_requests.user_id.eq:x:@.arguments/*/filter
remove-nodes:x:@.arguments/*/filter

// Adding all other arguments.
add:x:+/*/where/*
get-nodes:x:@.arguments/*

Expand Down
19 changes: 19 additions & 0 deletions backend/files/system/magic/ml_requests.get.hl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
offset:long
order:string
direction:string
filter:string
ml_requests.id.eq:long
ml_requests.created.eq:date
ml_requests.type.like:string
Expand Down Expand Up @@ -38,6 +39,24 @@ data.connect:[generic|magic]
remove-nodes:x:@.arguments/*/limit
remove-nodes:x:@.arguments/*/offset

// Checking if user provided a [filter]
if
exists:x:@.arguments/*/filter
.lambda

// Adding filter and removing it from arguments collection.
strings.concat
.:%
get-value:x:@.arguments/*/filter
.:%
unwrap:x:+/*/*/*
add:x:@data.connect/*/data.read/*/where/*/and
.
or
ml_requests.prompt.like:x:@strings.concat
ml_requests.user_id.eq:x:@.arguments/*/filter
remove-nodes:x:@.arguments/*/filter

// Parametrising our read invocation with filtering arguments.
add:x:./*/data.read/*/where/*
get-nodes:x:@.arguments/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export class SearchboxComponent implements OnInit {
});
}

setSearchTerm(query: string) {

this.filterControl.setValue(query);
}

removeSearchTerm() {

this.filterControl.setValue('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ export class MachineLearningTrainingService {
const file = new Blob([res.body]);
saveAs(file, filename);
},
error: (error: any) => {
error: () => {

this.generalService.showFeedback(error?.error?.message ?? error, 'errorMessage');
this.generalService.showFeedback('No leads were found', 'errorMessage');
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h3 class="mb-2 fw-bold">Machine Learning history</h3>

<!-- Search textbox -->
<app-searchbox
#searchBox
(filterList)="filterList($event)"
buttonText="Export leads"
(buttonClick)="exportLeads()"
Expand Down Expand Up @@ -57,6 +58,31 @@ <h3 class="mb-2 fw-bold">Machine Learning history</h3>
</td>
</ng-container>

<!-- User ID column -->
<ng-container matColumnDef="user_id">
<th
mat-header-cell
*matHeaderCellDef
class="pe-sm-3 small-table-column text-nowrap"
mat-sort-header>
User ID
</th>
<td
mat-cell
*matCellDef="let element"
class="pe-sm-3 text-nowrap small-table-column">

<button
mat-button
color="primary"
style="width:100%;text-align:left;"
(click)="filterOnUserId($event, element.user_id)">
{{element.user_id}}
</button>

</td>
</ng-container>

<!-- Created column -->
<ng-container matColumnDef="created">
<th
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
* Copyright (c) Aista Ltd, and Thomas Hansen - For license inquiries you can contact thomas@ainiro.io.
*/

import { Component, OnInit } from '@angular/core';
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { PageEvent } from '@angular/material/paginator';
import { ConfirmationDialogComponent } from 'src/app/_general/components/confirmation-dialog/confirmation-dialog.component';
import { GeneralService } from 'src/app/_general/services/general.service';
import { MachineLearningTrainingService } from 'src/app/_general/services/machine-learning-training.service';
import { MachineLearningEditCacheComponent } from '../components/machine-learning-edit-cache/machine-learning-edit-cache.component';
import { SearchboxComponent } from 'src/app/_general/components/searchbox/searchbox.component';

/**
* Helper component to view and manage Machine Learning requests
Expand All @@ -28,6 +29,7 @@ export class MachineLearningRequestsComponent implements OnInit {
types: string[] = null;
displayedColumns: string[] = [
'prompt',
'user_id',
'type',
'created',
'finish_reason',
Expand All @@ -39,6 +41,7 @@ export class MachineLearningRequestsComponent implements OnInit {
order: 'created',
direction: 'desc',
};
@ViewChild('searchBox') searchBox: SearchboxComponent;

constructor(
private dialog: MatDialog,
Expand All @@ -50,6 +53,12 @@ export class MachineLearningRequestsComponent implements OnInit {
this.getTypes(true);
}

filterOnUserId(event:any, user: string) {

this.searchBox.setSearchTerm(user);
event.preventDefault();
}

filterList(event: { searchKey: string, type?: string }) {

const newFilter: any = {
Expand All @@ -64,7 +73,7 @@ export class MachineLearningRequestsComponent implements OnInit {
}
this.filter = newFilter;
if (event.searchKey) {
this.filter['ml_requests.prompt.like'] = '%' + event.searchKey + '%';
this.filter['filter'] = event.searchKey;
}
if (event.type) {
this.filter['ml_requests.type.eq'] = event.type;
Expand Down

0 comments on commit a7d5492

Please sign in to comment.