Skip to content

Add reusable template filter component to workflows-lib-shared - #1853

Open
hazdl wants to merge 6 commits into
mainfrom
hz/filter-component-template
Open

hazdl wants to merge 6 commits into
mainfrom
hz/filter-component-template

Conversation

@hazdl

@hazdl hazdl commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Analysis PlatformAP-1408

Summary

Implemented a reusable multi-select filter component using MUI Select, following the Figma design.
Added configurable labels, compact selection counts, and Clear all functionality.
Implemented controlled state through props, keeping the component independent of GraphQL, Apollo, and Relay.
Added Storybook examples and component documentation.

Testing

Added unit tests covering selection, deselection, multiple selections, Clear all, and controlled state.
All 10 component tests passing.
Verified the shared library builds successfully.

@hazdl
hazdl requested a review from a team November 18, 2026 10:07
@hazdl
hazdl force-pushed the hz/filter-component-template branch 2 times, most recently from 2c935fe to c6ded63 Compare November 18, 2026 10:49

@Oli-Jones475 Oli-Jones475 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The component and tests look good! It will need to be rebased onto main though and the component should be moved (or copied) into the workflows-ui module since its for dashboard-2. Storybooks havent been set up in that moudle yet which is why copying it without the storybook might be a good idea

@JamesDoingStuff JamesDoingStuff left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked through the tests or tried using this yet, so I might have yet have more comments, but there's a few in the code to be getting on with

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this documentation be better in the storybook, so that it's accessible for users?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we should move.

@hazdl
hazdl force-pushed the hz/filter-component-template branch from c6ded63 to 000e2c2 Compare November 18, 2026 12:47
@hazdl

hazdl commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Oli, thanks! I've updated the branch with main and copied TemplateFilter and its tests into workflows-ui, leaving Storybook in workflows-lib-shared for now.

@Oli-Jones475

Copy link
Copy Markdown
Contributor

Oli, thanks! I've updated the branch with main and copied TemplateFilter and its tests into workflows-ui, leaving Storybook in workflows-lib-shared for now.

Thank you! Sorry for the nit pick but could we have TemplateFilter.tsx in lib/components/templates instead of lib/components/common. Same thing applies to the test file (tests/components/templates instead of tests/components)

Thank you!

@hazdl
hazdl force-pushed the hz/filter-component-template branch 5 times, most recently from bf77e4a to 86510c5 Compare November 20, 2026 18:05
@hazdl
hazdl force-pushed the hz/filter-component-template branch from 86510c5 to bfa9780 Compare November 20, 2026 18:39
@hazdl

hazdl commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

I am leaving until it's running fine in workflows-lib-share, then I will move to workflows-ui.

@JamesDoingStuff JamesDoingStuff left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple things to tidy up in the code, plus:

  • I think it would be better to add this solely to workflows-ui, which is where we want this component to live long-term. Adding TemplateFilter.stories.tsx to workflows-ui before #1854 shouldn't cause any issues and the workflows-lib-shared storybook isn't shown anywhere anyway, so it wouldn't be any better. If there's a reason it must be added to both, then the workflows-ui copy also needs updating for everything I've reviewed thus far (I've only put comments on the workflows-lib-shared one to avoid repeating myself)
  • Commit messages need a bit of tidying:
    • We should be consistent with commit scope, especially for feat or fix, as those show up in the changelog - I would suggest the component name in PascalCase e.g. feat(TemplateFilter)
    • Commits should only modify one package - split up changes to workflows-ui and workflows-lib-shared
    • Messages should be useful for people reading the changelog, so shouldn't reference things like review feedback
    • It's a little bit fuzzier, but I think I like the idea of calling storybook commits docs(RelevantComponent) to make it clear that it it's not actual component code. It means each new component should have a feat, a test and a docs commit. Open to pushback on this though.

label,
emptyLabel = "All ",
filterValues,
selectedTemplates,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can selectedTemplates be renamed too?

Comment on lines +173 to +179
{filterValues.map((template) => (
<MenuItem key={template} value={template}>
<Checkbox
checked={selectedTemplates.includes(template)}
size="small"
/>
<ListItemText primary={template} />

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

References to templates here should also be renamed

Comment on lines +16 to +65
const StoryTheme = ({
children,
mode,
}: {
children: React.ReactNode;
mode: "light" | "dark";
}) => {
return (
<ThemeProvider theme={DiamondDSTheme}>
<ThemeMode mode={mode}>{children}</ThemeMode>
</ThemeProvider>
);
};

const ThemeMode = ({
children,
mode,
}: {
children: React.ReactNode;
mode: "light" | "dark";
}) => {
const { setMode } = useColorScheme();

useEffect(() => {
setMode(mode);

// Synchronise Diamond Design System CSS variables.
document.documentElement.setAttribute("data-mode", mode);
}, [mode, setMode]);

return <>{children}</>;
};

const meta: Meta<typeof TemplateFilter> = {
title: "TemplateFilter",
component: TemplateFilter,
decorators: [
(Story, context) => {
console.log("Diamond mode:", context.globals.diamondMode);

return (
<StoryTheme
mode={context.globals.diamondMode === "dark" ? "dark" : "light"}
>
<Story />
</StoryTheme>
);
},
],
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #1854 I've included some code I pinched from SciReactUI that they use for dark/light mode switching in stories, so if that gets merged then this could be removed. The SRU version defines a decorator that gets used for all stories, rather than a component-specific one like this

Comment on lines +25 to +26
| `templates` | `string[]` | Available options displayed in the dropdown. |
| `selectedTemplates` | `string[]` | Currently selected values, controlled by the parent. |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to be updated to new names

Comment on lines +144 to +163
MenuProps={{
PaperProps: {
sx: {
bgcolor: "background.paper",
color: "text.primary",
},
},
}}
sx={{
bgcolor: "background.paper",
color: "text.primary",

"& .MuiSelect-select": {
color: "text.primary",
},

"& .MuiSelect-icon": {
color: "text.primary",
},
}}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Select, Paper and Menu should already be styled like this, so this shouldn't be necessary - perhaps it's just the storybook that lacks the Diamond theming? If so, that should be fixed by #1854


## Selection behaviour

The dropdown supports multiple selections without displaying checkboxes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs updating

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in https://diamondlightsource.slack.com/archives/C06N43M7JP3/p1795077722627219, please can we keep tests and stories with components? If you feel otherwise we can discuss

component: TemplateFilter,
decorators: [
(Story, context) => {
console.log("Diamond mode:", context.globals.diamondMode);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging message?

filterValues,
selectedTemplates,
onChange,
variant = "outlined",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the expected behaviour for the different variants? In my testing, standard makes the filter box shrink to the text height and filled/outlined just seem to affect the alignment of the text.

Also, it would also be good if the stories showed the variants

} from "@diamondlightsource/sci-react-ui";
import { TemplateFilter, type TemplateFilterProps } from "../lib/main";

const templates = [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs renaming

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants