Skip to content

Commit

Permalink
Always display segments filter when the feature is enabled (#6704)
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya authored Sep 25, 2024
1 parent 9f54d5e commit 42e22a7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { useDashboardFilters } from '../../utils/dashboard/hooks';
import { courseURL } from '../../utils/dashboard/navigation';
import { useDocumentTitle } from '../../utils/hooks';
import { replaceURLParams } from '../../utils/url';
import type { DashboardActivityFiltersProps } from './DashboardActivityFilters';
import type {
DashboardActivityFiltersProps,
SegmentsType,
} from './DashboardActivityFilters';
import DashboardActivityFilters from './DashboardActivityFilters';
import DashboardBreadcrumbs from './DashboardBreadcrumbs';
import FormattedDate from './FormattedDate';
Expand Down Expand Up @@ -61,21 +64,21 @@ export default function AssignmentActivity() {
}

const hasSections = 'sections' in data;
const hasGroups = 'groups' in data;
const entries = hasSections
? data.sections
: 'groups' in data
: hasGroups
? data.groups
: undefined;

// If the assignment doesn't have either sections or groups, we won't
// display the segments filter
if (!entries || entries.length === 0) {
return undefined;
}
const type: SegmentsType = hasSections
? 'sections'
: hasGroups
? 'groups'
: 'none';

return {
type: hasSections ? 'sections' : 'groups',
entries,
type,
entries: entries ?? [],
selectedIds: segmentIds,
onChange: segmentIds => updateFilters({ segmentIds }),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ export type ActivityFilterItem<T extends Course | Assignment> = {
onClear: () => void;
};

export type SegmentsType = 'groups' | 'sections' | 'none';

export type SegmentsSelection = ActivityFilterSelection & {
type: 'groups' | 'sections';
type: SegmentsType;
entries: AssignmentSegment[];
};

Expand Down Expand Up @@ -129,16 +131,19 @@ function StudentOption({
function SegmentsMultiSelect({ segments }: { segments: SegmentsSelection }) {
const segmentsName = segments.type === 'groups' ? 'groups' : 'sections';
const segmentNameSingular = segments.type === 'groups' ? 'group' : 'section';
const allSegmentsText =
segments.type === 'none' ? 'N/A' : `All ${segmentsName}`;

return (
<MultiSelect
aria-label={`Select ${segmentsName}`}
containerClasses="!w-auto min-w-[180px]"
value={segments.selectedIds}
onChange={newSegmentIds => segments.onChange(newSegmentIds)}
disabled={segments.entries.length === 0}
buttonContent={
segments.selectedIds.length === 0 ? (
<>All {segmentsName}</>
<>{allSegmentsText}</>
) : segments.selectedIds.length === 1 ? (
segments.entries.find(
s => s.h_authority_provided_id === segments.selectedIds[0],
Expand All @@ -152,7 +157,7 @@ function SegmentsMultiSelect({ segments }: { segments: SegmentsSelection }) {
data-testid="segments-select"
>
<MultiSelect.Option value={undefined}>
All {segmentsName}
{allSegmentsText}
</MultiSelect.Option>
{segments.entries.map(entry => (
<MultiSelect.Option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,30 +432,27 @@ describe('AssignmentActivity', () => {
assert.isUndefined(filters.prop('segments'));
});

[{}, { sections: [] }, { groups: [] }].forEach(assignmentExtra => {
it('sets no segments when assignment has no groups or sections', () => {
setUpFakeUseAPIFetch({
...activeAssignment,
...assignmentExtra,
auto_grading_config: {},
});

const wrapper = createComponent();
const filters = wrapper.find('DashboardActivityFilters');

assert.isUndefined(filters.prop('segments'));
});
});

[
{
assignmentExtra: { sections: [{}, {}] },
expectedType: 'sections',
},
{
assignmentExtra: { sections: [] },
expectedType: 'sections',
},
{
assignmentExtra: { groups: [{}, {}, {}] },
expectedType: 'groups',
},
{
assignmentExtra: { groups: [] },
expectedType: 'groups',
},
{
assignmentExtra: {},
expectedType: 'none',
},
].forEach(({ assignmentExtra, expectedType }) => {
it('sets type of segment based on assignment data fields', () => {
setUpFakeUseAPIFetch({
Expand All @@ -469,7 +466,7 @@ describe('AssignmentActivity', () => {
const segments = filters.prop('segments');

assert.equal(segments.type, expectedType);
assert.equal(segments.entries, assignmentExtra[expectedType]);
assert.deepEqual(segments.entries, assignmentExtra[expectedType] ?? []);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,19 @@ describe('DashboardActivityFilters', () => {
assert.deepEqual(select.prop('value'), selectedIds);
});

[
{ entries: [], shouldBeDisabled: true },
{ entries: ['foo', 'bar'], shouldBeDisabled: false },
].forEach(({ entries, shouldBeDisabled }) => {
it('disables segments filter when entries are empty', () => {
const wrapper = createComponentWithSegments({ entries });
assert.equal(
getSegmentsSelect(wrapper).prop('disabled'),
shouldBeDisabled,
);
});
});

it('invokes onChange callback', () => {
const wrapper = createComponentWithSegments();
const select = getSegmentsSelect(wrapper);
Expand Down Expand Up @@ -565,6 +578,11 @@ describe('DashboardActivityFilters', () => {
segmentsConfig: { type: 'sections' },
expectedButtonContent: 'All sections',
},
// "None" type
{
segmentsConfig: { type: 'none' },
expectedButtonContent: 'N/A',
},
// 1 known selected item
{
segmentsConfig: {
Expand Down

0 comments on commit 42e22a7

Please sign in to comment.