@aws/mynah-ui 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Mynah UI
2
2
 
3
- This package is the whole UI of AWS Tookit Mynah extension UI for VSCode and Intellij IDEs written in typescript without and framework and UI library dependency. Purpose of the separated UI is to handle the interactions and look & feel of the UI from one single source.
3
+ This package is the whole UI of AWS Tookit Mynah extension UI for VSCode and Intellij IDEs written in typescript without any framework or third-party UI library dependency. Purpose of the separated UI is to handle the interactions and look & feel of the UI from one single source.
4
4
 
5
5
  ## How to install
6
6
 
@@ -9,39 +9,112 @@ npm install @aws/mynah-ui
9
9
  ```
10
10
 
11
11
  ## How to use
12
- When you import `@aws/mynah-ui` it provides you the `MynahUI` class to generate a new all-in-one object to create the UI. However, you have to to provide 2 arguments to let the UI work properly.
12
+ When you import `@aws/mynah-ui` it provides you the `MynahUI` class to generate a new all-in-one object to create the UI. You can connect to user interaction events through the initial properties have provide to the UI.
13
13
 
14
14
  ``` typescript
15
15
  import { MynahUI } from '@aws/mynah-ui';
16
16
 
17
17
  export const createMynahUI = () => {
18
- new MynahUI({
19
- // You have to provide a connector to let the UI call for requests.
20
- // See "ServiceConnector" type for mandatory and optional public functions
21
- serviceConnector: new ServiceConnector({
22
- postMessageHandler: message => {
23
- // post message handling
18
+ const mynahUI = new MynahUI({
19
+ // initial UI state data
20
+ // It doesn't have to be matched with backend data
21
+ // but to update the UI and rerender its desired parts,
22
+ // it expects the data in this model.
23
+ storeData?: MynahUIDataModel;
24
+
25
+ // All below items trigger when;
26
+ // User hits search button or enter inside query input
27
+ onSearch?: (
28
+ searchPayload: SearchPayload,
29
+ isFromHistory?: boolean,
30
+ isFromAutocomplete?: boolean
31
+ ) => void;
32
+
33
+ // UI is ready
34
+ onReady?: () => void;
35
+
36
+ // User votes a suggestion
37
+ onClickSuggestionVote?: (suggestion: Suggestion, vote: RelevancyVoteType) => void;
38
+ // User opens the detail view of selected code block
39
+ onClickCodeDetails?: (
40
+ code: string,
41
+ fileName?: string,
42
+ range?: {
43
+ start: { row: string; column?: string };
44
+ end?: { row: string; column?: string };
24
45
  }
25
- }),
26
- // You have to provide a state manager to locally store temporary data.
27
- // If you don't need to store panelID or temporary information,
28
- // you can leave the contents of the get and set state functions empty.
29
- stateManager: {
30
- getState: (): Record<string, any> => {
31
- // return all recorded items
32
- },
33
- setState: state => {
34
- // set all items at once
35
- }
36
- },
46
+ ) => void;
47
+
48
+ // Data store is reset
49
+ onResetStore?: () => void;
50
+
51
+ // Matching policy is changed (context items)
52
+ onChangeContext?: (changeType: ContextChangeType, queryContext: ContextType) => void;
53
+
54
+ // User engages with a suggestion
55
+ onSuggestionEngagement?: (engagement: SuggestionEngagement) => void;
56
+
57
+ // User copies text from suggestion
58
+ onSuggestionClipboardInteraction?: (suggestionId: string, type?: string, text?: string) => void;
59
+
60
+ // User clicks to the title, clicks or copies the link of the suggestion
61
+ onSuggestionInteraction?: (eventName: SuggestionEventName, suggestion: Suggestion) => void;
62
+
63
+ // User sends feedback
64
+ onSendFeedback?: (feedbackPayload: FeedbackPayload) => void;
65
+
66
+ // Search history panel view opens
67
+ onRequestHistoryRecords?: (filterPayload: SearchHistoryFilters) => void;
68
+
69
+ // Autocomplete items list block opens
70
+ onRequestAutocompleteList?: (input: string) => void;
71
+
72
+ // User changes live search state
73
+ onChangeLiveSearchState?: (liveSearchState: LiveSearchState) => void;
74
+
75
+ // User selects and autocomplete item
76
+ onClickAutocompleteItem?: (
77
+ text: string,
78
+ currSelected?: number,
79
+ suggestionCount?: number
80
+ ) => void;
81
+ });
82
+ }
83
+ ```
84
+
85
+ MynahUI also provides some accessible functions to help developer show a notification or more importantly update the UI state data store. When you update the data store, it will automatically rerender the parts that is subscribed to that particular data part.
86
+
87
+ ``` typescript
88
+ import { MynahUI } from '@aws/mynah-ui';
89
+
90
+ export const createMynahUI = () => {
91
+ let mynahUI:MynahUI;
92
+ const getSuggestions = (searchPayload) => {
93
+ mynahUI.updateStore({loading: true});
94
+ // get suggestions list
95
+ const suggestions = await getSuggestions(searchPayload);
96
+ if(suggestions){
97
+ mynahUI.updateStore({suggestions, loading: false});
98
+ } else {
99
+ mynahUI.updateStore({loading: false});
100
+ mynahUI.notify({
101
+ content: "Couldn't get suggestions!",
102
+ type: NotificationType.ERROR,
103
+ });
104
+ }
105
+
106
+ }
107
+ const mynahUI = new MynahUI({
108
+ ...,
109
+ onSearch: getSuggestions
37
110
  });
38
111
  }
39
112
  ```
40
113
 
41
- In addition to MynahUI class, there are also some exported type definitions that might be helpful for function returns in ServiceConnector.
114
+ In addition to MynahUI class, there are also some exported type definitions that can be handy for function returns or proper usage of arguments.
42
115
 
43
116
  ``` typescript
44
- export {
117
+ import {
45
118
  AutocompleteItem,
46
119
  SearchPayloadCodeSelection,
47
120
  FeedbackPayload,
@@ -53,7 +126,14 @@ export {
53
126
  SearchHistoryItem,
54
127
  EngagementType,
55
128
  SuggestionEngagement,
56
- } from './static';
129
+ SuggestionEventName,
130
+ SearchHistoryFilters,
131
+ MynahUIDataModel,
132
+ ContextChangeType,
133
+ ContextSource,
134
+ ContextTypes,
135
+ NotificationType,
136
+ } from '@aws/mynah-ui';
57
137
  ```
58
138
 
59
139
  ## Styles