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 { BikesService, CargoBikeResult } from 'src/app/services/bikes.service';
import { flatten } from 'src/app/helperFunctions/flattenObject'; import { flatten } from 'src/app/helperFunctions/flattenObject';
import { deepen } from 'src/app/helperFunctions/deepenObject'; 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 { import {
CargoBikeFieldsMutableFragmentDoc, CargoBikeFieldsMutableFragmentDoc,
CargoBikeUpdateInput, CargoBikeUpdateInput,
@ -74,11 +75,6 @@ export class BikesComponent {
for (let index in this.data) { for (let index in this.data) {
this.data[index] = flatten(this.data[index]); 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 //sort, so the displayedColumns array is in the same order as the columnInfo
this.dataColumns.sort((columnA, columnB) => { this.dataColumns.sort((columnA, columnB) => {
@ -133,6 +129,7 @@ export class BikesComponent {
} }
getType(propertyName: string, row) { getType(propertyName: string, row) {
//TODO: get type from introspection query
return ( return (
this.columnInfo.find((column) => column.name === propertyName)?.type || this.columnInfo.find((column) => column.name === propertyName)?.type ||
(typeof row[propertyName]) (typeof row[propertyName])
@ -142,7 +139,7 @@ export class BikesComponent {
isReadonly(propertyName: string) { isReadonly(propertyName: string) {
return ( return (
this.columnInfo.find((column) => column.name === propertyName) this.columnInfo.find((column) => column.name === propertyName)
?.readonly || false ?.readonly || !isPartOfGraphQLDoc(propertyName, CargoBikeFieldsMutableFragmentDoc)
); );
} }

Loading…
Cancel
Save