Skip to content

Commit

Permalink
Resolve backend pivot issue in typeDef helper. Frontend updates
Browse files Browse the repository at this point in the history
  • Loading branch information
big213 committed Mar 6, 2021
1 parent 70dc1f1 commit d0787d2
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 32 deletions.
30 changes: 18 additions & 12 deletions backend/functions/src/schema/helpers/typeDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,13 @@ export function generatePaginatorPivotResolverObject(params: {
? currentService.typename.toLowerCase()
: null;

// if filterByField, ensure that filterByField is a valid filterField on pivotService
if (filterByField && !pivotService.filterFieldsMap[filterByField]) {
throw new JomqlInitializationError({
message: `Filter Key '${filterByField}' does not exist on type '${pivotService.typename}'`,
});
}

const sortByScalarDefinition: ScalarDefinition = {
name: pivotService.typename + "SortByKey",
types: Object.keys(pivotService.sortFieldsMap).map((ele) => `"${ele}"`),
Expand Down Expand Up @@ -756,21 +763,20 @@ export function generatePaginatorPivotResolverObject(params: {
// parentValue.id should be requested (via requiredSqlFields)
const parentItemId = parentValue.id;

// apply the filterByField as an arg to each filterObject
const filterObjectArray = validatedArgs.filterBy ?? [{}];
filterObjectArray.forEach((filterObject) => {
filterObject[filterByField] = { eq: parentItemId };
});
console.log(filterObjectArray);

return pivotService.paginator.getRecord({
req,
fieldPath,
args: deepAssign(
{ ...validatedArgs },
{
filterBy: {
[filterByField]: [
{
value: parentItemId,
},
],
},
}
),
args: {
...validatedArgs,
filterBy: filterObjectArray,
},
query,
data,
});
Expand Down
2 changes: 1 addition & 1 deletion backend/functions/src/schema/models/user/typeDef.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import * as bcrypt from "bcryptjs";

import { JomqlObjectType, lookupSymbol, ObjectTypeDefinition } from "jomql";
import { JomqlObjectType, ObjectTypeDefinition } from "jomql";
import { User } from "../../services";
import {
generateIdField,
Expand Down
1 change: 0 additions & 1 deletion backend/functions/src/schema/scalars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export { number } from "./number"; // replacing the built-in number type to auto
export { imageUrl } from "./imageUrl";
export { unixTimestamp } from "./unixTimestamp";
export { date } from "./date";
export { jsonAsString } from "./jsonAsString";
export { id } from "./id";
export { regex } from "./regex";

Expand Down
16 changes: 0 additions & 16 deletions backend/functions/src/schema/scalars/jsonAsString.ts

This file was deleted.

2 changes: 2 additions & 0 deletions frontend/components/interface/crud/crudRecordInterface.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
:prepend-icon="item.fieldInfo.icon"
clearable
filled
return-object
class="py-0"
@change="filterChanged = true"
></v-autocomplete>
Expand All @@ -162,6 +163,7 @@
filled
hide-no-data
cache-items
return-object
class="py-0"
@update:search-input="handleSearchUpdate(item)"
@blur="item.focused = false"
Expand Down
2 changes: 2 additions & 0 deletions frontend/components/interface/crud/editRecordInterface.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
:readonly="item.readonly || mode === 'view'"
:clearable="!item.readonly && mode !== 'view'"
filled
return-object
class="py-0"
></v-autocomplete>
<v-autocomplete
Expand All @@ -151,6 +152,7 @@
filled
hide-no-data
cache-items
return-object
class="py-0"
@update:search-input="handleSearchUpdate(item)"
@blur="item.focused = false"
Expand Down
7 changes: 5 additions & 2 deletions frontend/mixins/crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ export default {
__args: {
first: 20,
search: inputObject.search,
filterBy: inputObject.fieldInfo.lookupFilters
? inputObject.fieldInfo.lookupFilters(this)
: [],
},
},
})
Expand Down Expand Up @@ -707,9 +710,9 @@ export default {
this.options.initialLoad = true
// populate sort/page options
this.options.sortBy =
this.recordInfo.paginationOptions.sortOptions?.sortBy ?? []
this.recordInfo.paginationOptions.sortOptions?.sortBy.slice() ?? []
this.options.sortDesc =
this.recordInfo.paginationOptions.sortOptions?.sortDesc ?? []
this.recordInfo.paginationOptions.sortOptions?.sortDesc.slice() ?? []
}

// sets all of the filter values to null, searchInput to '' and also emits changes to parent
Expand Down
9 changes: 9 additions & 0 deletions frontend/mixins/editRecordInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export default {
__args: {
first: 20,
search: inputObject.search,
filterBy: inputObject.fieldInfo.lookupFilters
? inputObject.fieldInfo.lookupFilters(this)
: [],
},
},
})
Expand Down Expand Up @@ -190,6 +193,12 @@ export default {
} else {
value = inputObject.value.id
}
} else if (
inputObject.fieldInfo.inputType === 'autocomplete' ||
inputObject.fieldInfo.inputType === 'server-autocomplete'
) {
// as we are using return-object option, the entire object will be returned for autocompletes, unless it is null
value = inputObject.value ? inputObject.value.id : null
} else {
value = inputObject.value
}
Expand Down
9 changes: 9 additions & 0 deletions frontend/models/personalBest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ export const PersonalBest = <RecordInfo<'personalBest'>>{
'created_by.id': {
text: 'Created By',
inputType: 'server-autocomplete',
lookupFilters: (_that) => {
return [
{
is_public: {
eq: true,
},
},
]
},
typename: 'user',
parseQueryValue: (val) => Number(val),
},
Expand Down
2 changes: 2 additions & 0 deletions frontend/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type RecordInfo<T extends keyof MainTypes> = {
inputRules?: any[]
getOptions?: (that) => Promise<any[]>
typename?: string
// filters that should be applied when looking up results (server-X input type)
lookupFilters?: (that) => any[]

// is the field hidden? if yes, won't fetch it for edit fields
hidden?: boolean
Expand Down

0 comments on commit d0787d2

Please sign in to comment.