Skip to content

Commit

Permalink
Merge pull request #189 from kbss-cvut/fetch-type-ahead
Browse files Browse the repository at this point in the history
Add simulation of possible values endpoint
  • Loading branch information
blcham authored Nov 2, 2022
2 parents 7f8d24b + 8298ed2 commit c3d2fef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export const globalTypes = {
defaultValue: false,
control: { type: "boolean" },
},
timeOut: {
name: "Time Out (ms)",
description: "Set time-out for possible values (in ms)",
defaultValue: 1500,
control: { type: "number", min: 0, max: 10000, step: 500 },
},
};

const options = {
Expand Down
16 changes: 14 additions & 2 deletions src/stories/SForms.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import occurrenceReportingForm from "./assets/form/occurrenceReportingForm.json"
import queryString from "query-string";
import Constants from "../constants/Constants";
import IntlContextProvider from "../contexts/IntlContextProvider";
import possibleValues from "./assets/possibleValues.json";

const getP = (queryParameterName: string, defaultValue: string) => {
return {
Expand Down Expand Up @@ -39,7 +40,7 @@ export default {

const Template: ComponentStory<typeof SForms> = (
args,
{ globals: { iconBehavior, locale, debugMode, horizontalNavBar } }
{ globals: { iconBehavior, locale, debugMode, horizontalNavBar, timeOut } }
) => {
const options = {
i18n: {
Expand Down Expand Up @@ -82,9 +83,20 @@ const Template: ComponentStory<typeof SForms> = (
},
],
};

const fetchTypeAheadValues = () => {
return new Promise((resolve) =>
setTimeout(() => resolve(possibleValues), timeOut)
);
};

return (
<IntlContextProvider locale={locale}>
<SForms {...args} options={options} />
<SForms
{...args}
options={options}
fetchTypeAheadValues={fetchTypeAheadValues}
/>
</IntlContextProvider>
);
};
Expand Down

0 comments on commit c3d2fef

Please sign in to comment.