Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,21 @@ useEffect(() => {
>
<DraggableIcon />
</button>

<label htmlFor={`${item.id ?? item.name}-checkbox-id`} className="input-checkbox">
<label htmlFor={`${!(item.isFormVariable)
? "static-" + (item.id || item.name)
: item.id || item.name
}-checkbox-id`} className="input-checkbox">
<input
id={`${item.id ?? item.name}-checkbox-id`}
id={`${!(item.isFormVariable)
? "static-" + (item.id || item.name)
: item.id || item.name
}-checkbox-id`}
type="checkbox"
checked={item.isChecked}
onChange={() => onCheckboxChange(index)}
disabled={preventLastCheck && item.isChecked && filterItems.filter(i => i.isChecked).length === 1}
data-testid={`${item.name}-checkbox`}
/>
/>
<span>{item.label ?? item.name}</span>
{item.isChecked ? <CheckboxCheckedIcon /> : <CheckboxUncheckedIcon /> }
</label>
Expand Down
132 changes: 106 additions & 26 deletions forms-flow-review/src/components/TaskList/TaskList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@ const TaskList = () => {
"submitterName",
"formName"
])
// check if selectedType belongs to sortableList
const currentVariable = taskvariables.find((item)=> item.key === filterListSortParams?.activeKey);
const isFormVariable =currentVariable?.isFormVariable || enabledSort.has(filterListSortParams?.activeKey) ;
// Use the actual sort key stored in filterListSortParams
const actualSortKey = filterListSortParams?.actualSortKey || filterListSortParams?.activeKey;
// Check if it's explicitly set as a form variable or is in the enabled sort set
const isFormVariable = filterListSortParams?.isFormVariable !== undefined
? filterListSortParams.isFormVariable
: enabledSort.has(actualSortKey);
if (filterCached) {
payload = lastReqPayload;
dispatch(resetTaskListParams({ filterCached: false }));
Expand Down Expand Up @@ -163,28 +166,40 @@ const TaskList = () => {
};

const handleSortApply = (selectedSortOption, selectedSortOrder) => {
// reset the sort orders using helper function
// Reset the sort orders using helper function
const resetSortOrders = HelperServices.getResetSortOrders(optionSortBy.options);

// get the variable info first
const selectedVar = taskvariables.find(item => item.key === selectedSortOption);
const selectedType = selectedVar?.type;

// check if it's a form variable
const isFormVariable = sortableKeysSet.has(selectedType);


// Get all available sort options
const allSortOptions = optionsForSortModal();

// Find the selected option from our options list
const selectedOption = allSortOptions.find(option => option.value === selectedSortOption);

if (!selectedOption) {
console.error("Selected sort option not found:", selectedSortOption);
return;
}

// Get the actual sort key and form variable flag from the selected option
const actualSortKey = selectedOption.actualSortKey || selectedSortOption;
const isFormVariable = selectedOption.isFormVariable;
const selectedType = selectedOption.type;

const updatedData = {
...resetSortOrders,
activeKey: selectedSortOption,
[selectedSortOption]: {
sortOrder: selectedSortOrder,
...(isFormVariable && { type: selectedType })
},
// Store the actual sortKey to use in API requests
actualSortKey: actualSortKey,
isFormVariable: isFormVariable
};

dispatch(setFilterListSortParams(updatedData));
setShowSortModal(false);
fetchTaskListData({ sortData: updatedData });
fetchTaskListData({ sortData: updatedData });
};


Expand Down Expand Up @@ -237,19 +252,84 @@ const TaskList = () => {
}, [isAssigned, activePage, limit]);

const optionsForSortModal = () => {
const existingValues = new Set(optionSortBy.keys);
// Get predefined sort options and dynamic columns from task variables
const existingKeys = new Set(optionSortBy.keys);
const dynamicColumns = buildDynamicColumns(taskvariables);

const filteredDynamicColumns = dynamicColumns
.filter(column =>
!existingValues.has(column.sortKey) && // filter out duplicates form sorting list
sortableKeysSet.has(column.type)) // sorting enabled only for sortablelist items and optionSortBy
.map(column => ({
value: column.sortKey,
label: column.name,
}));

return [...optionSortBy.options, ...filteredDynamicColumns];

// Track what we've already used to avoid duplicates
const usedLabels = new Map();
const usedValues = new Set();

// Process the base options first
const baseOptions = optionSortBy.options.map(option => {
// Mark this label and value as used
usedLabels.set(option.label, true);
usedValues.add(option.value);

return {
...option,
actualSortKey: option.value,
isFormVariable: false
};
});

// Process dynamic columns from task variables
const formFieldOptions = dynamicColumns
// Only keep sortable columns that aren't duplicates (unless they're form variables)
.filter(column =>
sortableKeysSet.has(column.type) &&
(!existingKeys.has(column.sortKey) || column.isFormVariable)
)
.map(column => {
// Create a unique identifier for this column
const uniqueValue = column.isFormVariable ?
`${column.sortKey}_form` : column.sortKey;

// Skip if we already have this value
if (usedValues.has(uniqueValue)) {
return null;
}

// Start with the column name as the label
let label = column.name;

// If this label is already used, make it unique
if (usedLabels.has(label)) {
// Add context to the label
label = column.isFormVariable ?
`${label} (Form Field)` :
`${label} (Task Field)`;

// If still a duplicate, add a number
if (usedLabels.has(label)) {
let counter = 1;
let newLabel = label;

while (usedLabels.has(newLabel)) {
counter++;
newLabel = `${label} ${counter}`;
}

label = newLabel;
}
}

// Mark this label and value as used
usedLabels.set(label, true);
usedValues.add(uniqueValue);

return {
value: uniqueValue,
label: label,
actualSortKey: column.sortKey,
isFormVariable: column.isFormVariable,
type: column.type
};
})
.filter(Boolean); // Remove null entries

// Combine base options with form field options
return [...baseOptions, ...formFieldOptions];
};

return (
Expand Down
22 changes: 16 additions & 6 deletions forms-flow-review/src/components/TaskList/TasklistTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,22 @@ return matchingVar.value ?? "-";
"submitterName",
"formName"
])

// Create a unique key for the column that includes isFormVariable to differentiate between columns with same sortKey
const uniqueColumnKey = column.isFormVariable ? `${column.sortKey}_form` : column.sortKey;

const updatedFilterListSortParams = {
...resetSortOrders,
[column.sortKey]: {
[uniqueColumnKey]: {
sortOrder:
filterListSortParams[column.sortKey]?.sortOrder === "asc" ? "desc" : "asc",
filterListSortParams[uniqueColumnKey]?.sortOrder === "asc" ? "desc" : "asc",
...((column.isFormVariable || enabledSort.has(column.sortKey)) && {
type: column.type ,
type: column.type,
})
},
activeKey: column.sortKey,
activeKey: uniqueColumnKey,
// Store the actual sortKey to use in API requests
actualSortKey: column.sortKey,
};

dispatch(setFilterListSortParams(updatedFilterListSortParams));
Expand All @@ -284,14 +290,18 @@ return matchingVar.value ?? "-";
</span>
)
}

// Create a unique key for the column that includes isFormVariable to differentiate between columns with same sortKey
const uniqueColumnKey = column.isFormVariable ? `${column.sortKey}_form` : column.sortKey;

return (
<SortableHeader
className="header-sortable"
columnKey={column.sortKey}
columnKey={uniqueColumnKey}
title={t(column.name)}
currentSort={filterListSortParams}
handleSort={() => handleSort(column)}
dataTestId={`sort-header-${column.sortKey}`}
dataTestId={`sort-header-${uniqueColumnKey}`}
ariaLabel={t("Sort by {{columnName}}", {
columnName: t(column.name),
})}
Expand Down
9 changes: 6 additions & 3 deletions forms-flow-review/src/helper/taskHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ export const createReqPayload = (
"formName"
])

// Get the actual sortKey to use in API requests (for columns with same sortKey but different isFormVariable)
const actualSortKey = filterListSortParams?.actualSortKey || filterListSortParams?.activeKey;

// Build sort filter
const newFilter = isFormVariable || enabledSort.has(filterListSortParams?.activeKey)
const newFilter = isFormVariable || enabledSort.has(actualSortKey)
? {
sortBy: "processVariable",
sortOrder: filterListSortParams?.[filterListSortParams?.activeKey]?.sortOrder,
parameters: {
variable: filterListSortParams?.activeKey,
variable: actualSortKey,
type:
sortableList[
filterListSortParams?.[filterListSortParams?.activeKey]?.type
Expand All @@ -76,7 +79,7 @@ export const createReqPayload = (
},
}
: {
sortBy: filterListSortParams?.activeKey,
sortBy: actualSortKey,
sortOrder:
filterListSortParams?.[filterListSortParams?.activeKey]?.sortOrder,
};
Expand Down
Loading