Skip to content

Commit

Permalink
Merge branch 'master' into new-sdk-release
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-trajanovski authored Nov 29, 2024
2 parents 71cf7b8 + 27eb0ad commit 6da7a82
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 13 deletions.
51 changes: 51 additions & 0 deletions cypress/e2e/datasets/datasets-general.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,55 @@ describe("Datasets general", () => {
cy.deleteProposal(proposalId);
});
});

describe.only("Dataset page filter and scientific condition UI test", () => {
it("should not be able to add duplicated conditions ", () => {
cy.visit("/datasets");

cy.get(".user-button").click();

cy.get("[data-cy=logout-button]").click();

cy.finishedLoading();

cy.visit("/datasets");

cy.get('[data-cy="more-filters-button"]').click();

cy.get('[data-cy="add-scientific-condition-button"]').click();

cy.get('input[name="lhs"]').type("test");
cy.get('input[name="rhs"]').type("1");

cy.get('button[type="submit"]').click();

cy.get('[data-cy="add-scientific-condition-button"]').click();

cy.get('input[name="lhs"]').type("test");
cy.get('input[name="rhs"]').type("1");

cy.get('button[type="submit"]').click();

cy.get(".snackbar-warning")
.should("contain", "Condition already exists")
.contains("Close")
.click();

cy.get('[data-cy="scientific-condition-filter-list"').should(
"have.length",
1,
);

cy.get('[data-cy="add-scientific-condition-button"]').click();

cy.get('input[name="lhs"]').type("test");
cy.get('input[name="rhs"]').type("2");

cy.get('button[type="submit"]').click();

cy.get('[data-cy="scientific-condition-filter-list"]')
.find("input")
.should("have.length", 2);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
</ng-container>
</ng-container>

<div class="section-container" *ngIf="appConfig.scienceSearchEnabled">
<div
class="section-container"
*ngIf="appConfig.scienceSearchEnabled"
data-cy="scientific-condition-filter-list"
>
<ng-container *ngFor="let condition of scientificConditions$ | async">
<ng-container
*ngComponentOutlet="ConditionFilterComponent; inputs: { condition }"
></ng-container>
</ng-container>
</div>

<div class="section-container">
<div class="section-container" data-cy="more-filters-button">
<button
mat-button
class="full-width-button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ <h2 mat-dialog-title>Configure Filters</h2>
color="primary"
*ngIf="appConfig.scienceSearchEnabled"
(click)="addCondition()"
data-cy="add-scientific-condition-button"
>
<mat-icon>add</mat-icon>
Add Conditions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { MatIconModule } from "@angular/material/icon";
import { AppConfigService } from "app-config.service";
import { DatasetsFilterSettingsComponent } from "./datasets-filter-settings.component";
import { ConditionConfig } from "../../../shared/modules/filters/filters.module";
import { MatSnackBar, MatSnackBarModule } from "@angular/material/snack-bar";

export class MockMatDialog {
open() {
Expand Down Expand Up @@ -82,6 +83,7 @@ describe("DatasetsFilterSettingsComponent", () => {
MatSelectModule,
MatNativeDateModule,
ReactiveFormsModule,
MatSnackBarModule,
SharedScicatFrontendModule,
StoreModule.forRoot({}),
],
Expand All @@ -96,6 +98,7 @@ describe("DatasetsFilterSettingsComponent", () => {
providers: [
{ provide: AppConfigService, useValue: { getConfig } },
{ provide: MatDialog, useClass: MockMatDialog },
{ provide: MatSnackBar },
{ provide: MatDialogRef, useClass: MockMatDialogRef },
{
provide: MAT_DIALOG_DATA,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Inject } from "@angular/core";
import { Component, Inject } from "@angular/core";
import {
MAT_DIALOG_DATA,
MatDialog,
Expand All @@ -22,12 +22,13 @@ import {
ConditionConfig,
FilterConfig,
} from "../../../shared/modules/filters/filters.module";
import { isEqual } from "lodash-es";
import { MatSnackBar } from "@angular/material/snack-bar";

@Component({
selector: "app-type-datasets-filter-settings",
templateUrl: `./datasets-filter-settings.component.html`,
styleUrls: [`./datasets-filter-settings.component.scss`],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DatasetsFilterSettingsComponent {
metadataKeys$ = this.store.select(selectMetadataKeys);
Expand All @@ -39,6 +40,7 @@ export class DatasetsFilterSettingsComponent {
constructor(
public dialogRef: MatDialogRef<DatasetsFilterSettingsComponent>,
public dialog: MatDialog,
private snackBar: MatSnackBar,
private store: Store,
private asyncPipe: AsyncPipe,
private appConfigService: AppConfigService,
Expand All @@ -56,6 +58,18 @@ export class DatasetsFilterSettingsComponent {
.subscribe((res) => {
if (res) {
const { data } = res;

// If the condition already exists, do nothing
const existingConditionIndex = this.data.conditionConfigs.findIndex(
(config) => isEqual(config.condition, data),
);
if (existingConditionIndex !== -1) {
this.snackBar.open("Condition already exists", "Close", {
duration: 2000,
panelClass: ["snackbar-warning"],
});
return;
}
const condition = this.toggleCondition({
condition: data,
enabled: false,
Expand All @@ -66,15 +80,6 @@ export class DatasetsFilterSettingsComponent {
}

editCondition(condition: ConditionConfig, i: number) {
this.store.dispatch(
removeScientificConditionAction({ condition: condition.condition }),
);
this.store.dispatch(
deselectColumnAction({
name: condition.condition.lhs,
columnType: "custom",
}),
);
this.dialog
.open(SearchParametersDialogComponent, {
data: {
Expand All @@ -86,6 +91,24 @@ export class DatasetsFilterSettingsComponent {
.subscribe((res) => {
if (res) {
const { data } = res;

// If the condition is unchanged, do nothing
if (isEqual(condition.condition, data)) {
return;
}

this.store.dispatch(
removeScientificConditionAction({
condition: condition.condition,
}),
);
this.store.dispatch(
deselectColumnAction({
name: condition.condition.lhs,
columnType: "custom",
}),
);

this.data.conditionConfigs[i] = {
...condition,
condition: data,
Expand Down
2 changes: 2 additions & 0 deletions src/app/datasets/datasets.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import { DatasetsFilterSettingsComponent } from "./datasets-filter/settings/data
import { CdkDrag, CdkDragHandle, CdkDropList } from "@angular/cdk/drag-drop";
import { FiltersModule } from "shared/modules/filters/filters.module";
import { userReducer } from "state-management/reducers/user.reducer";
import { MatSnackBarModule } from "@angular/material/snack-bar";

@NgModule({
imports: [
Expand Down Expand Up @@ -121,6 +122,7 @@ import { userReducer } from "state-management/reducers/user.reducer";
MatStepperModule,
MatTableModule,
MatTabsModule,
MatSnackBarModule,
MatTooltipModule,
NgxJsonViewerModule,
ReactiveFormsModule,
Expand Down

0 comments on commit 6da7a82

Please sign in to comment.