Skip to content

Commit cd9bd26

Browse files
authored
Merge pull request #18 from beekpr/FUL-23611
FUL-23611: Update with new API
2 parents b734447 + 7040b1f commit cd9bd26

File tree

3 files changed

+33
-68
lines changed

3 files changed

+33
-68
lines changed

home-screen-widget/profiles/README.md

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,17 @@ python3 scripts/configure_home_screen.py --tenantUrl https://<tenant_url> --toke
5959

6060
The following four steps are **required** for every widget to be shown on the home screen.
6161

62-
1. [Define Widget ID](src/components/Widget.vue#L19)
62+
1. [Define Widget Type Name](src/components/Widget.vue#L17)
6363
```javascript:title=home-screen-widget/profiles/src/components/Widget.vue
64-
export const WIDGET_TYPE = 'profiles';
64+
export const WIDGET_TYPE_NAME = 'profiles';
6565
```
66-
2. [Register Widget Component](src/main.js#L9)
66+
2. [Register Widget Component](src/main.js#L6)
6767
```javascript:title=home-screen-widget/profiles/src/main.js
68-
BeekeeperHomeScreen.registerWidget(WIDGET_TYPE, component)
68+
BeekeeperHomeScreen.registerVueWidget(WIDGET_TYPE_NAME, component)
6969
```
70-
3. [Add widgetInstanceId Prop](src/components/Widget.vue#L38)
70+
3. [Trigger 'widget-loaded' Event](src/components/Widget.vue#L46)
7171
```javascript:title=home-screen-widget/profiles/src/components/Widget.vue
72-
props: {
73-
widgetInstanceId: {
74-
type: String,
75-
required: true,
76-
},
77-
...
78-
},
79-
```
80-
4. [Trigger LOADED Event](src/components/Widget.vue#L71)
81-
```javascript:title=home-screen-widget/profiles/src/components/Widget.vue
82-
import BeekeeperHomeScreen, { EventType } from '@beekeeper/home-screen-sdk';
83-
BeekeeperHomeScreen.triggerEvent(EventType.LOADED, this.widgetInstanceId);
72+
this.$emit('widget-loaded');
8473
```
8574
8675
## Caveats with Webpack
@@ -89,7 +78,7 @@ As the Home Screen uses Webpack to bundle components, please take a look at [vue
8978
9079
## Common Pitfalls
9180
92-
Make sure to update the ``WIDGET_TYPE`` in Widget.vue to the ``typeName`` returned by the API. Otherwise, your widget will not be loaded.
81+
Make sure to update the ``WIDGET_TYPE_NAME`` in Widget.vue to the ``typeName`` returned by the API. Otherwise, your widget will not be loaded.
9382
9483
## Limitations
9584

home-screen-widget/profiles/src/components/Widget.vue

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,87 +9,58 @@
99
</template>
1010

1111
<script>
12-
import { createNamespacedHelpers } from 'vuex';
13-
import BeekeeperHomeScreen, { EventType } from '@beekeeper/home-screen-sdk';
12+
import { mapActions, mapState } from 'vuex';
1413
1514
import ProfilesGrid from '~/components/ProfilesGrid.vue';
16-
import store from '~/store';
1715
1816
/**
19-
* Step 1: Specify widget type
17+
* Step 1: Specify widget type name
2018
*
2119
* In order for the home screen to be aware of the widget we need to register it. That's why we defined here
2220
* a unique string as widget type. We called it 'profiles' since this is the profiles widget.
2321
* See also the "Widget type" in the "Configuration" section on the developers portal
2422
* {@link https://developers.beekeeper.io/v2/welcome/home-screen}
2523
*/
26-
export const WIDGET_TYPE = 'profiles';
24+
export const WIDGET_TYPE_NAME = 'profiles';
2725
export const PROFILE_LIMIT = 50;
2826
29-
const { mapState, mapActions } = createNamespacedHelpers(WIDGET_TYPE);
30-
3127
3228
export default {
3329
components: {
3430
ProfilesGrid,
3531
},
36-
/**
37-
* Step 3: Add widgetInstanceId prop
38-
*
39-
* Once the widget is registered, the home screen will try to instantiate it and assign an instance id.
40-
* This will be used by the home screen to manage all widgets and listen to events.
41-
* In order for this to work, we therefore need a vue prop called 'widgetInstanceId'.
42-
*/
32+
computed: {
33+
...mapState(['profiles', 'initialized']),
34+
},
4335
props: {
44-
widgetInstanceId: {
45-
type: String,
46-
required: true,
47-
},
48-
49-
/**
50-
* Step 7: Define customizable input props (Optional)
51-
*
52-
* Every widget can have input properties that can be customized by admins.
53-
* In this example for different widget instances one might want to display more or fewer profiles.
54-
* The default is now set to 50.
55-
*
56-
*/
57-
maxNumberOfDisplayedProfiles: {
58-
type: Number,
59-
required: false,
36+
properties: {
37+
type: Object,
6038
default() {
61-
return PROFILE_LIMIT;
62-
},
39+
return {
40+
maxNumberOfDisplayedProfiles: 12,
41+
};
42+
}
6343
},
6444
},
65-
computed: {
66-
...mapState(['profiles', 'initialized']),
67-
},
6845
watch: {
6946
/**
70-
* Step 6: Trigger LOADED event
47+
* Step 3: Trigger `widget-loaded` event
7148
*
7249
* Once the profiles are successfully loaded we notify the home screen by triggering an event
73-
* that contains the event type and the widget instance id
7450
*/
7551
initialized(newVal, oldVal) {
7652
if (newVal && newVal !== oldVal) {
77-
BeekeeperHomeScreen.triggerEvent(EventType.LOADED, this.widgetInstanceId);
53+
this.$emit('widget-loaded');
7854
}
7955
},
8056
},
81-
beforeCreate() {
82-
/**
83-
* Step 4: Register widget store module (Optional: not needed for a static widget without store)
84-
*
85-
* In order for Vuex to be aware of this store, we need to register it upon widget creation.
86-
* When the module is registered, all of its getters, actions and mutations will be automatically
87-
* namespaced based on the path the module is registered at.
88-
*/
89-
this.$store.registerModule(WIDGET_TYPE, store, { preserveState: false });
57+
computed: {
58+
displayedProfiles() {
59+
return this.properties?.maxNumberOfDisplayedProfiles || PROFILE_LIMIT;
60+
},
9061
},
9162
created() {
92-
this.initStore(this.maxNumberOfDisplayedProfiles);
63+
this.initStore(displayedProfiles);
9364
},
9465
methods: {
9566
...mapActions({
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import BeekeeperHomeScreen from '@beekeeper/home-screen-sdk';
2-
import component, { WIDGET_TYPE } from '~/components/Widget.vue';
2+
3+
import component, { WIDGET_TYPE_NAME } from '~/components/Widget.vue';
4+
import store from '~/store';
35

46
/**
57
* Step 2: Register widget component
68
*
79
* This is the entry point of your widget and here we need to register
810
* the component with its widget id into the home screen
911
*/
10-
BeekeeperHomeScreen.registerWidget(WIDGET_TYPE, component);
12+
BeekeeperHomeScreen.registerVueWidget(WIDGET_TYPE_NAME, component, {
13+
useStore: true,
14+
storeOptions: store,
15+
});

0 commit comments

Comments
 (0)