From 9c3b2a2814c70b96935dba5cf0fd83e96bef31b8 Mon Sep 17 00:00:00 2001 From: peternandersson Date: Mon, 16 Sep 2024 14:11:58 -0700 Subject: [PATCH 1/3] Remove interaction API from plugin package --- README.md | 50 ---------------------------------------- src/client/initialize.ts | 30 ------------------------ src/react/hooks.ts | 30 ------------------------ src/types.ts | 34 --------------------------- 4 files changed, 144 deletions(-) diff --git a/README.md b/README.md index c31d20b..d157989 100644 --- a/README.md +++ b/README.md @@ -242,11 +242,6 @@ type CustomPluginConfigOptions = name: string; label?: string; allowedTypes?: ControlType[]; - } - | { - type: 'interaction'; - name: string; - label?: string; }; ``` @@ -423,20 +418,6 @@ interface PluginInstance { */ 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 */ @@ -449,14 +430,6 @@ interface PluginInstance { 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: { @@ -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 diff --git a/src/client/initialize.ts b/src/client/initialize.ts index a651f19..70c3565 100644 --- a/src/client/initialize.ts +++ b/src/client/initialize.ts @@ -12,7 +12,6 @@ export function initialize(): PluginInstance { config: {} as T, }; - let subscribedInteractions: Record = {}; let subscribedWorkbookVars: Record = {}; const listeners: { @@ -54,11 +53,6 @@ export function initialize(): PluginInstance { }, ); - 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); @@ -123,18 +117,6 @@ export function initialize(): PluginInstance { 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>, - ) { - void execPromise('wb:plugin:selection:set', id, elementId, selection); - }, configureEditorPanel(options) { void execPromise('wb:plugin:config:inspector', options); }, @@ -153,18 +135,6 @@ export function initialize(): PluginInstance { off('wb:plugin:variable:update', setValues); }; }, - subscribeToWorkbookInteraction( - id: string, - callback: (input: WorkbookSelection[]) => void, - ): Unsubscriber { - const setValues = (values: Record) => { - callback(values[id]); - }; - on('wb:plugin:selection:update', setValues); - return () => { - off('wb:plugin:selection:update', setValues); - }; - }, }, elements: { getElementColumns(id) { diff --git a/src/react/hooks.ts b/src/react/hooks.ts index 330ff65..c6841a5 100644 --- a/src/react/hooks.ts +++ b/src/react/hooks.ts @@ -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(); - - useEffect(() => { - return client.config.subscribeToWorkbookInteraction( - id, - setWorkbookInteraction, - ); - }, [client, id]); - - const setInteraction = useCallback( - (value: WorkbookSelection[]) => { - client.config.setInteraction(id, elementId, value); - }, - [id], - ); - - return [workbookInteraction, setInteraction]; -} diff --git a/src/types.ts b/src/types.ts index 734ddb6..7e75170 100644 --- a/src/types.ts +++ b/src/types.ts @@ -161,11 +161,6 @@ export type CustomPluginConfigOptions = name: string; label?: string; allowedTypes?: ControlType[]; - } - | { - type: 'interaction'; - name: string; - label?: string; }; /** @@ -237,24 +232,6 @@ export interface PluginInstance { */ 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 @@ -271,17 +248,6 @@ export interface PluginInstance { 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: { From 6c36c86207fb6836d387107e99a0e59e88e7d7e8 Mon Sep 17 00:00:00 2001 From: peternandersson Date: Thu, 19 Sep 2024 15:11:27 -0700 Subject: [PATCH 2/3] Change removal to deprecation --- src/client/initialize.ts | 15 ++++++++++++++- src/react/hooks.ts | 2 ++ src/types.ts | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/client/initialize.ts b/src/client/initialize.ts index 1597e94..c44c8fd 100644 --- a/src/client/initialize.ts +++ b/src/client/initialize.ts @@ -12,6 +12,7 @@ export function initialize(): PluginInstance { config: {} as T, }; + let subscribedInteractions: Record = {}; let subscribedWorkbookVars: Record = {}; const registeredEffects: Record void> = {}; @@ -170,6 +171,18 @@ export function initialize(): PluginInstance { off('wb:plugin:variable:update', setValues); }; }, + subscribeToWorkbookInteraction( + id: string, + callback: (input: WorkbookSelection[]) => void, + ): Unsubscriber { + const setValues = (values: Record) => { + callback(values[id]); + }; + on('wb:plugin:selection:update', setValues); + return () => { + off('wb:plugin:selection:update', setValues); + }; + }, }, elements: { getElementColumns(id) { @@ -197,7 +210,7 @@ export function initialize(): PluginInstance { }, fetchMoreElementData(id) { void execPromise('wb:plugin:element:fetch-more', id); - } + }, }, destroy() { Object.keys(listeners).forEach(event => delete listeners[event]); diff --git a/src/react/hooks.ts b/src/react/hooks.ts index 5acf7db..c8f3e65 100644 --- a/src/react/hooks.ts +++ b/src/react/hooks.ts @@ -180,7 +180,9 @@ export function useVariable( return [workbookVariable, setVariable]; } + /** + * @deprecated Use Action API instead * 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 diff --git a/src/types.ts b/src/types.ts index adeb371..176b5bf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -248,12 +248,14 @@ export interface PluginInstance { setVariable(id: string, ...values: unknown[]): void; /** + * @deprecated Use Action API instead * Getter for interaction selection state * @param {string} id ID from interaction type in Plugin Config */ getInteraction(id: string): WorkbookSelection[]; /** + * @deprecated Use Action API instead * 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 @@ -295,6 +297,18 @@ export interface PluginInstance { id: string, callback: (input: WorkbookVariable) => void, ): Unsubscriber; + + /** + * @deprecated Use Action API instead + * 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: { From 97f29e8400adfe9adfbbd54bb21a735381504e22 Mon Sep 17 00:00:00 2001 From: peternandersson Date: Thu, 19 Sep 2024 15:12:39 -0700 Subject: [PATCH 3/3] Missed README --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 0063bde..e069073 100644 --- a/README.md +++ b/README.md @@ -477,6 +477,15 @@ interface PluginInstance { id: string, callback: (input: WorkbookVariable) => void, ): Unsubscriber; + + /** + * @deprecated Use Action API instead + * Allows users to subscribe to changes in the passed in interaction ID + */ + subscribeToWorkbookInteraction( + id: string, + callback: (input: WorkbookSelection[]) => void, + ): Unsubscriber; }; elements: {