Sorry, but you either have no stories or none are selected somehow.
If the problem persists, check the browser console, or the terminal you've run Storybook from.
The component failed to render properly, likely due to a configuration issue in Storybook. Here are some common causes and how you can address them:
Two helper services are included in the library to help with initializing components when sending values to the Disciple.Tools API.
This will provide a structured way to send and receive data with the standard Disciple.Tools API.
To initialize, instantiate the class while passing a WP nonce (for authentication) and the
root path of the WordPress API (if different than wp-json
).
const apiService = new ApiService(wpnonce);
A few utility methods are used internally to share logic among all the endpoint methods:
makeRequest
Name | Type | Description |
---|---|---|
type | string | HTTP Method |
url | string | Either full URL to API endpoint or just the URL segment after base |
data | object | Post data to send in body of request |
base (optional) | Base of URL endpoint. Defaults to "dt/v1/" |
Promise with body of response as JSON object.
makeRequestOnPosts
Specific use of makeRequest
for all of the endpoints that are specific to a given post.
Sets the base
argument and passes all of the rest through to makeRequest
return this.makeRequest(type, url, data, 'dt-posts/v2/');
Most standard endpoints that are needed for the web components have been implemented. Those include (but may not be limited to):
See the source code for details of all endpoints included.
Refer to theme documentation for all of the available endpoints.
The ComponentService helps to initialize the ApiService and hook up all change events for a given page on Disciple.Tools. Once a post page is loaded in the theme, you just run the following to setup all of the needed event listeners:
const componentService = new ComponentService(postType, postId, nonce, apiRoot); componentService.initialize();
The constructor will instantiate the ApiService for use within event listeners within
the service. The initialize()
method will attach various event listeners. These
two methods should generally be the only methods needed in client scripts alongside
web components.
initialize()
Convenience method to call two other service methods:
postId
(from the constructor), calls enableAutoSave()
. This will connect change events to the API on the post detail screen.attachLoadEvents()
to connect dt:get-data
events to API for fetching field options.attachLoadEvents(selector)
For all components in this.dynamicLoadComponents
(or overridden by selector
parameter),
this will attach event listeners to the dt:get-data
event that is dispatched by components
that have an autocomplete function or need a list of values from the API.
enableAutoSave(selector)
For all components in this.autoSaveComponents
(or overridden by selector
parameter),
this will attach event listeners to the change
event that is dispatched by form
components and call the handleChangeEvent()
function.
handleChangeEvent(event)
Calls the convertValue()
function to convert the value of the component to the format
required by the API and then send the value to the API to be saved.
While saving, this sets the loading
attribute and will set the saved
or error
attributes
on success or failure of the API request.
convertValue(component, value, oldValue)
Based on the name of the component
, this transforms the value from the format returned
by the component to the format required by the API.
convertApiValue(component, value)
Based on the name of the component
, this transforms the value from the format returned
by the API to the format required by the component.