Skip to content

Commit

Permalink
gh-470: Allow for duplicate field names
Browse files Browse the repository at this point in the history
  • Loading branch information
NigelPalmer committed Oct 14, 2024
1 parent 8e7a146 commit 80362e9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 78 deletions.
8 changes: 2 additions & 6 deletions src/app/data-explorer/pipes/meql.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ export class MeqlPipe implements PipeTransform {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const date = moment.isMoment(value) ? value : moment(value);

return `${quotes}${this._date
.transform(date.toDate(), 'dd/MM/yyyy')
?.toString()}${quotes}`;
return `${quotes}${this._date.transform(date.toDate(), 'dd/MM/yyyy')?.toString()}${quotes}`;
}

private parseQuery(
Expand Down Expand Up @@ -115,9 +113,7 @@ export class MeqlPipe implements PipeTransform {
}
break;
case 'field': {
const entity = value.entity as string;
const fullName = entity ? `${entity}.${value[key]}` : value[key];
meql += this.formattedValue(fullName, true) + ' ';
meql += this.formattedValue(value[key], true) + ' ';
break;
}
case 'value':
Expand Down
35 changes: 17 additions & 18 deletions src/app/data-explorer/query-builder-wrapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ export const mapModelDataTypeToOptionsArray = (dataType: DataType): Option[] =>
];
};

export const mapOptionsArrayToModelDataType = (
options: Option[]
): Required<CatalogueItem> => {
export const mapOptionsArrayToModelDataType = (options: Option[]): Required<CatalogueItem> => {
const domainType = options.find((o) => o.name === 'modelResourceDomainType')
?.value as CatalogueItemDomainType;
const id = options.find((o) => o.name === 'modelResourceId')?.value;
Expand Down Expand Up @@ -90,10 +88,7 @@ export class QueryBuilderWrapperService {
map(([items, coreTableProfile]) => {
let errorMessage = '';

errorMessage = this.appendErrorMessages(
errorMessage,
this.getDataTypeProfileErrors(items)
);
errorMessage = this.appendErrorMessages(errorMessage, this.getDataTypeProfileErrors(items));

errorMessage = this.appendErrorMessages(
errorMessage,
Expand Down Expand Up @@ -128,6 +123,12 @@ export class QueryBuilderWrapperService {
.join('.');
}

private getEntityAndLabel(dataElement: DataElementSearchResult) {
const entity = this.getEntity(dataElement);
const label = dataElement.label;
return entity ? `${entity}.${label}` : label;
}

private getQueryBuilderDatatypeProfile(dataType?: DataType): Observable<Profile> {
if (dataType?.domainType === CatalogueItemDomainType.PrimitiveType) {
const requestOptions = {
Expand All @@ -148,8 +149,7 @@ export class QueryBuilderWrapperService {
private getDataTypeString(data: Profile, dataElement: DataElementSearchResult) {
if (
dataElement.dataType?.domainType === CatalogueItemDomainType.ModelDataType &&
(dataElement.dataType?.modelResourceDomainType ===
CatalogueItemDomainType.Terminology ||
(dataElement.dataType?.modelResourceDomainType === CatalogueItemDomainType.Terminology ||
dataElement.dataType?.modelResourceDomainType === CatalogueItemDomainType.CodeSet)
) {
return 'terminology';
Expand Down Expand Up @@ -190,10 +190,10 @@ export class QueryBuilderWrapperService {
return dataTypeString.toLowerCase() === 'number'
? 0
: dataTypeString.toLowerCase() === 'string'
? ''
: dataTypeString.toLowerCase() === 'boolean'
? false
: null;
? ''
: dataTypeString.toLowerCase() === 'boolean'
? false
: null;
}

private getQueryCondition(query?: DataSpecificationQueryPayload): QueryCondition {
Expand All @@ -211,7 +211,7 @@ export class QueryBuilderWrapperService {
dataElement: DataElementSearchResult,
config: QueryBuilderConfig
) {
config.fields[dataElement.label] = {
config.fields[this.getEntityAndLabel(dataElement)] = {
name: dataElement.label + ' (' + dataTypeString + ')',
type: dataTypeString,
entity: this.getEntity(dataElement),
Expand All @@ -225,12 +225,11 @@ export class QueryBuilderWrapperService {
config: QueryBuilderConfig,
queryCondition: QueryCondition
) {
const dataElementPath = this.getEntityAndLabel(dataElement);
if (
queryCondition?.rules?.find((x) =>
(x as QueryExpression)?.field?.startsWith(dataElement.label)
)
queryCondition?.rules?.find((x) => (x as QueryExpression)?.field?.startsWith(dataElementPath))
) {
config.fields[dataElement.label] = {
config.fields[dataElementPath] = {
name: dataElement.label + ' (string)',
type: 'string',
entity: this.getEntity(dataElement),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class QueryBuilderWrapperComponent implements OnInit {
options: terms.items.map((item) => {
return {
name: item.definition,
value: item,
value: item.definition,
};
}),
};
Expand Down
69 changes: 16 additions & 53 deletions src/app/data-explorer/query-builder/query-builder.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@
[ngClass]="getClassNames('arrowIconButton', data.collapsed ? 'collapsed' : null)"
>
<ng-container *ngIf="getArrowIconTemplate() as template; else defaultArrowIcon">
<ng-container
*ngTemplateOutlet="template; context: getArrowIconContext()"
></ng-container>
<ng-container *ngTemplateOutlet="template; context: getArrowIconContext()"></ng-container>
</ng-container>
</a>

<ng-container *ngIf="getButtonGroupTemplate() as template; else defaultButtonGroup">
<div [ngClass]="getClassNames('buttonGroup', 'rightAlign')">
<ng-container
*ngTemplateOutlet="template; context: getButtonGroupContext()"
></ng-container>
<ng-container *ngTemplateOutlet="template; context: getButtonGroupContext()"></ng-container>
</div>
</ng-container>

Expand Down Expand Up @@ -80,21 +76,13 @@
</ng-template>

<ng-container *ngIf="getSwitchGroupTemplate() as template; else defaultSwitchGroup">
<ng-container
*ngTemplateOutlet="template; context: getSwitchGroupContext()"
></ng-container>
<ng-container *ngTemplateOutlet="template; context: getSwitchGroupContext()"></ng-container>
</ng-container>

<ng-template #defaultSwitchGroup>
<mat-radio-group
*ngIf="data"
[(ngModel)]="data.condition"
(ngModelChange)="changeConnective()"
>
<mat-radio-group *ngIf="data" [(ngModel)]="data.condition" (ngModelChange)="changeConnective()">
<mat-radio-button color="primary" value="and">AND</mat-radio-button>
<mat-radio-button *ngIf="showOrRadioButton()" color="primary" value="or"
>OR</mat-radio-button
>
<mat-radio-button *ngIf="showOrRadioButton()" color="primary" value="or">OR</mat-radio-button>
</mat-radio-group>
</ng-template>

Expand Down Expand Up @@ -145,9 +133,7 @@
Condition used to be: entities?.length ?? 0 > 0
-->
<div *ngIf="false" class="q-inline-block-display">
<ng-container
*ngIf="getEntityTemplate() as template; else defaultEntity"
>
<ng-container *ngIf="getEntityTemplate() as template; else defaultEntity">
<ng-container
*ngTemplateOutlet="template; context: getEntityContext(rule)"
></ng-container>
Expand Down Expand Up @@ -183,19 +169,14 @@
(ngModelChange)="changeField($event, rule)"
[disabled]="disabled"
>
<option
*ngFor="let field of getFields(rule.entity)"
[ngValue]="field.value"
>
<option *ngFor="let field of getFields(rule.entity)" [ngValue]="field.value">
{{ field.name }}
</option>
</select>
</div>
</ng-template>

<ng-container
*ngIf="getOperatorTemplate() as template; else defaultOperator"
>
<ng-container *ngIf="getOperatorTemplate() as template; else defaultOperator">
<ng-container
*ngTemplateOutlet="template; context: getOperatorContext(rule)"
></ng-container>
Expand All @@ -219,9 +200,7 @@
</div>
</ng-template>

<ng-container
*ngIf="findTemplateForRule(rule) as template; else defaultInput"
>
<ng-container *ngIf="findTemplateForRule(rule) as template; else defaultInput">
<ng-container
*ngTemplateOutlet="template; context: getInputContext(rule)"
></ng-container>
Expand Down Expand Up @@ -271,10 +250,7 @@
[disabled]="disabled"
*ngSwitchCase="'category'"
>
<option
*ngFor="let opt of getOptions(rule.field)"
[ngValue]="opt.value"
>
<option *ngFor="let opt of getOptions(rule.field)" [ngValue]="opt.value">
{{ opt.name }}
</option>
</select>
Expand All @@ -286,10 +262,7 @@
[disabled]="disabled"
multiple
>
<option
*ngFor="let opt of getOptions(rule.field)"
[ngValue]="opt.value"
>
<option *ngFor="let opt of getOptions(rule.field)" [ngValue]="opt.value">
{{ opt.name }}
</option>
</select>
Expand All @@ -315,18 +288,10 @@
[parentOperatorTemplate]="parentOperatorTemplate || operatorTemplate"
[parentFieldTemplate]="parentFieldTemplate || fieldTemplate"
[parentEntityTemplate]="parentEntityTemplate || entityTemplate"
[parentSwitchGroupTemplate]="
parentSwitchGroupTemplate || switchGroupTemplate
"
[parentButtonGroupTemplate]="
parentButtonGroupTemplate || buttonGroupTemplate
"
[parentRemoveButtonTemplate]="
parentRemoveButtonTemplate || removeButtonTemplate
"
[parentEmptyWarningTemplate]="
parentEmptyWarningTemplate || emptyWarningTemplate
"
[parentSwitchGroupTemplate]="parentSwitchGroupTemplate || switchGroupTemplate"
[parentButtonGroupTemplate]="parentButtonGroupTemplate || buttonGroupTemplate"
[parentRemoveButtonTemplate]="parentRemoveButtonTemplate || removeButtonTemplate"
[parentEmptyWarningTemplate]="parentEmptyWarningTemplate || emptyWarningTemplate"
[parentArrowIconTemplate]="parentArrowIconTemplate || arrowIconTemplate"
[parentValue]="data"
[classNames]="classNames"
Expand All @@ -340,9 +305,7 @@
>
</query-builder>

<ng-container
*ngIf="getEmptyWarningTemplate() as template; else defaultEmptyWarning"
>
<ng-container *ngIf="getEmptyWarningTemplate() as template; else defaultEmptyWarning">
<ng-container *ngIf="local.invalid">
<ng-container
*ngTemplateOutlet="template; context: getEmptyWarningContext()"
Expand Down

0 comments on commit 80362e9

Please sign in to comment.