Add dynamic readonly columns

pull/3/head
Max Ehrlicher-Schmidt 4 years ago
parent dc95721546
commit 67b7baf770

@ -0,0 +1,28 @@
import { DocumentNode } from 'graphql';
export function isPartOfGraphQLDoc(
variableName: String,
doc: DocumentNode
): boolean {
return isPartOfSelectionSet(variableName, doc.definitions[0]);
}
function isPartOfSelectionSet(
variableName: String,
selectionObject: any
): boolean {
const variablePath = variableName.split('.');
const selections = selectionObject.selectionSet?.selections;
if (selections !== undefined) {
const nextSelectionObject = selections.find(selection => selection.name.value === variablePath[0]);
if (nextSelectionObject !== undefined) {
if (variablePath.length === 1) {
return true;
}
return isPartOfSelectionSet(variablePath.slice(1).join(), nextSelectionObject);
} else {
return false;
}
}
return false;
}

@ -4,7 +4,8 @@ import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { BikesService, CargoBikeResult } from 'src/app/services/bikes.service';
import { flatten } from 'src/app/helperFunctions/flattenObject';
import { deepen } from 'src/app/helperFunctions/deepenObject';
import { filter, propType } from 'graphql-anywhere';
import { isPartOfGraphQLDoc } from 'src/app/helperFunctions/isPartOfGraphQLFunction';
import { filter } from 'graphql-anywhere';
import {
CargoBikeFieldsMutableFragmentDoc,
CargoBikeUpdateInput,
@ -75,11 +76,6 @@ export class BikesComponent {
this.data[index] = flatten(this.data[index]);
}
console.log(CargoBikeFieldsMutableFragmentDoc);
for (const prop in Object.keys(CargoBikeFieldsMutableFragmentDoc)) {
console.log(prop);
}
//sort, so the displayedColumns array is in the same order as the columnInfo
this.dataColumns.sort((columnA, columnB) => {
const indexA = this.columnInfo.findIndex((c) => c.name == columnA);
@ -133,6 +129,7 @@ export class BikesComponent {
}
getType(propertyName: string, row) {
//TODO: get type from introspection query
return (
this.columnInfo.find((column) => column.name === propertyName)?.type ||
(typeof row[propertyName])
@ -142,7 +139,7 @@ export class BikesComponent {
isReadonly(propertyName: string) {
return (
this.columnInfo.find((column) => column.name === propertyName)
?.readonly || false
?.readonly || !isPartOfGraphQLDoc(propertyName, CargoBikeFieldsMutableFragmentDoc)
);
}

Loading…
Cancel
Save