@bfrs/agentic-components 0.6.7 → 0.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1756,7 +1756,8 @@ Use `TableViewSelector` with `TableSaveView` when a list page needs named saved
1756
1756
 
1757
1757
  ```tsx
1758
1758
  const screenName = "orders.list";
1759
- const saveCurrentView = createLocalSaveView(screenName);
1759
+ const saveApi = useMemo(() => ({ baseUrl: import.meta.env.VITE_PLATFORM_BASE_URL, viewType: "orders", tab: "all" }), []);
1760
+ const { views } = useSavedViews(screenName);
1760
1761
 
1761
1762
  <ListPageLayout
1762
1763
  title="Orders"
@@ -1764,6 +1765,7 @@ const saveCurrentView = createLocalSaveView(screenName);
1764
1765
  <>
1765
1766
  <TableViewSelector
1766
1767
  screenName={screenName}
1768
+ saveApi={saveApi}
1767
1769
  onValueChange={(_, view) => {
1768
1770
  if (!view) return;
1769
1771
  setVisibleColumnIds(view.columns.filter((column) => column.visible).map((column) => column.key));
@@ -1772,12 +1774,14 @@ const saveCurrentView = createLocalSaveView(screenName);
1772
1774
  />
1773
1775
  <Select size="sm" value={status} onValueChange={setStatus} options={statusOptions} />
1774
1776
  <TableSaveView
1777
+ screenName={screenName}
1778
+ saveApi={saveApi}
1775
1779
  viewType={screenName}
1776
1780
  columns={visibilityColumns}
1777
1781
  visibleColumnIds={visibleColumnIds}
1778
1782
  filters={filters}
1779
1783
  filtersCount={filters.length}
1780
- onSave={saveCurrentView}
1784
+ onSaved={({ view }) => setActiveViewId(view.view_id)}
1781
1785
  />
1782
1786
  </>
1783
1787
  }
@@ -1785,7 +1789,7 @@ const saveCurrentView = createLocalSaveView(screenName);
1785
1789
  />
1786
1790
  ```
1787
1791
 
1788
- Use `createLocalViewStore(screenName, { saveApi })` instead of `createLocalSaveView(screenName)` when save should call the library API adapter first and then mirror the saved view in localStorage. The selector's rename/delete/primary actions remain local unless you pass a custom `ViewStore`.
1792
+ Pass `saveApi` directly to `TableViewSelector` and `TableSaveView` when saved views should use the Shiprocket endpoints and keep localStorage as the mirror/fallback. App code should not call the saved-view list/get/update/delete helpers directly; those calls are owned by the selector. `TableSaveView` owns create/save when `screenName` and `saveApi` are supplied, then fires `onSaved` so the app can update its selected-view state. Use `useSavedViews(screenName)` when app state needs a read-only list of the locally mirrored views. `saveApi.viewType` maps to the backend `view_type`, and `saveApi.tab` maps to the `tab` query/body scope. Backend reads/mutations run only when both are explicitly supplied, which avoids sending UI-only `screenName` values such as `"orders.list"` as API `view_type`. The built-in component adapter calls `GET listviews`, `GET getview`, `PUT updateview`, and `DELETE deleteview`; API rows are merged into localStorage so local-only saved views remain visible. Because the update/delete endpoints do not take `view_id`, rename/delete/reset call the backend only for the primary view for that `view_type` + `tab`. `createLocalViewStore` and `createLocalSaveView` remain localStorage helpers for local-only saved views.
1789
1793
 
1790
1794
  Column visibility still belongs in `TableToolbar`; keep that table-local save/discard flow separate from saved-view listing controls.
1791
1795
 
@@ -1805,7 +1809,7 @@ Column visibility still belongs in `TableToolbar`; keep that table-local save/di
1805
1809
  />
1806
1810
  ```
1807
1811
 
1808
- Angular custom-element consumers can use `<bfrs-table-view-selector>` and `<bfrs-table-save-view>` with the same `screen-name`. The selector emits `value-change`, `view-select`, `primary-view-change`, `rename-view`, `delete-view`, and `reset-saved-filters`; `bfrs-table-save-view` emits `saved-view` after a successful save.
1812
+ Angular custom-element consumers can use `<bfrs-table-view-selector>` and `<bfrs-table-save-view>` with the same `screen-name`. Pass `saveApi` through the element `props` object to enable the same backend + localStorage behavior. The selector emits `value-change`, `view-select`, `primary-view-change`, `rename-view`, `delete-view`, and `reset-saved-filters`; `bfrs-table-save-view` emits `saved-view` after a successful save.
1809
1813
 
1810
1814
  Custom-element DataTable action cells must be declarative because Angular/HTML cannot pass React `cell` functions through JSON. Use `cellType: "button"` for one inline button, `cellType: "buttons"` for multiple inline buttons, or `cellType: "actions"` for an action menu. Action clicks emit `cell-action` with `{ actionId, columnId, row, rowId, rowIndex }` and do not trigger `row-click`.
1811
1815
 
@@ -191,6 +191,7 @@ export type SavedView = {
191
191
  view_id: string;
192
192
  name: string;
193
193
  view_type: ViewType;
194
+ tab?: string;
194
195
  columns: ViewColumn[];
195
196
  filters: ViewFilter[];
196
197
  priority: number;
@@ -199,6 +200,7 @@ export type SavedView = {
199
200
  };
200
201
  export type SaveViewPayload = {
201
202
  view_type: ViewType;
203
+ tab?: string;
202
204
  name: string;
203
205
  columns: ViewColumn[];
204
206
  filters?: ViewFilter[];
@@ -1,5 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { TableColumnVisibilityColumn, ViewFilter, ViewType, SaveViewPayload, SaveViewResult } from './DataTable.types';
3
+ import { SaveViewApiConfig } from './saveViewApi';
3
4
  export type TableSaveViewProps = {
4
5
  open?: boolean;
5
6
  defaultOpen?: boolean;
@@ -27,17 +28,23 @@ export type TableSaveViewProps = {
27
28
  filters?: ViewFilter[];
28
29
  /** View priority. Higher wins on resolution. Defaults to 0. */
29
30
  priority?: number;
31
+ /** Screen key for component-owned persistence through the saved-view store. */
32
+ screenName?: string;
33
+ /** Component-owned backend config used when `screenName` is supplied. */
34
+ saveApi?: SaveViewApiConfig;
30
35
  cancelLabel?: ReactNode;
31
36
  saveLabel?: ReactNode;
32
37
  onCancel?: () => void;
33
38
  /**
34
39
  * Called on submit with the API-formatted payload.
35
- * Return a `SaveViewResult` (e.g. from `saveView()`) to trigger `onSaved`
36
- * and allow the component to detect duplicates.
40
+ * Return a `SaveViewResult` to trigger `onSaved` and allow the component to
41
+ * detect duplicates.
37
42
  */
38
43
  onSave?: (payload: SaveViewPayload) => void | Promise<SaveViewResult | void>;
39
44
  /** Fires after a successful save with the resolved view and duplicate flag. */
40
45
  onSaved?: (result: SaveViewResult) => void;
46
+ /** Fires when the save callback or component-owned store rejects. */
47
+ onError?: (error: unknown) => void;
41
48
  loading?: boolean;
42
49
  disabled?: boolean;
43
50
  closeOnSave?: boolean;
@@ -47,4 +54,4 @@ export type TableSaveViewProps = {
47
54
  className?: string;
48
55
  triggerClassName?: string;
49
56
  };
50
- export declare function TableSaveView({ open, defaultOpen, onOpenChange, onClose, trigger, triggerLabel, title, description, viewName, defaultViewName, onViewNameChange, viewNameLabel, viewNamePlaceholder, appliedLabel, appliedSettings, appliedSettingLabels, columns, visibleColumnIds, hiddenColumnCount, filtersCount, viewType, filters, priority, cancelLabel, saveLabel, onCancel, onSave, onSaved, loading, disabled, closeOnSave, closeOnOverlayClick, closeOnEscape, preventClose, className, triggerClassName }: TableSaveViewProps): import("react/jsx-runtime").JSX.Element;
57
+ export declare function TableSaveView({ open, defaultOpen, onOpenChange, onClose, trigger, triggerLabel, title, description, viewName, defaultViewName, onViewNameChange, viewNameLabel, viewNamePlaceholder, appliedLabel, appliedSettings, appliedSettingLabels, columns, visibleColumnIds, hiddenColumnCount, filtersCount, viewType, filters, priority, screenName, saveApi, cancelLabel, saveLabel, onCancel, onSave, onSaved, onError, loading, disabled, closeOnSave, closeOnOverlayClick, closeOnEscape, preventClose, className, triggerClassName }: TableSaveViewProps): import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,14 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { SavedView } from './DataTable.types';
3
3
  import { ViewStore } from './viewStore';
4
+ import { SaveViewApiConfig } from './saveViewApi';
4
5
  export type TableViewSelectorProps = {
5
6
  /** Free-form screen key used for localStorage scoping, e.g. "orders_new". */
6
7
  screenName: string;
7
- /** Optional store adapter. Defaults to localStorage via createLocalViewStore(screenName). */
8
+ /** Optional store adapter. Defaults to the component-owned local/API store for this screen. */
8
9
  store?: ViewStore;
10
+ /** Optional API adapter config for the default local store. Ignored when `store` is supplied. */
11
+ saveApi?: SaveViewApiConfig;
9
12
  /** Controlled selected view id. Selection is separate from the persisted primary view. */
10
13
  value?: string | null;
11
14
  /** Initial selected view id for uncontrolled mode. Falls back to the store's primary view. */
@@ -41,4 +44,4 @@ export type TableViewSelectorProps = {
41
44
  contentClassName?: string;
42
45
  actionMenuClassName?: string;
43
46
  };
44
- export declare function TableViewSelector({ screenName, store, value, defaultValue, selectPrimaryByDefault, onValueChange, onViewSelect, onPrimaryViewChange, onRenameView, onDeleteView, onResetSavedFilters, onError, triggerLabel, placeholder, viewsLabel, emptyLabel, loadingLabel, resetLabel, setPrimaryLabel, renameLabel, deleteLabel, renameTitle, renameDescription, renameInputLabel, renameCancelLabel, renameSaveLabel, size, disabled, className, triggerClassName, contentClassName, actionMenuClassName }: TableViewSelectorProps): import("react/jsx-runtime").JSX.Element | null;
47
+ export declare function TableViewSelector({ screenName, store, saveApi, value, defaultValue, selectPrimaryByDefault, onValueChange, onViewSelect, onPrimaryViewChange, onRenameView, onDeleteView, onResetSavedFilters, onError, triggerLabel, placeholder, viewsLabel, emptyLabel, loadingLabel, resetLabel, setPrimaryLabel, renameLabel, deleteLabel, renameTitle, renameDescription, renameInputLabel, renameCancelLabel, renameSaveLabel, size, disabled, className, triggerClassName, contentClassName, actionMenuClassName }: TableViewSelectorProps): import("react/jsx-runtime").JSX.Element | null;
@@ -10,5 +10,7 @@ export * from './TableBulkActions';
10
10
  export * from './TableColumnVisibility';
11
11
  export * from './TableSaveView';
12
12
  export * from './TableViewSelector';
13
- export * from './saveViewApi';
14
- export * from './viewStore';
13
+ export * from './useSavedViews';
14
+ export type { SaveViewApiConfig, SaveViewHeaderSource, SaveViewTokenSource } from './saveViewApi';
15
+ export { createLocalSaveView, createLocalViewStore } from './viewStore';
16
+ export type { LocalViewStoreOptions, RemoteSaveView, ViewStore } from './viewStore';
@@ -1,4 +1,4 @@
1
- import { SaveViewPayload, SaveViewResult } from './DataTable.types';
1
+ import { SavedView, SaveViewPayload, SaveViewResult, ViewType } from './DataTable.types';
2
2
  export type SaveViewHeaderSource = Record<string, string | null | undefined> | (() => Record<string, string | null | undefined>);
3
3
  export type SaveViewTokenSource = string | null | undefined | (() => string | null | undefined);
4
4
  export type SaveViewApiConfig = {
@@ -8,8 +8,22 @@ export type SaveViewApiConfig = {
8
8
  * `https://platform.shiprocket.in/api/v1/`.
9
9
  */
10
10
  baseUrl?: string;
11
- /** Endpoint path. Defaults to `api/v1/saveview` and de-dupes `/api/v1`. */
11
+ /**
12
+ * Back-compat endpoint override for direct saves. Prefer `saveEndpoint` for
13
+ * new code. Component-owned saved-view flows only POST when `endpoint`,
14
+ * `saveEndpoint`, or `remoteSave` is supplied explicitly.
15
+ */
12
16
  endpoint?: string;
17
+ /** Optional create/save endpoint. Omit when save should remain localStorage-only. */
18
+ saveEndpoint?: string;
19
+ listEndpoint?: string;
20
+ getEndpoint?: string;
21
+ updateEndpoint?: string;
22
+ deleteEndpoint?: string;
23
+ /** Backend view_type. Defaults to the save payload's view_type. */
24
+ viewType?: ViewType;
25
+ /** Backend tab scope, e.g. "all" or "new". Added to query/body when present. */
26
+ tab?: string;
13
27
  /** Auth token or lazy token reader. Defaults to common Shiprocket localStorage keys. */
14
28
  token?: SaveViewTokenSource;
15
29
  /** Extra headers or lazy header reader. */
@@ -26,13 +40,15 @@ export type SaveViewOptions = SaveViewApiConfig & {
26
40
  * Saves a user view. Returns the saved view and whether it was a duplicate.
27
41
  * Throws on HTTP error (auth, validation, network).
28
42
  */
29
- export declare function saveView({ baseUrl, endpoint, token, headers, credentials, fetcher, payload, }: SaveViewOptions): Promise<SaveViewResult>;
43
+ export declare function saveView({ baseUrl, endpoint, saveEndpoint, viewType, tab, token, headers, credentials, fetcher, payload, }: SaveViewOptions): Promise<SaveViewResult>;
44
+ export declare function listViews(config: SaveViewApiConfig): Promise<SavedView[]>;
45
+ export declare function getView(config: SaveViewApiConfig): Promise<SavedView | null>;
46
+ export declare function updateView(config: SaveViewApiConfig & {
47
+ payload: SaveViewPayload;
48
+ }): Promise<SavedView | null>;
49
+ export declare function deleteView(config: SaveViewApiConfig): Promise<void>;
30
50
  /**
31
51
  * Creates a pre-configured save function bound to a base URL and token.
32
52
  * The returned function matches the `TableSaveView.onSave` signature directly.
33
- *
34
- * @example
35
- * const save = createSaveView({ baseUrl: import.meta.env.VITE_AGENTIC_BASE_URL });
36
- * <TableSaveView onSave={save} onSaved={...} />
37
53
  */
38
54
  export declare function createSaveView(config?: SaveViewApiConfig): (payload: SaveViewPayload) => Promise<SaveViewResult>;
@@ -0,0 +1,23 @@
1
+ import { SavedView } from './DataTable.types';
2
+ import { ViewStore } from './viewStore';
3
+ export type UseSavedViewsOptions = {
4
+ /** Optional read adapter. Defaults to the localStorage-backed store for `screenName`. */
5
+ store?: ViewStore;
6
+ /** Set false to keep the hook idle while a screen key is still resolving. */
7
+ enabled?: boolean;
8
+ };
9
+ export type UseSavedViewsResult = {
10
+ views: SavedView[];
11
+ primaryView: SavedView | null;
12
+ loading: boolean;
13
+ error: unknown;
14
+ refresh: () => Promise<SavedView[]>;
15
+ };
16
+ /**
17
+ * Read saved views for a screen without exposing the saved-view HTTP helpers.
18
+ *
19
+ * Components that own the backend sync write into the same screen-scoped local
20
+ * store; this hook subscribes to that store so consumers can react to the latest
21
+ * mirrored list.
22
+ */
23
+ export declare function useSavedViews(screenName: string | undefined, options?: UseSavedViewsOptions): UseSavedViewsResult;
@@ -35,7 +35,13 @@ export type LocalViewStoreOptions = {
35
35
  * only mirrors the view into localStorage after the remote save succeeds.
36
36
  */
37
37
  remoteSave?: RemoteSaveView;
38
- /** Convenience API config that uses the library `saveView()` implementation. */
38
+ };
39
+ export type TableViewSelectorStoreOptions = LocalViewStoreOptions & {
40
+ /**
41
+ * Component-owned API config for Shiprocket saved-view endpoints. This is
42
+ * intentionally used only by TableViewSelector and custom elements so app
43
+ * code does not call saved-view APIs directly.
44
+ */
39
45
  saveApi?: SaveViewApiConfig;
40
46
  };
41
47
  /**
@@ -43,10 +49,10 @@ export type LocalViewStoreOptions = {
43
49
  * Views for a screen live under `bfrs.savedViews.<screenName>`.
44
50
  */
45
51
  export declare function createLocalViewStore(screenName: string, options?: LocalViewStoreOptions): ViewStore;
52
+ export declare function createTableViewSelectorStore(screenName: string, options?: TableViewSelectorStoreOptions): ViewStore;
46
53
  /**
47
54
  * A pre-bound save function for a screen's local store, matching the
48
- * `TableSaveView.onSave` signature — the localStorage counterpart of
49
- * `createSaveView`.
55
+ * `TableSaveView.onSave` signature.
50
56
  *
51
57
  * @example
52
58
  * const onSave = createLocalSaveView("orders_new");