Sure! Here are the answers to your questions bob. Thanks for helping again!
- Here is the entire data source code I am using in the update role cascader component.
[
{
"value": "Live Tutoring",
"label": "Live Tutoring"
},
{
"value": "Live Tutoring / Analytical Writing Tutor",
"label": "Analytical Writing Tutor",
"parentValue": "Live Tutoring",
"disabled": true
},
{
"value": "Live Tutoring / Creative Writing Tutor",
"label": "Creative Writing Tutor",
"parentValue": "Live Tutoring",
"disabled": true
},
{
"value": "Live Tutoring / Application Consultant",
"label": "Application Consultant",
"parentValue": "Live Tutoring",
"disabled": true
},
{
"value": "Live Bootcamps",
"label": "Live Bootcamps"
},
{
"value": "Live Bootcamps / Bootcamp Teacher",
"label": "Teacher",
"parentValue": "Live Bootcamps",
"disabled": true
},
{
"value": "Mock Interviews",
"label": "Mock Interviews"
},
{
"value": "Mock Interviews / College Consulting Interviewer",
"label": "College Consulting Interviewer",
"parentValue": "Mock Interviews"
},
{
"value": "Async Editing",
"label": "Async Editing"
},
{
"value": "Async Editing / Async Trainee",
"label": "Trainee",
"parentValue": "Async Editing"
},
{
"value": "Async Editing / Async Editor",
"label": "Editor",
"parentValue": "Async Editing"
},
{
"value": "Async Editing / Async Heimdall",
"label": "Heimdall",
"parentValue": "Async Editing",
"disabled": true
},
{
"value": "Story Editing",
"label": "Story Editing"
},
{
"value": "Story Editing / Story Trainee",
"label": "Trainee",
"parentValue": "Story Editing"
},
{
"value": "Story Editing / Story Editor",
"label": "Editor",
"parentValue": "Story Editing"
},
{
"value": "Story Editing / Story Heimdall",
"label": "Heimdall",
"parentValue": "Story Editing"
},
{
"value": "Bootcamp HW Grading",
"label": "Bootcamp HW Grading"
},
{
"value": "Bootcamp HW Grading / Bootcamp HW Trainee",
"label": "Trainee",
"parentValue": "Bootcamp HW Grading"
},
{
"value": "Bootcamp HW Grading / Bootcamp HW Grader",
"label": "Grader",
"parentValue": "Bootcamp HW Grading",
"disabled": true
},
{
"value": "Bootcamp HW Grading / Bootcamp HW Manager",
"label": "Manager",
"parentValue": "Bootcamp HW Grading"
},
{
"value": "Season of Ink",
"label": "Season of Ink"
},
{
"value": "Season of Ink / Season of Ink Judge",
"label": "Judge",
"parentValue": "Season of Ink"
},
{
"value": "Ongoing Admin",
"label": "Ongoing Admin"
},
{
"value": "Ongoing Admin / General Work",
"label": "General Work",
"parentValue": "Ongoing Admin"
}
]
And here is my code for how I generated that set:
let originalArr = [
{
value: "Live Tutoring", label: "Live Tutoring",
children: [
{ value: "Analytical Writing Tutor", label: "Analytical Writing Tutor" },
{ value: "Creative Writing Tutor", label: "Creative Writing Tutor" },
{ value: "Application Consultant", label: "Application Consultant" },
]
},
{
value: "Live Bootcamps", label: "Live Bootcamps",
children: [
{ value: "Bootcamp Teacher", label: "Teacher" },
]
},
{
value: "Mock Interviews", label: "Mock Interviews",
children: [
{ value: "College Consulting Interviewer", label: "College Consulting Interviewer" },
]
},
{
value: "Async Editing", label: "Async Editing",
children: [
{ value: "Async Trainee", label: "Trainee" },
{ value: "Async Editor", label: "Editor" },
{ value: "Async Heimdall", label: "Heimdall" }
]
},
{
value: "Story Editing", label: "Story Editing",
children: [
{ value: "Story Trainee", label: "Trainee" },
{ value: "Story Editor", label: "Editor" },
{ value: "Story Heimdall", label: "Heimdall" }
]
},
{
value: "Bootcamp HW Grading", label: "Bootcamp HW Grading",
children: [
{ value: "Bootcamp HW Trainee", label: "Trainee" },
{ value: "Bootcamp HW Grader", label: "Grader" },
{ value: "Bootcamp HW Manager", label: "Manager" }
]
},
{
value: "Season of Ink", label: "Season of Ink",
children: [
{ value: "Season of Ink Judge", label: "Judge" },
]
},
{
value: "Ongoing Admin", label: "Ongoing Admin",
children: [
{ value: "General Work", label: "General Work" },
]
}
];
// If no selected staff, return original flattened without disabled logic
if (!srViewStaff.selectedItem || !srViewStaff.selectedItem.id) {
return flattenRoles(originalArr);
}
// Prepare Staff Roles Data
const staffRolesData = srGetAllStaff.data;
const staffRolesObjects = [];
const keys = Object.keys(staffRolesData);
const arrays = keys.map(key => staffRolesData[key]);
const length = arrays[0].length;
for (let i = 0; i < length; i++) {
const item = {};
keys.forEach((key, index) => {
item[key] = arrays[index][i];
});
staffRolesObjects.push(item);
}
// Filtered Roles for Selected Staff
const filteredData = staffRolesObjects.filter(item => item.staff_id === srViewStaff.selectedItem.id);
// Flatten Function with Disabled Logic
function flattenRolesWithDisabled(originalArr, filteredData) {
const result = [];
originalArr.forEach(parent => {
result.push({
value: parent.value,
label: parent.label
});
parent.children.forEach(child => {
const isDisabled = filteredData.some(item =>
item.service === parent.value && item.role === child.value
);
result.push({
value: `${parent.value} / ${child.value}`,
label: child.label,
parentValue: parent.value,
...(isDisabled && { disabled: true })
});
});
});
return result;
}
// Helper if no disabled logic needed
function flattenRoles(originalArr) {
const result = [];
originalArr.forEach(parent => {
result.push({
value: parent.value,
label: parent.label
});
parent.children.forEach(child => {
result.push({
value: `${parent.value} / ${child.value}`,
label: child.label,
parentValue: parent.value
});
});
});
return result;
}
// Return the flattened with disabled logic applied
return flattenRolesWithDisabled(originalArr, filteredData);
- Yes, item.value and item.label have different values. For the label, I just put "Creative Writing Tutor" and drop out the service (i.e. "Live Tutoring"), even though the value is "Live Tutoring / Creative Writing Tutor". I thought that would help with readability, but I'm happy to change the label to match that of the value if needed! I think I'm misunderstanding how the new Cascader works with parent values.
3 and 4. I recorded a video showing you what I see. Now there's some straight up weird behavior; it automatically prefills the Cascader with Application Consultant, even though I set it as Creative Writing Tutor. Clips