@genspectrum/dashboard-components 0.8.5 → 0.9.0
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 +14 -2
- package/custom-elements.json +30 -7
- package/dist/{genspectrum-components.d.ts → components.d.ts} +15 -49
- package/dist/{dashboard-components.js → components.js} +36 -62
- package/dist/components.js.map +1 -0
- package/dist/util.d.ts +301 -0
- package/dist/util.js +6 -0
- package/dist/util.js.map +1 -0
- package/dist/utilEntrypoint-g4DsyhU7.js +61 -0
- package/dist/utilEntrypoint-g4DsyhU7.js.map +1 -0
- package/package.json +10 -5
- package/src/{index.ts → componentsEntrypoint.ts} +0 -1
- package/src/preact/dateRangeSelector/date-range-selector.stories.tsx +101 -44
- package/src/preact/dateRangeSelector/date-range-selector.tsx +33 -14
- package/src/preact/dateRangeSelector/dateConversion.ts +1 -5
- package/src/preact/dateRangeSelector/dateRangeOption.ts +18 -0
- package/src/standaloneEntrypoint.ts +2 -0
- package/src/utilEntrypoint.ts +6 -0
- package/src/web-components/input/gs-date-range-selector.stories.ts +41 -10
- package/src/web-components/input/gs-date-range-selector.tsx +16 -2
- package/standalone-bundle/assets/mutationOverTimeWorker-MVSt1FVw.js.map +1 -0
- package/standalone-bundle/dashboard-components.js +13241 -16906
- package/standalone-bundle/dashboard-components.js.map +1 -1
- package/standalone-bundle/style.css +1 -0
- package/dist/dashboard-components.js.map +0 -1
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A date range option that can be used in the `gs-date-range-selector` component.
|
|
3
|
+
*/
|
|
4
|
+
export declare type DateRangeOption = {
|
|
5
|
+
/** The label of the date range option that will be shown to the user */
|
|
6
|
+
label: string;
|
|
7
|
+
/**
|
|
8
|
+
* The start date of the date range in the format `YYYY-MM-DD`.
|
|
9
|
+
* If not set, the date range selector will default to the `earliestDate` property.
|
|
10
|
+
*/
|
|
11
|
+
dateFrom?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The end date of the date range in the format `YYYY-MM-DD`.
|
|
14
|
+
* If not set, the date range selector will default to the current date.
|
|
15
|
+
*/
|
|
16
|
+
dateTo?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export declare class DateRangeOptionChangedEvent extends CustomEvent<DateRangeSelectOption> {
|
|
20
|
+
constructor(detail: DateRangeSelectOption);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Presets for the `gs-date-range-selector` component that can be used as `dateRangeOptions`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const dateRangeOptionPresets: {
|
|
27
|
+
last2Weeks: {
|
|
28
|
+
label: string;
|
|
29
|
+
dateFrom: string;
|
|
30
|
+
};
|
|
31
|
+
lastMonth: {
|
|
32
|
+
label: string;
|
|
33
|
+
dateFrom: string;
|
|
34
|
+
};
|
|
35
|
+
last2Months: {
|
|
36
|
+
label: string;
|
|
37
|
+
dateFrom: string;
|
|
38
|
+
};
|
|
39
|
+
last3Months: {
|
|
40
|
+
label: string;
|
|
41
|
+
dateFrom: string;
|
|
42
|
+
};
|
|
43
|
+
last6Months: {
|
|
44
|
+
label: string;
|
|
45
|
+
dateFrom: string;
|
|
46
|
+
};
|
|
47
|
+
lastYear: {
|
|
48
|
+
label: string;
|
|
49
|
+
dateFrom: string;
|
|
50
|
+
};
|
|
51
|
+
allTimes: {
|
|
52
|
+
label: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export declare type DateRangeSelectOption = string | {
|
|
57
|
+
dateFrom: string;
|
|
58
|
+
dateTo: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export { }
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
declare global {
|
|
65
|
+
interface HTMLElementEventMap {
|
|
66
|
+
'gs-error': ErrorEvent;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
declare global {
|
|
72
|
+
interface HTMLElementTagNameMap {
|
|
73
|
+
'gs-app': App;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
declare global {
|
|
79
|
+
namespace JSX {
|
|
80
|
+
interface IntrinsicElements {
|
|
81
|
+
'gs-app': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
declare global {
|
|
88
|
+
interface HTMLElementTagNameMap {
|
|
89
|
+
'gs-mutation-comparison-component': MutationComparisonComponent;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
declare global {
|
|
95
|
+
namespace JSX {
|
|
96
|
+
interface IntrinsicElements {
|
|
97
|
+
'gs-mutation-comparison-component': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
declare global {
|
|
104
|
+
interface HTMLElementTagNameMap {
|
|
105
|
+
'gs-mutations-component': MutationsComponent;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
declare global {
|
|
111
|
+
namespace JSX {
|
|
112
|
+
interface IntrinsicElements {
|
|
113
|
+
'gs-mutations-component': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
declare global {
|
|
120
|
+
interface HTMLElementTagNameMap {
|
|
121
|
+
'gs-prevalence-over-time': PrevalenceOverTimeComponent;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
declare global {
|
|
127
|
+
namespace JSX {
|
|
128
|
+
interface IntrinsicElements {
|
|
129
|
+
'gs-prevalence-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
declare global {
|
|
136
|
+
interface HTMLElementTagNameMap {
|
|
137
|
+
'gs-relative-growth-advantage': RelativeGrowthAdvantageComponent;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
declare global {
|
|
143
|
+
namespace JSX {
|
|
144
|
+
interface IntrinsicElements {
|
|
145
|
+
'gs-relative-growth-advantage': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
declare global {
|
|
152
|
+
interface HTMLElementTagNameMap {
|
|
153
|
+
'gs-aggregate-component': AggregateComponent;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
declare global {
|
|
159
|
+
namespace JSX {
|
|
160
|
+
interface IntrinsicElements {
|
|
161
|
+
'gs-aggregate-component': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
declare global {
|
|
168
|
+
interface HTMLElementTagNameMap {
|
|
169
|
+
'gs-number-sequences-over-time': NumberSequencesOverTimeComponent;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
declare global {
|
|
175
|
+
namespace JSX {
|
|
176
|
+
interface IntrinsicElements {
|
|
177
|
+
'gs-number-sequences-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
declare global {
|
|
184
|
+
interface HTMLElementTagNameMap {
|
|
185
|
+
'gs-mutations-over-time': MutationsOverTimeComponent;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
declare global {
|
|
191
|
+
namespace JSX {
|
|
192
|
+
interface IntrinsicElements {
|
|
193
|
+
'gs-mutations-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
declare global {
|
|
200
|
+
interface HTMLElementTagNameMap {
|
|
201
|
+
'gs-date-range-selector': DateRangeSelectorComponent;
|
|
202
|
+
}
|
|
203
|
+
interface HTMLElementEventMap {
|
|
204
|
+
'gs-date-range-filter-changed': CustomEvent<Record<string, string>>;
|
|
205
|
+
'gs-date-range-option-changed': DateRangeOptionChangedEvent;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
declare global {
|
|
211
|
+
namespace JSX {
|
|
212
|
+
interface IntrinsicElements {
|
|
213
|
+
'gs-date-range-selector': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
declare global {
|
|
220
|
+
interface HTMLElementTagNameMap {
|
|
221
|
+
'gs-location-filter': LocationFilterComponent;
|
|
222
|
+
}
|
|
223
|
+
interface HTMLElementEventMap {
|
|
224
|
+
'gs-location-changed': CustomEvent<Record<string, string>>;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
declare global {
|
|
230
|
+
namespace JSX {
|
|
231
|
+
interface IntrinsicElements {
|
|
232
|
+
'gs-location-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
declare global {
|
|
239
|
+
interface HTMLElementTagNameMap {
|
|
240
|
+
'gs-text-input': TextInputComponent;
|
|
241
|
+
}
|
|
242
|
+
interface HTMLElementEventMap {
|
|
243
|
+
'gs-text-input-changed': CustomEvent<Record<string, string>>;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
declare global {
|
|
249
|
+
namespace JSX {
|
|
250
|
+
interface IntrinsicElements {
|
|
251
|
+
'gs-text-input': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
declare global {
|
|
258
|
+
interface HTMLElementTagNameMap {
|
|
259
|
+
'gs-mutation-filter': MutationFilterComponent;
|
|
260
|
+
}
|
|
261
|
+
interface HTMLElementEventMap {
|
|
262
|
+
'gs-mutation-filter-changed': CustomEvent<SelectedMutationFilterStrings>;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
declare global {
|
|
268
|
+
namespace JSX {
|
|
269
|
+
interface IntrinsicElements {
|
|
270
|
+
'gs-mutation-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
declare global {
|
|
277
|
+
interface HTMLElementTagNameMap {
|
|
278
|
+
'gs-lineage-filter': LineageFilterComponent;
|
|
279
|
+
}
|
|
280
|
+
interface HTMLElementEventMap {
|
|
281
|
+
'gs-lineage-filter-changed': CustomEvent<Record<string, string>>;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
declare global {
|
|
287
|
+
namespace JSX {
|
|
288
|
+
interface IntrinsicElements {
|
|
289
|
+
'gs-lineage-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
declare module 'chart.js' {
|
|
296
|
+
interface CartesianScaleTypeRegistry {
|
|
297
|
+
logit: {
|
|
298
|
+
options: CoreScaleOptions;
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
}
|
package/dist/util.js
ADDED
package/dist/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const toYYYYMMDD = (date) => {
|
|
2
|
+
const options = { year: "numeric", month: "2-digit", day: "2-digit" };
|
|
3
|
+
return date.toLocaleDateString("en-CA", options);
|
|
4
|
+
};
|
|
5
|
+
class DateRangeOptionChangedEvent extends CustomEvent {
|
|
6
|
+
constructor(detail) {
|
|
7
|
+
super("gs-date-range-option-changed", {
|
|
8
|
+
detail,
|
|
9
|
+
bubbles: true,
|
|
10
|
+
composed: true
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const today = /* @__PURE__ */ new Date();
|
|
15
|
+
const twoWeeksAgo = /* @__PURE__ */ new Date();
|
|
16
|
+
twoWeeksAgo.setDate(today.getDate() - 14);
|
|
17
|
+
const lastMonth = new Date(today);
|
|
18
|
+
lastMonth.setMonth(today.getMonth() - 1);
|
|
19
|
+
const last2Months = new Date(today);
|
|
20
|
+
last2Months.setMonth(today.getMonth() - 2);
|
|
21
|
+
const last3Months = new Date(today);
|
|
22
|
+
last3Months.setMonth(today.getMonth() - 3);
|
|
23
|
+
const last6Months = new Date(today);
|
|
24
|
+
last6Months.setMonth(today.getMonth() - 6);
|
|
25
|
+
const lastYear = new Date(today);
|
|
26
|
+
lastYear.setFullYear(today.getFullYear() - 1);
|
|
27
|
+
const dateRangeOptionPresets = {
|
|
28
|
+
last2Weeks: {
|
|
29
|
+
label: "Last 2 weeks",
|
|
30
|
+
dateFrom: toYYYYMMDD(twoWeeksAgo)
|
|
31
|
+
},
|
|
32
|
+
lastMonth: {
|
|
33
|
+
label: "Last month",
|
|
34
|
+
dateFrom: toYYYYMMDD(lastMonth)
|
|
35
|
+
},
|
|
36
|
+
last2Months: {
|
|
37
|
+
label: "Last 2 months",
|
|
38
|
+
dateFrom: toYYYYMMDD(last2Months)
|
|
39
|
+
},
|
|
40
|
+
last3Months: {
|
|
41
|
+
label: "Last 3 months",
|
|
42
|
+
dateFrom: toYYYYMMDD(last3Months)
|
|
43
|
+
},
|
|
44
|
+
last6Months: {
|
|
45
|
+
label: "Last 6 months",
|
|
46
|
+
dateFrom: toYYYYMMDD(last6Months)
|
|
47
|
+
},
|
|
48
|
+
lastYear: {
|
|
49
|
+
label: "Last year",
|
|
50
|
+
dateFrom: toYYYYMMDD(lastYear)
|
|
51
|
+
},
|
|
52
|
+
allTimes: {
|
|
53
|
+
label: "All times"
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
DateRangeOptionChangedEvent as D,
|
|
58
|
+
dateRangeOptionPresets as d,
|
|
59
|
+
toYYYYMMDD as t
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=utilEntrypoint-g4DsyhU7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilEntrypoint-g4DsyhU7.js","sources":["../src/preact/dateRangeSelector/dateConversion.ts","../src/preact/dateRangeSelector/dateRangeOption.ts"],"sourcesContent":["export const toYYYYMMDD = (date: Date) => {\n const options: Intl.DateTimeFormatOptions = { year: 'numeric', month: '2-digit', day: '2-digit' };\n return date.toLocaleDateString('en-CA', options);\n};\n","import { toYYYYMMDD } from './dateConversion';\n\n/**\n * A date range option that can be used in the `gs-date-range-selector` component.\n */\nexport type DateRangeOption = {\n /** The label of the date range option that will be shown to the user */\n label: string;\n /**\n * The start date of the date range in the format `YYYY-MM-DD`.\n * If not set, the date range selector will default to the `earliestDate` property.\n */\n dateFrom?: string;\n /**\n * The end date of the date range in the format `YYYY-MM-DD`.\n * If not set, the date range selector will default to the current date.\n */\n dateTo?: string;\n};\n\nexport type DateRangeSelectOption = string | { dateFrom: string; dateTo: string };\nexport class DateRangeOptionChangedEvent extends CustomEvent<DateRangeSelectOption> {\n constructor(detail: DateRangeSelectOption) {\n super('gs-date-range-option-changed', {\n detail,\n bubbles: true,\n composed: true,\n });\n }\n}\n\nconst today = new Date();\n\nconst twoWeeksAgo = new Date();\ntwoWeeksAgo.setDate(today.getDate() - 14);\n\nconst lastMonth = new Date(today);\nlastMonth.setMonth(today.getMonth() - 1);\n\nconst last2Months = new Date(today);\nlast2Months.setMonth(today.getMonth() - 2);\n\nconst last3Months = new Date(today);\nlast3Months.setMonth(today.getMonth() - 3);\n\nconst last6Months = new Date(today);\nlast6Months.setMonth(today.getMonth() - 6);\n\nconst lastYear = new Date(today);\nlastYear.setFullYear(today.getFullYear() - 1);\n\n/**\n * Presets for the `gs-date-range-selector` component that can be used as `dateRangeOptions`.\n */\nexport const dateRangeOptionPresets = {\n last2Weeks: {\n label: 'Last 2 weeks',\n dateFrom: toYYYYMMDD(twoWeeksAgo),\n },\n lastMonth: {\n label: 'Last month',\n dateFrom: toYYYYMMDD(lastMonth),\n },\n last2Months: {\n label: 'Last 2 months',\n dateFrom: toYYYYMMDD(last2Months),\n },\n last3Months: {\n label: 'Last 3 months',\n dateFrom: toYYYYMMDD(last3Months),\n },\n last6Months: {\n label: 'Last 6 months',\n dateFrom: toYYYYMMDD(last6Months),\n },\n lastYear: {\n label: 'Last year',\n dateFrom: toYYYYMMDD(lastYear),\n },\n allTimes: {\n label: 'All times',\n },\n} satisfies Record<string, DateRangeOption>;\n"],"names":[],"mappings":"AAAa,MAAA,aAAa,CAAC,SAAe;AACtC,QAAM,UAAsC,EAAE,MAAM,WAAW,OAAO,WAAW,KAAK;AAC/E,SAAA,KAAK,mBAAmB,SAAS,OAAO;AACnD;ACkBO,MAAM,oCAAoC,YAAmC;AAAA,EAChF,YAAY,QAA+B;AACvC,UAAM,gCAAgC;AAAA,MAClC;AAAA,MACA,SAAS;AAAA,MACT,UAAU;AAAA,IAAA,CACb;AAAA,EACL;AACJ;AAEA,MAAM,4BAAY;AAElB,MAAM,kCAAkB;AACxB,YAAY,QAAQ,MAAM,QAAQ,IAAI,EAAE;AAExC,MAAM,YAAY,IAAI,KAAK,KAAK;AAChC,UAAU,SAAS,MAAM,SAAS,IAAI,CAAC;AAEvC,MAAM,cAAc,IAAI,KAAK,KAAK;AAClC,YAAY,SAAS,MAAM,SAAS,IAAI,CAAC;AAEzC,MAAM,cAAc,IAAI,KAAK,KAAK;AAClC,YAAY,SAAS,MAAM,SAAS,IAAI,CAAC;AAEzC,MAAM,cAAc,IAAI,KAAK,KAAK;AAClC,YAAY,SAAS,MAAM,SAAS,IAAI,CAAC;AAEzC,MAAM,WAAW,IAAI,KAAK,KAAK;AAC/B,SAAS,YAAY,MAAM,YAAY,IAAI,CAAC;AAKrC,MAAM,yBAAyB;AAAA,EAClC,YAAY;AAAA,IACR,OAAO;AAAA,IACP,UAAU,WAAW,WAAW;AAAA,EACpC;AAAA,EACA,WAAW;AAAA,IACP,OAAO;AAAA,IACP,UAAU,WAAW,SAAS;AAAA,EAClC;AAAA,EACA,aAAa;AAAA,IACT,OAAO;AAAA,IACP,UAAU,WAAW,WAAW;AAAA,EACpC;AAAA,EACA,aAAa;AAAA,IACT,OAAO;AAAA,IACP,UAAU,WAAW,WAAW;AAAA,EACpC;AAAA,EACA,aAAa;AAAA,IACT,OAAO;AAAA,IACP,UAAU,WAAW,WAAW;AAAA,EACpC;AAAA,EACA,UAAU;AAAA,IACN,OAAO;AAAA,IACP,UAAU,WAAW,QAAQ;AAAA,EACjC;AAAA,EACA,UAAU;AAAA,IACN,OAAO;AAAA,EACX;AACJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genspectrum/dashboard-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "GenSpectrum web components for building dashboards",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -27,10 +27,15 @@
|
|
|
27
27
|
]
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|
|
30
|
-
"
|
|
31
|
-
"import": "./dist/
|
|
32
|
-
"require": "./dist/
|
|
33
|
-
"types": "./dist/
|
|
30
|
+
"./components": {
|
|
31
|
+
"import": "./dist/components.js",
|
|
32
|
+
"require": "./dist/components.js",
|
|
33
|
+
"types": "./dist/components.d.ts"
|
|
34
|
+
},
|
|
35
|
+
"./util": {
|
|
36
|
+
"import": "./dist/util.js",
|
|
37
|
+
"require": "./dist/util.js",
|
|
38
|
+
"types": "./dist/util.d.ts"
|
|
34
39
|
},
|
|
35
40
|
"./custom-elements.json": "./custom-elements.json",
|
|
36
41
|
"./package.json": "./package.json",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from './web-components';
|
|
2
2
|
|
|
3
3
|
export { type ErrorEvent, UserFacingError } from './preact/components/error-display';
|
|
4
|
-
export { type DateRangeOption, dateRangeOptionPresets } from './preact/dateRangeSelector/dateRangeOption';
|
|
5
4
|
|
|
6
5
|
declare global {
|
|
7
6
|
interface HTMLElementEventMap {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type Meta, type StoryObj } from '@storybook/preact';
|
|
2
|
-
import { expect, userEvent, waitFor, within } from '@storybook/test';
|
|
1
|
+
import { type Meta, type PreactRenderer, type StoryObj } from '@storybook/preact';
|
|
2
|
+
import { expect, fn, userEvent, waitFor, within } from '@storybook/test';
|
|
3
|
+
import type { StepFunction } from '@storybook/types';
|
|
3
4
|
import dayjs from 'dayjs/esm';
|
|
4
5
|
|
|
5
6
|
import { DateRangeSelector, type DateRangeSelectorProps } from './date-range-selector';
|
|
@@ -10,12 +11,18 @@ import { dateRangeOptionPresets } from './dateRangeOption';
|
|
|
10
11
|
|
|
11
12
|
const earliestDate = '1970-01-01';
|
|
12
13
|
|
|
14
|
+
const customDateRange = {
|
|
15
|
+
label: 'CustomDateRange',
|
|
16
|
+
dateFrom: '2021-01-01',
|
|
17
|
+
dateTo: '2021-12-31',
|
|
18
|
+
};
|
|
19
|
+
|
|
13
20
|
const meta: Meta<DateRangeSelectorProps> = {
|
|
14
21
|
title: 'Input/DateRangeSelector',
|
|
15
22
|
component: DateRangeSelector,
|
|
16
23
|
parameters: {
|
|
17
24
|
actions: {
|
|
18
|
-
handles: ['gs-date-range-changed', ...previewHandles],
|
|
25
|
+
handles: ['gs-date-range-filter-changed', 'gs-date-range-option-changed', ...previewHandles],
|
|
19
26
|
},
|
|
20
27
|
fetchMock: {},
|
|
21
28
|
},
|
|
@@ -43,15 +50,7 @@ const meta: Meta<DateRangeSelectorProps> = {
|
|
|
43
50
|
},
|
|
44
51
|
},
|
|
45
52
|
args: {
|
|
46
|
-
dateRangeOptions: [
|
|
47
|
-
dateRangeOptionPresets.lastMonth,
|
|
48
|
-
dateRangeOptionPresets.allTimes,
|
|
49
|
-
{
|
|
50
|
-
label: 'CustomDateRange',
|
|
51
|
-
dateFrom: '2021-01-01',
|
|
52
|
-
dateTo: '2021-12-31',
|
|
53
|
-
},
|
|
54
|
-
],
|
|
53
|
+
dateRangeOptions: [dateRangeOptionPresets.lastMonth, dateRangeOptionPresets.allTimes, customDateRange],
|
|
55
54
|
earliestDate,
|
|
56
55
|
initialValue: dateRangeOptionPresets.lastMonth.label,
|
|
57
56
|
dateColumn: 'aDateColumn',
|
|
@@ -88,14 +87,10 @@ export const SetCorrectInitialValues: StoryObj<DateRangeSelectorProps> = {
|
|
|
88
87
|
play: async ({ canvasElement }) => {
|
|
89
88
|
const canvas = within(canvasElement);
|
|
90
89
|
|
|
91
|
-
const dateFrom = () => canvas.getByPlaceholderText('Date from');
|
|
92
|
-
const dateTo = () => canvas.getByPlaceholderText('Date to');
|
|
93
|
-
const selectField = () => canvas.getByRole('combobox');
|
|
94
|
-
|
|
95
90
|
await waitFor(() => {
|
|
96
|
-
expect(selectField()).toHaveValue('CustomDateRange');
|
|
97
|
-
expect(
|
|
98
|
-
expect(
|
|
91
|
+
expect(selectField(canvas)).toHaveValue('CustomDateRange');
|
|
92
|
+
expect(dateFromPicker(canvas)).toHaveValue('2021-01-01');
|
|
93
|
+
expect(dateToPicker(canvas)).toHaveValue('2021-12-31');
|
|
99
94
|
});
|
|
100
95
|
},
|
|
101
96
|
};
|
|
@@ -111,14 +106,10 @@ export const SetCorrectInitialDateFrom: StoryObj<DateRangeSelectorProps> = {
|
|
|
111
106
|
play: async ({ canvasElement }) => {
|
|
112
107
|
const canvas = within(canvasElement);
|
|
113
108
|
|
|
114
|
-
const dateFrom = () => canvas.getByPlaceholderText('Date from');
|
|
115
|
-
const dateTo = () => canvas.getByPlaceholderText('Date to');
|
|
116
|
-
const selectField = () => canvas.getByRole('combobox');
|
|
117
|
-
|
|
118
109
|
await waitFor(() => {
|
|
119
|
-
expect(selectField()).toHaveValue('Custom');
|
|
120
|
-
expect(
|
|
121
|
-
expect(
|
|
110
|
+
expect(selectField(canvas)).toHaveValue('Custom');
|
|
111
|
+
expect(dateFromPicker(canvas)).toHaveValue(initialDateFrom);
|
|
112
|
+
expect(dateToPicker(canvas)).toHaveValue(dayjs().format('YYYY-MM-DD'));
|
|
122
113
|
});
|
|
123
114
|
},
|
|
124
115
|
};
|
|
@@ -134,37 +125,83 @@ export const SetCorrectInitialDateTo: StoryObj<DateRangeSelectorProps> = {
|
|
|
134
125
|
play: async ({ canvasElement }) => {
|
|
135
126
|
const canvas = within(canvasElement);
|
|
136
127
|
|
|
137
|
-
const dateFrom = () => canvas.getByPlaceholderText('Date from');
|
|
138
|
-
const dateTo = () => canvas.getByPlaceholderText('Date to');
|
|
139
|
-
const selectField = () => canvas.getByRole('combobox');
|
|
140
|
-
|
|
141
128
|
await waitFor(() => {
|
|
142
|
-
expect(selectField()).toHaveValue('Custom');
|
|
143
|
-
expect(
|
|
144
|
-
expect(
|
|
129
|
+
expect(selectField(canvas)).toHaveValue('Custom');
|
|
130
|
+
expect(dateFromPicker(canvas)).toHaveValue(earliestDate);
|
|
131
|
+
expect(dateToPicker(canvas)).toHaveValue(initialDateTo);
|
|
145
132
|
});
|
|
146
133
|
},
|
|
147
134
|
};
|
|
148
135
|
|
|
149
136
|
export const ChangingDateSetsOptionToCustom: StoryObj<DateRangeSelectorProps> = {
|
|
150
137
|
...Primary,
|
|
151
|
-
play: async ({ canvasElement }) => {
|
|
152
|
-
const canvas =
|
|
153
|
-
|
|
154
|
-
const dateFrom = () => canvas.getByPlaceholderText('Date from');
|
|
155
|
-
const dateTo = () => canvas.getByPlaceholderText('Date to');
|
|
156
|
-
const selectField = () => canvas.getByRole('combobox');
|
|
138
|
+
play: async ({ canvasElement, step }) => {
|
|
139
|
+
const { canvas, filterChangedListenerMock, optionChangedListenerMock } = await prepare(canvasElement, step);
|
|
157
140
|
|
|
158
141
|
await waitFor(() => {
|
|
159
|
-
expect(selectField()).toHaveValue('Last month');
|
|
142
|
+
expect(selectField(canvas)).toHaveValue('Last month');
|
|
160
143
|
});
|
|
161
144
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
145
|
+
step('Change date to custom value', async () => {
|
|
146
|
+
await userEvent.type(dateFromPicker(canvas), '{backspace>12}');
|
|
147
|
+
await userEvent.type(dateFromPicker(canvas), '2000-01-01');
|
|
148
|
+
await userEvent.click(dateToPicker(canvas));
|
|
149
|
+
|
|
150
|
+
await waitFor(() => {
|
|
151
|
+
expect(selectField(canvas)).toHaveValue('Custom');
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
await expect(filterChangedListenerMock).toHaveBeenCalledWith(
|
|
155
|
+
expect.objectContaining({
|
|
156
|
+
detail: {
|
|
157
|
+
aDateColumnFrom: '2000-01-01',
|
|
158
|
+
aDateColumnTo: dayjs().format('YYYY-MM-DD'),
|
|
159
|
+
},
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
await expect(optionChangedListenerMock).toHaveBeenCalledWith(
|
|
164
|
+
expect.objectContaining({
|
|
165
|
+
detail: {
|
|
166
|
+
dateFrom: '2000-01-01',
|
|
167
|
+
dateTo: dayjs().format('YYYY-MM-DD'),
|
|
168
|
+
},
|
|
169
|
+
}),
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export const ChangingDateOption: StoryObj<DateRangeSelectorProps> = {
|
|
176
|
+
...Primary,
|
|
177
|
+
play: async ({ canvasElement, step }) => {
|
|
178
|
+
const { canvas, filterChangedListenerMock, optionChangedListenerMock } = await prepare(canvasElement, step);
|
|
165
179
|
|
|
166
180
|
await waitFor(() => {
|
|
167
|
-
expect(selectField()).toHaveValue('
|
|
181
|
+
expect(selectField(canvas)).toHaveValue('Last month');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
step('Change date to custom', async () => {
|
|
185
|
+
await userEvent.selectOptions(selectField(canvas), 'CustomDateRange');
|
|
186
|
+
|
|
187
|
+
await waitFor(() => {
|
|
188
|
+
expect(selectField(canvas)).toHaveValue('CustomDateRange');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
await expect(filterChangedListenerMock).toHaveBeenCalledWith(
|
|
192
|
+
expect.objectContaining({
|
|
193
|
+
detail: {
|
|
194
|
+
aDateColumnFrom: customDateRange.dateFrom,
|
|
195
|
+
aDateColumnTo: customDateRange.dateTo,
|
|
196
|
+
},
|
|
197
|
+
}),
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
await expect(optionChangedListenerMock).toHaveBeenCalledWith(
|
|
201
|
+
expect.objectContaining({
|
|
202
|
+
detail: customDateRange.label,
|
|
203
|
+
}),
|
|
204
|
+
);
|
|
168
205
|
});
|
|
169
206
|
},
|
|
170
207
|
};
|
|
@@ -183,3 +220,23 @@ export const HandlesInvalidInitialDateFrom: StoryObj<DateRangeSelectorProps> = {
|
|
|
183
220
|
});
|
|
184
221
|
},
|
|
185
222
|
};
|
|
223
|
+
|
|
224
|
+
async function prepare(canvasElement: HTMLElement, step: StepFunction<PreactRenderer, unknown>) {
|
|
225
|
+
const canvas = within(canvasElement);
|
|
226
|
+
|
|
227
|
+
const filterChangedListenerMock = fn();
|
|
228
|
+
await step('Setup event listener mock', async () => {
|
|
229
|
+
canvasElement.addEventListener('gs-date-range-filter-changed', filterChangedListenerMock);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const optionChangedListenerMock = fn();
|
|
233
|
+
await step('Setup event listener mock', async () => {
|
|
234
|
+
canvasElement.addEventListener('gs-date-range-option-changed', optionChangedListenerMock);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
return { canvas, filterChangedListenerMock, optionChangedListenerMock };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const dateFromPicker = (canvas: ReturnType<typeof within>) => canvas.getByPlaceholderText('Date from');
|
|
241
|
+
const dateToPicker = (canvas: ReturnType<typeof within>) => canvas.getByPlaceholderText('Date to');
|
|
242
|
+
const selectField = (canvas: ReturnType<typeof within>) => canvas.getByRole('combobox');
|