I have a function that returns an array based on a condition. Here is the code snippet:
const operationPerResource = (resource: ResourceTypes): OperationTypes[] => {
const operations = cases[resource] || cases.default;
return operations;
};
Now, I need to iterate over an array of objects with a {label: string, value: string} type using the above function.
First, I transform the enum into an array:
const resources = transformEnumToArray(ResourceTypes);
const operations = operationPerResource(resources[0].value).map((value: any) => ({
label: value,
value
}));
The problem is that the above function only gives results for the first item in the array. I want to iterate over all items in the array and get back the available operations for each resource.
Whenever I select a resource from the select-box, I want to print the correct output. I am using the operationPerResource function to achieve this:
Since resources are an array of objects, I need to iterate over them to get the correct operations each time:
Example:
Resource: Name1 => Operations for Name1 [3 Items]
Resource: Name2 => Operations for Name2 [2 Items]
Resource: Name3 => Operations for Name3 [5 Items]
My goal is to make the process dynamic, so that clicking on a specific resource gives back the expected results each time.
I only want to print the results of each resource individually, not all together.
I'm facing a challenge in achieving this. Any assistance would be highly appreciated.