I have Projects, that can assign roles/tasks to employees from employees collection
so I created join table ProjectAssignments
where employee and specific role to it can be selected
here is how project creation looks
when I try to add an assignment
it opens a new modal where I need to select project, I would like it to be populated with project I came from (and maybe even hide it, and be selected based on project I came from)
and there is also problem with these assingments, that displayed name is just id of corresponding join table
I would like it to be consisted from employee>name + role/assignment of it
I would like to probably hide ProjectsAssignments from admin ui, because I don't think users of this admin panel will understand many-to-many join table, so I would like to leave them with
Projectedit page creation of these assignments
@akhrarovsaid
I would also like to create a select component of employees, that would have avatar + name as select options
not sure it availible in payload
probably needs to be created as custom component
that displayed name is just id of corresponding join table
You need
admin.useAsTitleon these collections
I would also like to create a select component of employees, that would have avatar + name as select options
This sounds like a custom select component
oh, actually I already added this field
but no avail
it opens a new modal where I need to select project, I would like it to be populated with project I came from
This sounds like a bug if it's not populating, it should be
Restart dev server
What payload version are you on?
Also, you are showing me collections with
useAsTitleon them but you need useAsTitle on the collections in the
relationTothat you reference
projectAssignmentsneed a
useAsTitlethe first thing I tried to do
these collection started to use as primary field, but in the projects, it displays just ids
In your
projectAssignmentsdo you have a
useAsTitle?
yep
Shouldn't be a relationship field, that's why you are getting primary key
ugh
You should add a new hidden field that uses the value of your employee
Add it in a hook or something
beforeChange would work
It constructs the value you want, then use that as the title
Internally, relationships are saved as id's
That's why you get a primary key as the title
alright
thanks
I think I'm starting understanding
something like this right?
Yep!
hooks was the concept I had troubles understanding
thanks, your mentorship on my problem lit the light to me
it should be
originalDocisn't?
I think
datahere should be fine
Then return the data
bunch of errors
ugh
You can use
operationto scope it to create and updates, also make sure you actually have the appropriate data here to set, don't forget to add an employeeName field and generateTypes
You are trying to overwrite a reltationship field with a string
You need a new field
employeeNameAnd use that as the title
I should add it to the collection
?
Yep
I've set it as hidden
okay?
this should be working
You need to generate types for it but yeah, restart dev server should do that for you if HMR didn't already
yeah, problem with this
for a some reason after restarting, the type error still present
const employeeID = typeof data.employee === 'number' ? data.employee : data.employee.idjust ts server error I guess
I'm currious how it would look with
operationarg that you've mention
if (operation === 'create' || operation === 'update') { ... }Just scope it down, no need to set a field if it's a delete
oh I see
this issue is still present
I hope scoped it properly
I'm feeling a bit silly because I'm asking a bunch of questions and taking your time
You did the inverse
but your help is priceless for me
You want to be running your hook if it is a create or update
Right now you are running it only if it is not a create or update
Yep
nice
thanks
I don't understand this eror
why Employee object appers as a whole
Depending on the context it may be a number Id or an employee
Payload doesn't know I'm advance
oh thanks
It also depends on access controls and depth
I don't know context where this could be employee object
hmm
Well it's not necessarily up to yoy to decide, it's Payload who will decide when and where, we should account for both cases
Generally, in hooks it will always be an ID though
For performance
pretty tricky moment, but thanks now I know how to write hooks properly
will keep in mind this quirk
interesting
strange thing
tried to log it
but nothing seems to appear in the console
and in browser console too
ugh
Have you added it to hooks in your collection?
hooks.beforeChange: [getEmployeeName]sure
Is there an employee set before you save?
yep
in the Employee column, it references its name properly
I also don't understand why loggin is not working
seems like this hook is not called
oh wait
maybe this is because this entry was created before employeeName hidden field was added?
this might be the case right?
Try making a new one
it works!
ugh
I bit upsetting, because I might encounter with it in the future again
how do I rerun hooks on the previous entries?
if I would need it just in case
Just go into them, change something, revert the change and save
oh
alright
You can also just call an empty update on them via apis
not sure I know how
just call some put method?
Yep
oh okay
so is there a way to make it more convinient?
hide project field, make it default be the project where user came from maybe
I also don't think modal suits this task, but I don't know if payload have other options
I'm sorry, I need your advice please
so is there a way to make it more convinient?
It sounds like a bug to me honestly, but are you clicking the '+' or the edit icon next to a doc?
One way would be to hide the field, then use a custom component to get the doc id of the currently open doc and populate it using react hooks
It's a Drawer component that opens btw
I was clicking the plus icon
Hmm, maybe open an issue with a reproduction on GH
Might get looked at, I feel like it should open with a reference to the currently editted doc
edit icon
But maybe not idk
plus icon
and yeah, now I see that's a drawer
may I send you the whole code?
zip it and send
But for what?
This is expected behavior right now afaik
ugh
hmm
that's sounds hard
Shouldn't be too bad
I suppose it depends on your comfort level with React
hide what field?
you mean replace it with a custom select component?
The project field, no need to replace
No need to hide technically either
Can use a UI field type for this
hm
I know how to get the path segments using a hook
I don't understand where should I add this type field
in what collection?
projects?
Whatever collection this drawer opens
okay, it opens the
ProjectAssignmentscollection
and here project field already have type of relationship
Ok, so you want it to be auto populated if you're coming from an existing project and click the '+' right?
So the ui field would grab the current project id, if any, and assign it to that relationship field
exactly
hmm, so I need new hidden field
Doesn't need to be a new hidden field
and where should I write the logic
it seems like I need to do something like this
but it should return empty component
with running hook, that alter project field value, right?
I wonder is there any example of similar thing implemented
Don't know how to change project field inside of a hook, after I get the id of a project from the current url
Your field definition is wrong
I'm also talking about doing it with
Reacthooks not Payload hooks
You pass a path to a custom component
Not a React Element
yeah, I understand that\
via path
as always in payload
I just wrote it this way for example
so I will have my custom component
but how to alter project field value inside of it
I encourage you to read through the docs here:
https://payloadcms.com/docs/admin/react-hooks#useformfieldsthanks!
that was all I need
thank you a lot!
really
you helped me figure payload out as no one else
My pleasure, truly
actually
Have some fun with it
I would like to become contributor too
but I don't know where to start
payload codebase seems to be very complex
My honest recommendation here is to start learning Payload as best you can. Then answer questions on Discord from users
such big projects source code looks very overwhelming and daunting
And then when you are comfortable enough, then start diving into the codebase
Discord questions will naturally make you search the codebase for answers
After you get comfortable doing that, start trying to reproduce issues in GH and finding fixes for them
okay, I will try to figure payload through docs as much as I can
This is how I started tbh
interesting
thank you !
Of course!
best wishes!
Star
Discord
online
Get dedicated engineering support directly from the Payload team.