-
Notifications
You must be signed in to change notification settings - Fork 5
feat/AB#74292 People picker #725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TaiKamilla
wants to merge
35
commits into
2.x.x
Choose a base branch
from
feat/AB#74292_ABC-Create-people-picker-question
base: 2.x.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
a164834
mock data
TaiKamilla 8c5d92a
Merge branch '2.1.x' into feat/AB#74292_ABC-Create-people-picker-ques…
NathanHGit d486e03
Merge branch 'beta' into feat/AB#74292_ABC-Create-people-picker-question
MwanPygmay 3647e3a
type not supported anymore, changed
MwanPygmay d93b78b
add support for people question: get type and metadata correctly, ali…
MwanPygmay 54937ce
Merge branch 'beta' into feat/AB#74292_ABC-Create-people-picker-question
TaiKamilla a84fecf
Merge remote-tracking branch 'origin/beta' into feat/AB#74292_ABC-Cre…
TaiKamilla 189c5a1
type
TaiKamilla 2115ffb
missing resolver change
TaiKamilla 3c3e00c
it works
TaiKamilla 52ae447
compact the code a bit
TaiKamilla 6602426
Clean 🧼 🧽
TaiKamilla 21522f0
Merge branch '2.x.x' into feat/AB#74292_ABC-Create-people-picker-ques…
NathanHGit ae83129
feat: added people type
NathanHGit d5f2cea
feat: add get people
NathanHGit 17c52d8
feat: handle people filtering and add people resolver
NathanHGit 2c5088c
review people filter format + unique ids
NathanHGit 05c65cd
add context to resolvers
NathanHGit 8e5b164
fix people resolver
NathanHGit e3c999a
delete field.resource
NathanHGit 0ea3ab0
fix empty value
NathanHGit 716011b
Merge branch '2.x.x' into feat/AB#74292_ABC-Create-people-picker-ques…
AntoineRelief fe3d1fc
now getting people ten by ten
MwanPygmay f5d146e
update meta, and correct export
MwanPygmay d4ea0f5
add support for summary cards and text editor
MwanPygmay 089a94d
avoid getting a back-to-back query
MwanPygmay acc3dee
Merge branch '2.x.x' into feat/AB#74292_ABC-Create-people-picker-ques…
AntoineRelief 09be020
update config
AntoineRelief 8f6eed0
Merge branch '2.x.x' into feat/AB#74292_ABC-Create-people-picker-ques…
AntoineRelief df67577
optimize people query
AntoineRelief 0c7dc32
add support for graphs
MwanPygmay 6906094
remove console log
MwanPygmay dcf1c7a
Merge branch '2.x.x' into feat/AB#74292_ABC-Create-people-picker-ques…
AntoineRelief 7893c10
add support for filter, record history. Sorting does not work yet
MwanPygmay 2031d43
add sorting for layouts
MwanPygmay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { GraphQLError, GraphQLList } from 'graphql'; | ||
import { logger } from '@services/logger.service'; | ||
import { Context } from '@server/apollo/context'; | ||
import GraphQLJSON from 'graphql-type-json'; | ||
import { PersonType } from '@schema/types/person.type'; | ||
import { getPeople } from '@utils/proxy'; | ||
|
||
/** Arguments for the people query */ | ||
type PeopleArgs = { | ||
filter?: any; | ||
}; | ||
|
||
/** | ||
* Return distant users from common services | ||
*/ | ||
export default { | ||
type: new GraphQLList(PersonType), | ||
args: { | ||
filter: { type: GraphQLJSON }, | ||
}, | ||
async resolve(parent, args: PeopleArgs, context: Context) { | ||
if (!args.filter) return []; | ||
try { | ||
// Formatted filter used by the API | ||
const getFormattedFilter = (filter: any) => { | ||
const formattedFilter = `{${filter.logic.toUpperCase()}:[ | ||
${filter.filters.map((el: any) => { | ||
if (el.operator === 'like') { | ||
el.value = `"%${el.value}%"`; | ||
} else if (el.operator === 'in') { | ||
el.value = el.value.map((e) => `"${e}"`); | ||
el.value = `[${el.value}]`; | ||
} | ||
return `{ ${el.field}_${el.operator}: ${el.value} }`; | ||
})} | ||
] | ||
}`; | ||
return formattedFilter.replace(/\s/g, ''); | ||
}; | ||
const filter = getFormattedFilter(args.filter); | ||
const people = await getPeople(context.token, filter); | ||
if (people) { | ||
return people.map((person) => { | ||
const updatedPerson = { ...person }; | ||
updatedPerson.id = updatedPerson.userid; | ||
delete updatedPerson.userid; | ||
return updatedPerson; | ||
}); | ||
} | ||
return []; | ||
} catch (err) { | ||
logger.error(err.message, { stack: err.stack }); | ||
throw new GraphQLError( | ||
context.i18next.t('common.errors.internalServerError') | ||
); | ||
} | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { GraphQLObjectType, GraphQLString } from 'graphql'; | ||
|
||
/** | ||
* GraphQL Person type. | ||
*/ | ||
export const PersonType = new GraphQLObjectType({ | ||
name: 'Person', | ||
fields: () => ({ | ||
id: { type: GraphQLString }, | ||
firstname: { type: GraphQLString }, | ||
lastname: { type: GraphQLString }, | ||
emailaddress: { type: GraphQLString }, | ||
}), | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import axios from 'axios'; | ||
|
||
/** | ||
* Fetches the people | ||
* | ||
* @param token The authorization token | ||
* @param filter The filter used for fetching the distant users | ||
* @returns the choices | ||
*/ | ||
export const getPeople = async (token: string, filter: any): Promise<any[]> => { | ||
const url = 'http://localhost:3000/proxy/common-services/graphql'; | ||
Matthis-M-ReliefApps marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
const query = `query { | ||
users( | ||
filter: ${filter} | ||
) { | ||
userid | ||
firstname | ||
lastname | ||
emailaddress | ||
} | ||
}`; | ||
try { | ||
let people: any[] = []; | ||
await axios({ | ||
url, | ||
method: 'post', | ||
headers: { | ||
Authorization: token, | ||
'Content-Type': 'application/json', | ||
}, | ||
data: { | ||
query: query, | ||
}, | ||
}).then(({ data }) => { | ||
people = data?.data?.users; | ||
}); | ||
return people; | ||
} catch { | ||
return []; | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './authManagement'; | ||
export * from './getChoices'; | ||
export * from './getPeople'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Record } from '@models'; | ||
import { Context } from '@server/apollo/context'; | ||
import { getPeople } from '@utils/proxy'; | ||
|
||
/** | ||
* Return people meta resolver. | ||
* | ||
* @param field field definition. | ||
* @param context graphQL context. | ||
* @returns People resolver. | ||
*/ | ||
const getMetaPeopleResolver = async (field: any, context: Context) => { | ||
const records = await Record.find({ | ||
resource: field.resource, | ||
archived: false, | ||
}); | ||
const peopleIds = []; | ||
records.forEach((record) => { | ||
const propertyValue = record.data[field.name]; | ||
propertyValue?.flat().forEach((id: string) => { | ||
if (!peopleIds.includes(id)) { | ||
peopleIds.push(id); | ||
} | ||
}); | ||
}); | ||
const getFilter = (people: any) => { | ||
const formattedFilter = `{ | ||
userid_in: | ||
[${people.map((el: any) => `"${el}"`)}] | ||
}`; | ||
return formattedFilter.replace(/\s/g, ''); | ||
}; | ||
const filter = getFilter(peopleIds); | ||
const people = await getPeople(context.token, filter); | ||
if (!people) { | ||
return []; | ||
} | ||
|
||
delete field.resource; | ||
|
||
return Object.assign(field, { | ||
choices: people.map((x: any) => { | ||
const fullname = | ||
x.firstname && x.lastname | ||
? `${x.firstname}, ${x.lastname}` | ||
: x.firstname || x.lastname; | ||
return { | ||
text: `${fullname} (${x.emailaddress})`, | ||
value: x.userid, | ||
}; | ||
}), | ||
}); | ||
}; | ||
|
||
export default getMetaPeopleResolver; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.