Skip to content
Merged
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
89 changes: 89 additions & 0 deletions apps/csm-portal/webapp/src/components/MultiSelectField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import { Autocomplete, Checkbox, Chip, ListItemText, TextField } from "@wso2/oxygen-ui";
import type * as React from "react";
import type { JSX } from "react";

export interface MultiSelectFieldProps<T extends string> {
id: string;
label: string;
values: T[];
options: { value: T; label: string }[];
onChange: (next: T[]) => void;
disabled?: boolean;
}

/**
* Autocomplete-based multi-select for a fixed, small set of options (e.g. an
* enum) — selected values render as chips, options are type-to-search +
* checkboxes. Pairs with {@link SearchableMultiSelect} for larger/dynamic
* option lists. Extracted from `CasesFilterBar.tsx` so other feature filter
* bars (e.g. time cards) can reuse the same look and behavior.
*/
export default function MultiSelectField<T extends string>({
id,
label,
values,
options,
onChange,
disabled,
}: MultiSelectFieldProps<T>): JSX.Element {
const selected = options.filter((o) => values.includes(o.value));
return (
<Autocomplete<{ value: T; label: string }, true>
multiple
size="small"
id={id}
disabled={disabled}
options={options}
value={selected}
disableCloseOnSelect
getOptionLabel={(o) => o.label}
isOptionEqualToValue={(o, v) => o.value === v.value}
onChange={(_event, next) => onChange(next.map((o) => o.value))}
renderTags={(value, getTagProps) =>
value.map((option, index) => {
const { key, ...tagProps } = getTagProps({ index });
return (
<Chip key={key} size="small" label={option.label} {...tagProps} />
);
})
}
renderOption={(props, option, { selected: isSelected }) => {
const { key, ...liProps } = props as React.HTMLAttributes<HTMLLIElement> & {
key: string;
};
return (
<li key={key} {...liProps} style={{ paddingTop: 2, paddingBottom: 2 }}>
<Checkbox size="small" checked={isSelected} sx={{ mr: 1, p: 0.25 }} />
<ListItemText
primary={option.label}
slotProps={{ primary: { style: { fontSize: 13 } } }}
/>
</li>
);
}}
renderInput={(params) => (
<TextField
{...params}
label={label}
placeholder={values.length ? undefined : "Select…"}
/>
)}
/>
);
}
131 changes: 131 additions & 0 deletions apps/csm-portal/webapp/src/components/SearchableMultiSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import { Autocomplete, Checkbox, Chip, ListItemText, TextField } from "@wso2/oxygen-ui";
import type * as React from "react";
import type { JSX } from "react";
Comment thread
Hesara2003 marked this conversation as resolved.
Resolved

export interface SearchableMultiSelectProps {
id: string;
label: string;
placeholder?: string;
values: string[];
options: string[];
/** Optional renderer for option labels (e.g. an `@me` sentinel → "Me"). */
formatOption?: (value: string) => string;
/** Optional secondary line shown beneath each option (e.g. email). */
getOptionSecondary?: (value: string) => string | undefined;
/** Optional filter against synthetic text (e.g. include email in the query). */
getOptionSearchText?: (value: string) => string;
onChange: (next: string[]) => void;
disabled?: boolean;
}

/**
* Multi-select autocomplete. Users type to filter the option list and
* select multiple. Picked values render as removable chips inside the field.
* Internally a thin wrapper over MUI Autocomplete so we keep oxygen-ui
* theming via the re-exported components. Extracted from `CasesFilterBar.tsx`
* so other feature filter bars (e.g. time cards) can reuse the same look and
* behavior instead of a plain free-text field.
*/
export default function SearchableMultiSelect({
id,
label,
placeholder,
values,
options,
formatOption,
getOptionSecondary,
getOptionSearchText,
onChange,
disabled,
}: SearchableMultiSelectProps): JSX.Element {
const format = formatOption ?? ((v: string) => v);
const searchText = getOptionSearchText ?? format;
return (
<Autocomplete
multiple
size="small"
disabled={disabled}
id={id}
options={options}
value={values}
onChange={(_event, next) => onChange(next as string[])}
disableCloseOnSelect
// MUI's own available-space heuristic sometimes flips the list above
// the field even when there's clearly room below (e.g. sitting above a
// data table) — pin it open downward instead of guessing.
slotProps={{
popper: {
placement: "bottom-start",
modifiers: [{ name: "flip", enabled: false }],
},
}}
getOptionLabel={(opt) => format(opt as string)}
isOptionEqualToValue={(opt, val) => opt === val}
filterOptions={(opts, state) => {
const q = state.inputValue.trim().toLowerCase();
if (!q) return opts;
return opts.filter((o) => searchText(o as string).toLowerCase().includes(q));
}}
renderTags={(value, getTagProps) =>
value.map((option, index) => {
const { key, ...tagProps } = getTagProps({ index });
return (
<Chip
key={key}
size="small"
label={format(option as string)}
{...tagProps}
/>
);
})
}
renderOption={(props, option, { selected }) => {
const { key, ...liProps } = props as React.HTMLAttributes<HTMLLIElement> & {
key: string;
};
const primary = format(option as string);
const secondary = getOptionSecondary?.(option as string);
return (
<li key={key} {...liProps} style={{ paddingTop: 2, paddingBottom: 2 }}>
<Checkbox
size="small"
checked={selected}
sx={{ mr: 1, p: 0.25 }}
/>
<ListItemText
primary={primary}
secondary={secondary}
slotProps={{
primary: { style: { fontSize: 13 } },
secondary: { style: { fontSize: 11 } },
}}
/>
</li>
);
}}
renderInput={(params) => (
<TextField
{...params}
label={label}
placeholder={values.length ? undefined : placeholder ?? "Type to search…"}
/>
)}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
// under the License.

import {
Autocomplete,
Box,
Button,
Checkbox,
Chip,
Dialog,
DialogActions,
DialogContent,
Expand Down Expand Up @@ -49,7 +46,6 @@ import {
X,
} from "@wso2/oxygen-ui-icons-react";
import { useMemo, useState, type JSX } from "react";
import type * as React from "react";
import type {
CaseState,
Severity,
Expand All @@ -76,6 +72,7 @@ import {
CASE_TYPE_LABEL,
} from "@features/csm-cases/utils/caseType";
import AsyncProjectMultiSelect from "@features/csm-cases/components/AsyncProjectMultiSelect";
import MultiSelectField from "@components/MultiSelectField";
import AsyncAssigneeMultiSelect from "@features/csm-cases/components/AsyncAssigneeMultiSelect";
import ProductNameMultiSelect from "@features/csm-cases/components/ProductNameMultiSelect";

Expand Down Expand Up @@ -164,71 +161,6 @@ const PRIMARY_STATES: CaseState[] = [
"closed",
];

interface MultiSelectFieldProps<T extends string> {
id: string;
label: string;
values: T[];
options: { value: T; label: string }[];
onChange: (next: T[]) => void;
disabled?: boolean;
}

function MultiSelectField<T extends string>({
id,
label,
values,
options,
onChange,
disabled,
}: MultiSelectFieldProps<T>): JSX.Element {
// Autocomplete-based multi-select: selected values render as chips and the
// options are type-to-search + checkboxes — matching the product filter.
const selected = options.filter((o) => values.includes(o.value));
return (
<Autocomplete<{ value: T; label: string }, true>
multiple
size="small"
id={id}
disabled={disabled}
options={options}
value={selected}
disableCloseOnSelect
getOptionLabel={(o) => o.label}
isOptionEqualToValue={(o, v) => o.value === v.value}
onChange={(_event, next) => onChange(next.map((o) => o.value))}
renderTags={(value, getTagProps) =>
value.map((option, index) => {
const { key, ...tagProps } = getTagProps({ index });
return (
<Chip key={key} size="small" label={option.label} {...tagProps} />
);
})
}
renderOption={(props, option, { selected: isSelected }) => {
const { key, ...liProps } = props as React.HTMLAttributes<HTMLLIElement> & {
key: string;
};
return (
<li key={key} {...liProps} style={{ paddingTop: 2, paddingBottom: 2 }}>
<Checkbox size="small" checked={isSelected} sx={{ mr: 1, p: 0.25 }} />
<ListItemText
primary={option.label}
slotProps={{ primary: { style: { fontSize: 13 } } }}
/>
</li>
);
}}
renderInput={(params) => (
<TextField
{...params}
label={label}
placeholder={values.length ? undefined : "Select…"}
/>
)}
/>
);
}

export default function CasesFilterBar({
filters,
onChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ export function usePostTimeCard(): UseMutationResult<
isBillable: input.billable,
issueComplexity: input.issueComplexity,
workLogComment: input.workLogComment,
// The backend's hour fields are integers (confirmed live: a 0.5
// value is rejected with 400) even though the form logs quarter-hour
// increments — round each bucket to the nearest whole hour here, at
// the API boundary, so the FE keeps its finer-grained display.
// The backend's time fields are whole minutes (confirmed:
// entity-service's own validation helper is named
// `nonNegativeMinutes`, and a real pre-existing card's `totalTime` of
// 150 only makes sense as ~2.5h of work in one entry, not 150 hours)
// — the form collects minutes directly now, so this is a defensive
// round only, not a unit conversion.
timeAnalyzing: Math.round(input.breakdown.analysisDebugging),
timeSettingUp: Math.round(input.breakdown.settingUp),
timeReproducingDebugging: Math.round(input.breakdown.reproduce),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ export function invalidateTimecards(queryClient: QueryClient): void {
}
}

/** Map the backend's `TimeCardView` to the portal's `CsmTimeCard`. */
/**
* Map the backend's `TimeCardView` to the portal's `CsmTimeCard`. `totalTime`
* is already whole minutes on the wire (see `usePostTimeCard`'s note on why),
* which is also the unit the portal displays throughout — a direct
* passthrough, no conversion needed.
*/
export function mapTimeCard(v: BeTimeCardView): CsmTimeCard {
return {
id: v.id,
Expand All @@ -103,7 +108,7 @@ export function mapTimeCard(v: BeTimeCardView): CsmTimeCard {
userName: v.user?.name ?? "—",
state: v.state,
billable: v.hasBillable,
totalHours: v.totalTime,
totalMinutes: v.totalTime,
approvedById: v.approvedBy?.id,
approvedByName: v.approvedBy?.name,
};
Expand Down
Loading