Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Interaction API, to be replaced by Actions API #18

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
50 changes: 0 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,6 @@ type CustomPluginConfigOptions =
name: string;
label?: string;
allowedTypes?: ControlType[];
}
| {
type: 'interaction';
name: string;
label?: string;
};
```

Expand Down Expand Up @@ -423,20 +418,6 @@ interface PluginInstance<T> {
*/
setVariable(id: string, ...values: unknown[]): void;

/**
* Getter for interaction selection state
*/
getInteraction(id: string): WorkbookSelection[];

/**
* Setter for interaction selection state
*/
setInteraction(
id: string,
elementId: string,
selection: WorkbookSelection[],
): void;

/**
* Overrider function for Config Ready state
*/
Expand All @@ -449,14 +430,6 @@ interface PluginInstance<T> {
id: string,
callback: (input: WorkbookVariable) => void,
): Unsubscriber;

/**
* Allows users to subscribe to changes in the passed in interaction ID
*/
subscribeToWorkbookInteraction(
id: string,
callback: (input: WorkbookSelection[]) => void,
): Unsubscriber;
};

elements: {
Expand Down Expand Up @@ -654,29 +627,6 @@ array or multiple parameters
function setVariableCallback(...values: unknown[]): void;
```

#### useInteraction()

Returns a given interaction's selection state and a setter to update that interation

```ts
function useInteraction(
interactionId: string,
elementId: string,
): [WorkbookSelection | undefined, (value: WorkbookSelection[]) => void];
```

Arguments

- `interactionId : string` - The ID of the interaction
- `elementId : string` - The ID of the element that this interaction is
associated with

The returned setter function accepts an array of workbook selection elements

```ts
function setVariableCallback(value: WorkbookSelection[]): void;
```

#### useConfig()

Returns the workbook element’s current configuration. If a key is provided, only
Expand Down
30 changes: 0 additions & 30 deletions src/client/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export function initialize<T = {}>(): PluginInstance<T> {
config: {} as T,
};

let subscribedInteractions: Record<string, WorkbookSelection[]> = {};
let subscribedWorkbookVars: Record<string, WorkbookVariable> = {};

const listeners: {
Expand Down Expand Up @@ -54,11 +53,6 @@ export function initialize<T = {}>(): PluginInstance<T> {
},
);

on('wb:plugin:selection:update', (updatedInteractions: unknown) => {
subscribedInteractions = {};
Object.assign(subscribedInteractions, updatedInteractions);
});

function on(event: string, listener: Function) {
listeners[event] = listeners[event] || [];
listeners[event].push(listener);
Expand Down Expand Up @@ -123,18 +117,6 @@ export function initialize<T = {}>(): PluginInstance<T> {
setVariable(id: string, ...values: unknown[]) {
void execPromise('wb:plugin:variable:set', id, ...values);
},
getInteraction(id: string) {
return subscribedInteractions[id];
},
setInteraction(
id: string,
elementId: string,
selection:
| string[]
| Array<Record<string, { type: string; val?: unknown }>>,
) {
void execPromise('wb:plugin:selection:set', id, elementId, selection);
},
configureEditorPanel(options) {
void execPromise('wb:plugin:config:inspector', options);
},
Expand All @@ -153,18 +135,6 @@ export function initialize<T = {}>(): PluginInstance<T> {
off('wb:plugin:variable:update', setValues);
};
},
subscribeToWorkbookInteraction(
id: string,
callback: (input: WorkbookSelection[]) => void,
): Unsubscriber {
const setValues = (values: Record<string, WorkbookSelection[]>) => {
callback(values[id]);
};
on('wb:plugin:selection:update', setValues);
return () => {
off('wb:plugin:selection:update', setValues);
};
},
},
elements: {
getElementColumns(id) {
Expand Down
30 changes: 0 additions & 30 deletions src/react/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,3 @@ export function useVariable(

return [workbookVariable, setVariable];
}

/**
* React hook for accessing a workbook interaction selections state
* @param {string} id ID of variable within Plugin Config to use
* @returns {[(WorkbookSelection | undefined), Function]} Constantly updating selection state and setter thereof
*/
export function useInteraction(
id: string,
elementId: string,
): [unknown, Function] {
const client = usePlugin();
const [workbookInteraction, setWorkbookInteraction] =
useState<WorkbookSelection[]>();

useEffect(() => {
return client.config.subscribeToWorkbookInteraction(
id,
setWorkbookInteraction,
);
}, [client, id]);

const setInteraction = useCallback(
(value: WorkbookSelection[]) => {
client.config.setInteraction(id, elementId, value);
},
[id],
);

return [workbookInteraction, setInteraction];
}
34 changes: 0 additions & 34 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,6 @@ export type CustomPluginConfigOptions =
name: string;
label?: string;
allowedTypes?: ControlType[];
}
| {
type: 'interaction';
name: string;
label?: string;
};

/**
Expand Down Expand Up @@ -237,24 +232,6 @@ export interface PluginInstance<T = any> {
*/
setVariable(id: string, ...values: unknown[]): void;

/**
* Getter for interaction selection state
* @param {string} id ID from interaction type in Plugin Config
*/
getInteraction(id: string): WorkbookSelection[];

/**
* Setter for interaction selection state
* @param {string} id ID from interaction type in Plugin Config
* @param {string} elementId Source element ID from element type in Plugin Config
* @param {Object} selection List of column IDs or Columns and values and key-value pairs to select
*/
setInteraction(
id: string,
elementId: string,
selection: WorkbookSelection[],
): void;

/**
* Overrider function for Config Ready state
* @param {boolean} loadingState Boolean representing if Plugin Config is still loading
Expand All @@ -271,17 +248,6 @@ export interface PluginInstance<T = any> {
id: string,
callback: (input: WorkbookVariable) => void,
): Unsubscriber;

/**
* Allows users to subscribe to changes in the passed in interaction ID
* @param {string} id ID of the interaction variable within Plugin Config
* @callback callback Function to be called upon receiving an updated interaction selection state
* @returns {Unsubscriber} A callable unsubscriber
*/
subscribeToWorkbookInteraction(
id: string,
callback: (input: WorkbookSelection[]) => void,
): Unsubscriber;
};

elements: {
Expand Down