Skip to content
Open
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
Binary file added docs/images/config_store.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions docs/users/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,22 @@ _Note: Importing replaces the current workspace without asking. Save first if yo

---

## Config Store

The config store saves a workspace to the server and gives you a link to share it, instead of a `.trc.json` file.

- Click the **Config Store** icon in the header to open it.
- **Save & copy share link** saves the current workspace and copies a link to your clipboard. Anyone with the link gets the same plots, axes, traces, styles, time ranges, and theme.
- **Saved configs** lists what's been saved, newest first. Use **Search** to filter the list by name. Each row has **Load**, **Rename**, copy-link, and delete actions.

<div style="text-align:center; margin:1.5rem 0;">
<a class="glightbox" href="../images/config_store.png"><img src="../images/config_store.png" alt="The Config Store modal, with the search field above the saved configs list" style="width:70%; border-radius:0.5rem;"></a>
</div>

_Note: The list shows at most 200 configs. If there are more, the header says so (e.g. "showing 200 of 340") — use **Search** to find a config past that cutoff._

---

## Export and Print

- **Export CSV** — downloads one CSV file per plot, named after the plot title. Each row has the PV name, the time (in nanoseconds and as a date), and the value. Archive and formula data are included; traces with only live data are not. For ranges longer than 30 minutes, the archive values are the averaged bins shown on the plot.
Expand Down
40 changes: 40 additions & 0 deletions src/components/ConfigStoreModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,46 @@ describe('ConfigStoreModal', () => {
);
});

it('debounces search input into a server-side listConfigs search query', async () => {
vi.mocked(listConfigs).mockResolvedValue({
results: [listedConfig],
continuationToken: null,
totalCount: 1,
});
renderModal();
await screen.findByText('test-config');
vi.mocked(listConfigs).mockClear();

fireEvent.change(screen.getByRole('searchbox', { name: 'Search saved configs' }), {
target: { value: 'klystron' },
});

await waitFor(() =>
expect(listConfigs).toHaveBeenCalledWith(expect.objectContaining({ search: 'klystron' }))
);
});

it('shows a search-specific empty state when a query has no matches', async () => {
vi.mocked(listConfigs).mockResolvedValueOnce({
results: [listedConfig],
continuationToken: null,
totalCount: 1,
});
renderModal();
await screen.findByText('test-config');

vi.mocked(listConfigs).mockResolvedValue({
results: [],
continuationToken: null,
totalCount: 0,
});
fireEvent.change(screen.getByRole('searchbox', { name: 'Search saved configs' }), {
target: { value: 'no-such-config' },
});

await screen.findByText('No configs match your search.');
});

it('aborts a pending load when the modal unmounts', async () => {
vi.mocked(listConfigs).mockResolvedValue({
results: [listedConfig],
Expand Down
37 changes: 34 additions & 3 deletions src/components/ConfigStoreModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
StructuredListBody,
StructuredListRow,
StructuredListCell,
Search,
} from '@carbon/react';
import { Copy, TrashCan, Renew } from '@carbon/icons-react';

Expand Down Expand Up @@ -49,6 +50,10 @@ interface ConfigStoreModalProps {
// silently hidden; real paging is slaclab/react-trace#80.
const PAGE_SIZE = 200;

// Delay before a search keystroke triggers a refetch, so typing doesn't fire
// a request per character.
const SEARCH_DEBOUNCE_MS = 300;

// Marks the delete confirmation, which opens as a second modal over the store.
// The store's Carbon focus wrap treats focus leaving for an element outside it
// as Tab-past-the-end and pulls it back to its own first button. Listing this
Expand Down Expand Up @@ -95,6 +100,9 @@ export function ConfigStoreModal({
const [configs, setConfigs] = useState<ConfigDTO[]>([]);
const [totalCount, setTotalCount] = useState<number | null>(null);
const [listing, setListing] = useState(false);
const [search, setSearch] = useState('');
// Debounced so `refresh` (and the fetch it fires) doesn't recreate on every keystroke.
const [debouncedSearch, setDebouncedSearch] = useState('');
// Slug currently undergoing a row action (delete/load), to disable its buttons.
const [busySlug, setBusySlug] = useState<string | null>(null);
const [deleteTarget, setDeleteTarget] = useState<ConfigDTO | null>(null);
Expand All @@ -113,7 +121,10 @@ export function ConfigStoreModal({
setError(null);
setListing(true);
try {
const page = await listConfigs({ pageSize: PAGE_SIZE });
const page = await listConfigs({
pageSize: PAGE_SIZE,
search: debouncedSearch.trim() || undefined,
});
if (gen !== refreshGen.current) return;
// Magpie orders by its (random UUID) primary key, so sort here to get a
// predictable newest-first list. See slaclab/canopy#90 for the server-side
Expand All @@ -130,12 +141,18 @@ export function ConfigStoreModal({
} finally {
if (gen === refreshGen.current) setListing(false);
}
}, []);
}, [debouncedSearch]);

useEffect(() => {
if (open) void Promise.resolve().then(refresh);
}, [open, refresh]);

// Debounce search keystrokes before they reach `debouncedSearch` (and thus `refresh`).
useEffect(() => {
const timer = setTimeout(() => setDebouncedSearch(search), SEARCH_DEBOUNCE_MS);
return () => clearTimeout(timer);
}, [search]);

useEffect(
() => () => {
loadAbortRef.current?.abort();
Expand Down Expand Up @@ -339,10 +356,24 @@ export function ConfigStoreModal({
/>
</div>

<Search
id="config-search"
labelText="Search saved configs"
placeholder="Search by name…"
size="sm"
value={search}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSearch(e.target.value)}
onClear={() => setSearch('')}
/>

{listing ? (
<InlineLoading description="Loading configs…" />
) : configs.length === 0 ? (
<p style={{ color: 'var(--cds-text-secondary)' }}>No saved configs yet.</p>
<p style={{ color: 'var(--cds-text-secondary)' }}>
{debouncedSearch.trim()
? 'No configs match your search.'
: 'No saved configs yet.'}
</p>
) : (
<StructuredListWrapper isCondensed>
<StructuredListHead>
Expand Down
Loading