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

TELESTION-462 Make widgets configurable #418

Merged
merged 1 commit into from
Jan 26, 2024

Conversation

pklaschka
Copy link
Member

Uses a context to make widgets configurable. While currently, configuration is only possible in the edit dashboard page, this context can, in the future, be used to also allow editing the configuration in other places, such as within the widget itself.

For convenience, components are provided for basic confiugration fields such as textfields and checkboxes. This makes configurability as easy as this:

{
	...
	configElement: (
		<WidgetConfigWrapper>
			<WidgetConfigCheckboxField label={'Bool value'} name={'bool'} />
			<WidgetConfigTextField label={'Test Text'} name={'text'} />
		</WidgetConfigWrapper>
	)
}

It is also possible to create custom configuration fields (using useConfigureWidgetField(name, validator)) or even fully custom configuration UIs (using useConfigureWidget()). Both of these hooks return both the current configuration and a function that works the same way a useState()-setter works. Note that any congiuration passed into or out of the confiuration controls automatically, controlled by the context, get validated using the widget's createConfig function.

Example of using the useConfiugreWidgetField() hook:

function WidgetConfigTextField(props: { label: string; name: string }) {
	const [value, setValue] = useConfigureWidgetField(props.name, s =>
		z.string().parse(s)
	);

	return (
		<FormGroup className={'mb-3'}>
			<FormLabel>{props.label}</FormLabel>
			<FormControl
				data-name={props.name}
				value={value}
				onChange={e => setValue(e.target.value)}
			/>
		</FormGroup>
	);
}

Everything related to widget configuration can be imported from @wuespace/telestion/widget.

Note that this also adjusts the user data to use a Record<string, jsonSchema> instead of a Record<string, unknown> as the widget instance configuration type. The jsonSchema implementation is taken from the zod documentation (README.md) wiwhere https://github.com/ggoodman is credited; thank you for this great implementation!

@pklaschka pklaschka force-pushed the 01-14-TELESTION-460_Dashboard_layout_editor branch from 835d7fa to 05e2707 Compare January 21, 2024 16:39
@pklaschka pklaschka force-pushed the 01-21-TELESTION-462_Make_widgets_configurable branch from 881e234 to c9a8328 Compare January 21, 2024 16:39
@pklaschka pklaschka self-assigned this Jan 21, 2024
@pklaschka pklaschka added 🌷 enhancement New feature or request 📚 library Possible candidate for a Telestion Library (like telestion-core or telestion-client) labels Jan 21, 2024 — with Graphite App
@pklaschka pklaschka force-pushed the 01-21-TELESTION-462_Make_widgets_configurable branch from c9a8328 to 8005af7 Compare January 21, 2024 17:06
@pklaschka pklaschka marked this pull request as ready for review January 21, 2024 17:07
@pklaschka pklaschka force-pushed the 01-21-TELESTION-462_Make_widgets_configurable branch 3 times, most recently from 77238a8 to 98b46ec Compare January 21, 2024 17:54
@pklaschka pklaschka force-pushed the 01-14-TELESTION-460_Dashboard_layout_editor branch from 05e2707 to 87c3688 Compare January 24, 2024 12:06
@pklaschka pklaschka force-pushed the 01-21-TELESTION-462_Make_widgets_configurable branch from 98b46ec to 52a2a56 Compare January 24, 2024 12:06
@pklaschka pklaschka force-pushed the 01-14-TELESTION-460_Dashboard_layout_editor branch from 87c3688 to 28d9e29 Compare January 24, 2024 12:15
@pklaschka pklaschka force-pushed the 01-21-TELESTION-462_Make_widgets_configurable branch from 52a2a56 to 7d56f8c Compare January 24, 2024 12:15
@pklaschka pklaschka force-pushed the 01-14-TELESTION-460_Dashboard_layout_editor branch from 28d9e29 to 70ec0fb Compare January 24, 2024 12:33
@pklaschka pklaschka force-pushed the 01-21-TELESTION-462_Make_widgets_configurable branch from 7d56f8c to ab9249e Compare January 24, 2024 12:33
@pklaschka pklaschka force-pushed the 01-14-TELESTION-460_Dashboard_layout_editor branch from 70ec0fb to 61d9145 Compare January 24, 2024 12:40
@pklaschka pklaschka force-pushed the 01-21-TELESTION-462_Make_widgets_configurable branch from ab9249e to 07d2c59 Compare January 24, 2024 12:40
@pklaschka pklaschka force-pushed the 01-14-TELESTION-460_Dashboard_layout_editor branch from 61d9145 to 0ee0c4e Compare January 26, 2024 17:34
@pklaschka pklaschka force-pushed the 01-21-TELESTION-462_Make_widgets_configurable branch from 07d2c59 to 8778084 Compare January 26, 2024 17:34
@pklaschka pklaschka force-pushed the 01-14-TELESTION-460_Dashboard_layout_editor branch from 0ee0c4e to 81b92d9 Compare January 26, 2024 18:13
@pklaschka pklaschka force-pushed the 01-21-TELESTION-462_Make_widgets_configurable branch from 8778084 to 5a72697 Compare January 26, 2024 18:13
Base automatically changed from 01-14-TELESTION-460_Dashboard_layout_editor to main January 26, 2024 18:15
Copy link
Member

@fussel178 fussel178 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🏃

Uses a context to make widgets configurable. While currently, configuration is only possible in the edit dashboard page, this context can, in the future, be used to also allow editing the configuration in other places, such as within the widget itself.

For convenience, components are provided for basic confiugration fields such as textfields and checkboxes. This makes configurability as easy as this:

```tsx
{
	...
	configElement: (
		<WidgetConfigWrapper>
			<WidgetConfigCheckboxField label={'Bool value'} name={'bool'} />
			<WidgetConfigTextField label={'Test Text'} name={'text'} />
		</WidgetConfigWrapper>
	)
}
```

It is also possible to create custom configuration fields (using `useConfigureWidgetField(name, validator)`) or even fully custom configuration UIs (using `useConfigureWidget()`). Both of these hooks return both the current configuration and a function that works the same way a `useState()`-setter works. Note that any congiuration passed into or out of the confiuration controls automatically, controlled by the context, get validated using the widget's `createConfig` function.

Example of using the `useConfiugreWidgetField()` hook:

```tsx
function WidgetConfigTextField(props: { label: string; name: string }) {
	const [value, setValue] = useConfigureWidgetField(props.name, s =>
		z.string().parse(s)
	);

	return (
		<FormGroup className={'mb-3'}>
			<FormLabel>{props.label}</FormLabel>
			<FormControl
				data-name={props.name}
				value={value}
				onChange={e => setValue(e.target.value)}
			/>
		</FormGroup>
	);
}
```

Everything related to widget configuration can be imported from `@wuespace/telestion/widget`.

Note that this also adjusts the user data to use a `Record<string, jsonSchema>` instead of a `Record<string, unknown>` as the widget instance configuration type. The `jsonSchema` implementation is taken from the zod documentation (`README.md`) wiwhere https://github.com/ggoodman is credited; thank you for this great implementation!
@pklaschka pklaschka force-pushed the 01-21-TELESTION-462_Make_widgets_configurable branch from 5a72697 to c271b9e Compare January 26, 2024 18:43
Copy link
Member Author

pklaschka commented Jan 26, 2024

Merge activity

  • Jan 26, 7:44 PM: Graphite rebased this pull request as part of a merge.
  • Jan 26, 7:45 PM: @pklaschka merged this pull request with Graphite.

@pklaschka pklaschka merged commit 66ce249 into main Jan 26, 2024
16 of 17 checks passed
@pklaschka pklaschka deleted the 01-21-TELESTION-462_Make_widgets_configurable branch January 26, 2024 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 library Possible candidate for a Telestion Library (like telestion-core or telestion-client) 🌷 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants