@genspectrum/dashboard-components 0.4.1 → 0.4.2
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/custom-elements.json +2 -2
- package/dist/dashboard-components.js +10 -6
- package/dist/dashboard-components.js.map +1 -1
- package/dist/genspectrum-components.d.ts +4 -4
- package/package.json +1 -1
- package/src/preact/locationFilter/location-filter.tsx +9 -2
- package/src/preact/textInput/text-input.tsx +2 -2
- package/src/web-components/input/gs-location-filter.stories.ts +9 -0
- package/src/web-components/input/gs-text-input.stories.ts +6 -0
package/custom-elements.json
CHANGED
|
@@ -521,7 +521,7 @@
|
|
|
521
521
|
"type": {
|
|
522
522
|
"text": "StoryObj<LocationFilterProps>"
|
|
523
523
|
},
|
|
524
|
-
"default": "{ ...Template, parameters: { fetchMock: { mocks: [ { matcher: aggregatedEndpointMatcher, response: { status: 200, body: data, }, }, ], }, }, play: async ({ canvasElement, step }) => { const canvas = await withinShadowRoot(canvasElement, 'gs-location-filter'); const inputField = () => canvas.getByRole('combobox'); const listenerMock = fn(); await step('Setup event listener mock', async () => { canvasElement.addEventListener('gs-location-changed', listenerMock); }); await step('wait until data is loaded', async () => { await waitFor(() => { return expect(inputField()).toBeEnabled(); }); }); await step('Input invalid location', async () => { await userEvent.type(inputField(), 'Not / A / Location'); await expect(listenerMock).not.toHaveBeenCalled(); await userEvent.type(inputField(), '{backspace>18/}'); }); await step('Select Asia', async () => { await userEvent.type(inputField(), 'Asia'); await expect(listenerMock.mock.calls.at(-1)[0].detail).toStrictEqual({ region: 'Asia', country: undefined, division: undefined, location: undefined, }); }); await step('Select Asia / Bangladesh / Rajshahi / Chapainawabgonj', async () => { await userEvent.type(inputField(), ' / Bangladesh / Rajshahi / Chapainawabgonj'); await expect(listenerMock).toHaveBeenCalledWith( expect.objectContaining({ detail: { region: 'Asia', country: 'Bangladesh', division: 'Rajshahi', location: 'Chapainawabgonj', }, }), ); }); }, }"
|
|
524
|
+
"default": "{ ...Template, parameters: { fetchMock: { mocks: [ { matcher: aggregatedEndpointMatcher, response: { status: 200, body: data, }, }, ], }, }, play: async ({ canvasElement, step }) => { const canvas = await withinShadowRoot(canvasElement, 'gs-location-filter'); const inputField = () => canvas.getByRole('combobox'); const listenerMock = fn(); await step('Setup event listener mock', async () => { canvasElement.addEventListener('gs-location-changed', listenerMock); }); await step('wait until data is loaded', async () => { await waitFor(() => { return expect(inputField()).toBeEnabled(); }); }); await step('Input invalid location', async () => { await userEvent.type(inputField(), 'Not / A / Location'); await expect(listenerMock).not.toHaveBeenCalled(); }); await step('Empty input', async () => { await userEvent.type(inputField(), '{backspace>18/}'); await expect(listenerMock.mock.calls.at(-1)[0].detail).toStrictEqual({ region: undefined, country: undefined, division: undefined, location: undefined, }); }); await step('Select Asia', async () => { await userEvent.type(inputField(), 'Asia'); await expect(listenerMock.mock.calls.at(-1)[0].detail).toStrictEqual({ region: 'Asia', country: undefined, division: undefined, location: undefined, }); }); await step('Select Asia / Bangladesh / Rajshahi / Chapainawabgonj', async () => { await userEvent.type(inputField(), ' / Bangladesh / Rajshahi / Chapainawabgonj'); await expect(listenerMock).toHaveBeenCalledWith( expect.objectContaining({ detail: { region: 'Asia', country: 'Bangladesh', division: 'Rajshahi', location: 'Chapainawabgonj', }, }), ); }); }, }"
|
|
525
525
|
}
|
|
526
526
|
],
|
|
527
527
|
"exports": [
|
|
@@ -863,7 +863,7 @@
|
|
|
863
863
|
"type": {
|
|
864
864
|
"text": "StoryObj<Required<TextInputProps>>"
|
|
865
865
|
},
|
|
866
|
-
"default": "{ ...Default, play: async ({ canvasElement, step }) => { const canvas = await withinShadowRoot(canvasElement, 'gs-text-input'); const inputField = () => canvas.getByPlaceholderText('Enter host name'); const listenerMock = fn(); await step('Setup event listener mock', async () => { canvasElement.addEventListener('gs-text-input-changed', listenerMock); }); await step('wait until data is loaded', async () => { await waitFor(() => { return expect(inputField()).toBeEnabled(); }); }); await step('Enters an invalid host name', async () => { await userEvent.type(inputField(), 'notInList'); await expect(listenerMock).not.toHaveBeenCalled(); await userEvent.type(inputField(), '{backspace>9/}'); }); await step('Enter a valid host name', async () => { await userEvent.type(inputField(), 'Homo'); await expect(listenerMock).toHaveBeenCalledWith( expect.objectContaining({ detail: { host: 'Homo', }, }), ); }); }, args: { ...Default.args, initialValue: '', }, }"
|
|
866
|
+
"default": "{ ...Default, play: async ({ canvasElement, step }) => { const canvas = await withinShadowRoot(canvasElement, 'gs-text-input'); const inputField = () => canvas.getByPlaceholderText('Enter host name'); const listenerMock = fn(); await step('Setup event listener mock', async () => { canvasElement.addEventListener('gs-text-input-changed', listenerMock); }); await step('wait until data is loaded', async () => { await waitFor(() => { return expect(inputField()).toBeEnabled(); }); }); await step('Enters an invalid host name', async () => { await userEvent.type(inputField(), 'notInList'); await expect(listenerMock).not.toHaveBeenCalled(); }); await step('Empty input', async () => { await userEvent.type(inputField(), '{backspace>9/}'); await expect(listenerMock.mock.calls.at(-1)[0].detail).toStrictEqual({ host: undefined, }); }); await step('Enter a valid host name', async () => { await userEvent.type(inputField(), 'Homo'); await expect(listenerMock).toHaveBeenCalledWith( expect.objectContaining({ detail: { host: 'Homo', }, }), ); }); }, args: { ...Default.args, initialValue: '', }, }"
|
|
867
867
|
}
|
|
868
868
|
],
|
|
869
869
|
"exports": [
|
|
@@ -7795,11 +7795,11 @@ const LocationFilterInner = ({ initialValue, fields }) => {
|
|
|
7795
7795
|
var _a;
|
|
7796
7796
|
const inputValue = event.currentTarget.value;
|
|
7797
7797
|
setValue(inputValue);
|
|
7798
|
-
if (inputValue.trim() === value.trim()) {
|
|
7798
|
+
if (inputValue.trim() === value.trim() && inputValue !== "") {
|
|
7799
7799
|
return;
|
|
7800
7800
|
}
|
|
7801
7801
|
const eventDetail = parseLocation(inputValue, fields);
|
|
7802
|
-
if (hasMatchingEntry(data, eventDetail)) {
|
|
7802
|
+
if (hasAllUndefined(eventDetail) || hasMatchingEntry(data, eventDetail)) {
|
|
7803
7803
|
(_a = divRef.current) == null ? void 0 : _a.dispatchEvent(
|
|
7804
7804
|
new CustomEvent("gs-location-changed", {
|
|
7805
7805
|
detail: eventDetail,
|
|
@@ -7830,9 +7830,13 @@ const LocationFilterInner = ({ initialValue, fields }) => {
|
|
|
7830
7830
|
] });
|
|
7831
7831
|
};
|
|
7832
7832
|
const parseLocation = (location, fields) => {
|
|
7833
|
+
if (location === "") {
|
|
7834
|
+
return fields.reduce((acc, field) => ({ ...acc, [field]: void 0 }), {});
|
|
7835
|
+
}
|
|
7833
7836
|
const fieldValues = location.split("/").map((part) => part.trim());
|
|
7834
7837
|
return fields.reduce((acc, field, i2) => ({ ...acc, [field]: fieldValues[i2] }), {});
|
|
7835
7838
|
};
|
|
7839
|
+
const hasAllUndefined = (obj) => Object.values(obj).every((value) => value === void 0);
|
|
7836
7840
|
const hasMatchingEntry = (data, eventDetail) => {
|
|
7837
7841
|
if (data === null) {
|
|
7838
7842
|
return false;
|
|
@@ -7901,10 +7905,10 @@ const TextInputInner = ({
|
|
|
7901
7905
|
return /* @__PURE__ */ u$1(NoDataDisplay, {});
|
|
7902
7906
|
}
|
|
7903
7907
|
const onInput = () => {
|
|
7904
|
-
var _a, _b;
|
|
7905
|
-
const value = (_a = inputRef.current) == null ? void 0 : _a.value;
|
|
7908
|
+
var _a, _b, _c;
|
|
7909
|
+
const value = ((_a = inputRef.current) == null ? void 0 : _a.value) === "" ? void 0 : (_b = inputRef.current) == null ? void 0 : _b.value;
|
|
7906
7910
|
if (isValidValue(value)) {
|
|
7907
|
-
(
|
|
7911
|
+
(_c = inputRef.current) == null ? void 0 : _c.dispatchEvent(
|
|
7908
7912
|
new CustomEvent("gs-text-input-changed", {
|
|
7909
7913
|
detail: { [lapisField]: value },
|
|
7910
7914
|
bubbles: true,
|
|
@@ -7915,7 +7919,7 @@ const TextInputInner = ({
|
|
|
7915
7919
|
};
|
|
7916
7920
|
const isValidValue = (value) => {
|
|
7917
7921
|
if (value === void 0) {
|
|
7918
|
-
return
|
|
7922
|
+
return true;
|
|
7919
7923
|
}
|
|
7920
7924
|
return data.includes(value);
|
|
7921
7925
|
};
|