From f80ea2735c6cc5e41cf5a718b5c0a5c01d04496f Mon Sep 17 00:00:00 2001 From: Gary Kaganas Date: Thu, 27 Jun 2024 10:51:11 -0400 Subject: [PATCH 1/3] feat: adds README for UPS (#302) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gary Kaganas Co-authored-by: Gabriel Tibúrcio Co-authored-by: jared-dickman --- src/services/user-preferences/README.md | 61 +++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/services/user-preferences/README.md diff --git a/src/services/user-preferences/README.md b/src/services/user-preferences/README.md new file mode 100644 index 000000000..d1571c5e2 --- /dev/null +++ b/src/services/user-preferences/README.md @@ -0,0 +1,61 @@ +# User Preferences Service + +The `UserPreferencesService` class is a TypeScript module designed to manage user preferences within an application. It leverages a composite pattern to handle preferences across different scopes and integrates with browser cookies for persistence. + +## Features + +- **Initialization of Preferences**: Loads and initializes user preferences from storage (currently uses cookies). +- **Opt-in Check**: Allows checking if a user has opted into a specific preference. +- **Set Preference**: Enables setting a user's preference, including opt-in/opt-out functionality. +- **Scoped Preferences**: Supports handling preferences within defined scopes to cater to different user segments or application areas. +- **Update Callbacks**: Provides an optional callback mechanism to react to changes in preferences. When preferences are successfully loaded or updated, the `onUpdate` callback is invoked with the resolved preferences as its argument. This allows for reactive updates in the application UI or logic based on the current user preferences. + +## Dependencies + +This module relies on several custom utilities and services, including: + +- `UserPreferences` and `CompositeUserPreferences` for modeling user preferences. +- `UserPreferenceScope` and `UserPreferenceDefinitions` for defining the scope and structure of preferences. +- `CompositeUserPreferencesService` for handling the composite nature of user preferences. +- `Cookies` utility for getting and setting preferences in browser cookies. + +## Usage + +To use the `UserPreferencesService`, you need to instantiate it with the necessary dependencies, including preference definitions, a composite service instance, the current scope, and cookie options. After instantiation, call the `init` method to load existing preferences. + +### Example + +```typescript +import { UserPreferencesService } from './user-preferences.ts' +import { UserPreferenceDefinitions } from 'src/services/user-preferences/models/definitions/user-preference-definitions' +import { CompositeUserPreferencesService } from 'src/services/user-preferences/composite-user-preferences-service' +import { UserPreferenceScope } from 'src/services/user-preferences/models/storage-models/user-preference-scope' +import { CookieOptions } from 'src/utils/Cookies' + +// Define your preferences, scope, and cookie options +const definitions = new UserPreferenceDefinitions(/* ... */) +const compositeService = new CompositeUserPreferencesService(/* ... */) +const scope = UserPreferenceScope.Global +const cookieOptions: CookieOptions = { key: 'user_prefs', path: '/', secure: true } + +// Instantiate the service +const userPreferencesService = new UserPreferencesService( + definitions, + compositeService, + scope, + cookieOptions, + resolvedPreferences => { + console.log('Preferences updated:', resolvedPreferences) + // Implement your update logic here, e.g., update UI or application state + }, +) + +// Initialize preferences +userPreferencesService.init().then(() => { + console.log('User preferences initialized.') +}) +``` + +#### Note + +This module is designed to be flexible and extensible to accommodate various types of user preferences and application requirements. It is essential to provide the correct dependencies and configurations for it to function correctly. From 0550de634279f79edf2cc5174d3951d2ed445e37 Mon Sep 17 00:00:00 2001 From: jared-dickman Date: Thu, 27 Jun 2024 10:55:08 -0400 Subject: [PATCH 2/3] chore: add autoFocus to queryItem numberInput (#313) --- .../data-entry/QueryItem/NumberInput.stories.tsx | 8 +++++++- src/components/data-entry/QueryItem/NumberInput.tsx | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/data-entry/QueryItem/NumberInput.stories.tsx b/src/components/data-entry/QueryItem/NumberInput.stories.tsx index 89e9176a0..0cdeaa3c3 100644 --- a/src/components/data-entry/QueryItem/NumberInput.stories.tsx +++ b/src/components/data-entry/QueryItem/NumberInput.stories.tsx @@ -59,4 +59,10 @@ export const Max: Story = { args: { max: 100, }, -} \ No newline at end of file +} + +export const AutoFocus: Story = { + args: { + autoFocus: true, + }, +} diff --git a/src/components/data-entry/QueryItem/NumberInput.tsx b/src/components/data-entry/QueryItem/NumberInput.tsx index 9153c76ed..31b5bae25 100644 --- a/src/components/data-entry/QueryItem/NumberInput.tsx +++ b/src/components/data-entry/QueryItem/NumberInput.tsx @@ -6,6 +6,7 @@ interface INumberInputProps { value?: number disabled?: boolean errorMessage?: string + autoFocus: boolean placeholder?: string min?: number max?: number @@ -27,6 +28,7 @@ const NumberInput = (props: INumberInputProps) => { disabled={props.disabled} className={inputClasses} value={props.value} + autoFocus={props.autoFocus} placeholder={props.placeholder} max={props.max} min={props.min} @@ -37,10 +39,9 @@ const NumberInput = (props: INumberInputProps) => { }} /> - {props.errorMessage && - {props.errorMessage}} + {props.errorMessage && {props.errorMessage}} ) } -export default NumberInput \ No newline at end of file +export default NumberInput From 58953aac96994d0fca8d1f26dc3311755edf1ccf Mon Sep 17 00:00:00 2001 From: jdickman Date: Mon, 8 Jul 2024 18:02:16 -0400 Subject: [PATCH 3/3] feat: align QueryItem.Text props with Typography.Text --- src/components/data-entry/QueryItem/Text.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/components/data-entry/QueryItem/Text.tsx b/src/components/data-entry/QueryItem/Text.tsx index f8518d180..a5d290911 100644 --- a/src/components/data-entry/QueryItem/Text.tsx +++ b/src/components/data-entry/QueryItem/Text.tsx @@ -1,16 +1,18 @@ +import { type TextProps } from 'antd/es/typography/Text' import { Typography } from 'src/components/general/Typography/Typography' -export interface ITextProps { +export interface ITextProps extends TextProps { disabled?: boolean - text: string + type?: TextProps['type'] + children: TextProps['children'] } -const Text = ({ disabled = false, text }: ITextProps) => { +const Text = ({ disabled = false, ...props }: ITextProps) => { return ( - - {text} + + {props.children} ) } -export default Text \ No newline at end of file +export default Text