Skip to content

Commit ae40cdc

Browse files
committed
Updated readme with new API's
1 parent ad86de3 commit ae40cdc

1 file changed

Lines changed: 96 additions & 4 deletions

File tree

README.md

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,14 @@ type CustomPluginConfigOptions =
264264
label?: string;
265265
}
266266
| {
267-
type: 'action-effect';
268-
name: string;
269-
label?: string;
270-
};
267+
type: 'action-effect';
268+
name: string;
269+
label?: string;
270+
}
271+
| {
272+
type: 'url-parameter';
273+
name: string;
274+
};
271275
```
272276
273277
</details>
@@ -404,6 +408,14 @@ A configurable action trigger to trigger actions in other elements within your w
404408
405409
A configurable action effect that can be triggered by other elements within your workbook
406410
411+
**URL Parameter**
412+
413+
A configurable URL parameter that can be read from and written to the browser's URL. This allows plugins to sync state with the URL for bookmarking and sharing.
414+
415+
Additional Fields
416+
417+
- `name : string` - The config ID used to access this URL parameter via the API
418+
407419
#### PluginInstance
408420
409421
```ts
@@ -488,6 +500,24 @@ interface PluginInstance<T> {
488500
callback: (input: WorkbookVariable) => void,
489501
): Unsubscriber;
490502
503+
/**
504+
* Allows users to subscribe to changes in the url parameter
505+
*/
506+
subscribeToUrlParameter(
507+
configId: string,
508+
callback: (input: UrlParameter) => void,
509+
): Unsubscriber;
510+
511+
/**
512+
* Gets the current value of a url parameter
513+
*/
514+
getUrlParameter(configId: string): UrlParameter;
515+
516+
/**
517+
* Setter for url parameter
518+
*/
519+
setUrlParameter(configId: string, value: string): void;
520+
491521
/**
492522
* @deprecated Use Action API instead
493523
* Allows users to subscribe to changes in the passed in interaction ID
@@ -727,6 +757,68 @@ array or multiple parameters
727757
function setVariableCallback(...values: unknown[]): void;
728758
```
729759
760+
#### useUrlParameter()
761+
762+
Returns a given URL parameter's value and a setter to update that URL parameter
763+
764+
```ts
765+
function useUrlParameter(
766+
configId: string,
767+
): [UrlParameter | undefined, (value: string) => void];
768+
```
769+
770+
Arguments
771+
772+
- `configId : string` - The config ID corresponding to the URL parameter
773+
774+
The returned setter function accepts a string value that will be set as the URL parameter value
775+
776+
```ts
777+
function setUrlParameterCallback(value: string): void;
778+
```
779+
780+
The URL parameter value has the following structure:
781+
782+
```ts
783+
interface UrlParameter {
784+
value: string;
785+
}
786+
```
787+
788+
Example
789+
790+
```ts
791+
const [urlParam, setUrlParam] = useUrlParameter('myParamId');
792+
793+
// Read the current value
794+
console.log(urlParam?.value); // e.g., "current-value"
795+
796+
// Update the URL parameter
797+
setUrlParam('new-value');
798+
```
799+
800+
Framework Agnostic Usage
801+
802+
You can also use the URL parameter API without React hooks:
803+
804+
```ts
805+
import { initialize } from '@sigmacomputing/plugin';
806+
807+
const client = initialize();
808+
809+
// Get current value
810+
const urlParam = client.config.getUrlParameter('myParamId');
811+
console.log(urlParam?.value);
812+
813+
// Set a new value
814+
client.config.setUrlParameter('myParamId', 'new-value');
815+
816+
// Subscribe to changes
817+
const unsubscribe = client.config.subscribeToUrlParameter('myParamId', (urlParam) => {
818+
console.log('URL parameter updated:', urlParam.value);
819+
});
820+
```
821+
730822
#### useInteraction()
731823
732824
Returns a given interaction's selection state and a setter to update that interaction

0 commit comments

Comments
 (0)