Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make form data optional #70

Merged
merged 2 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"lint": "yarn run eslint src",
"lint:fix": "yarn run lint --fix",
"prettify": "prettier --write",
"prepare": "yarn run build",
"prepare": "yarn run build && husky install",
"clean": "yarn clean:modules && yarn clean:cache",
"clean:cache": "yarn clean cache",
"clean:modules": "rimraf node_modules",
Expand Down Expand Up @@ -222,7 +222,7 @@
"eslint-plugin-redux-saga": "1.1.3",
"eslint-plugin-storybook": "^0.6.4",
"github-markdown-css": "~4.0.0",
"husky": "^7.0.2",
"husky": "^8.0.0",
"jest": "26.6.3",
"jest-canvas-mock": "^2.3.1",
"jest-circus": "^26.6.3",
Expand Down
3 changes: 1 addition & 2 deletions src/React/components/TrixtaFormComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { FormProps } from '@rjsf/core';
import * as React from 'react';
import { config, TrixtaFormProps } from '../../../config';
import { getDefaultUISchema } from '../../../utils/trixta';
import { DefaultUnknownType } from '../../types/common';

const withTheme = (props: TrixtaFormProps) => {
let rjsf = undefined;
Expand All @@ -27,7 +26,7 @@ export interface TrixtaReactJsonSchemaFormProps<TFormData>
isInProgress: boolean;
}

function TrixtaFormComponent<TFormData = DefaultUnknownType>({
function TrixtaFormComponent<TFormData = never>({
isRequestForEffect,
onSubmit,
idPrefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function mapDispatchToProps(
ownProps: TrixtaActionComponentProps,
) {
return {
dispatchSubmitActionResponse: (formData: DefaultUnknownType) =>
dispatchSubmitActionResponse: (formData?: DefaultUnknownType) =>
dispatch(
submitTrixtaActionResponse({
extraData: ownProps.extraData,
Expand Down
4 changes: 2 additions & 2 deletions src/React/components/actions/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { DefaultUnknownType, TrixtaCommon, TrixtaDispatch } from '../../types';
import { TrixtaInstanceResponse } from './../../types';
export interface TrixtaActionComponentArgs<
TFormData = DefaultUnknownType,
TSuccessType = DefaultUnknownType,
TErrorType = DefaultUnknownType
> {
Expand All @@ -13,7 +13,7 @@ export interface TrixtaActionComponentArgs<
* Name of Trixta role
*/
roleName: string;
submit: TrixtaDispatch<TFormData>;
submit: TrixtaDispatch<any>;
common: TrixtaCommon;
isInProgress: boolean;
response?: TrixtaInstanceResponse<TSuccessType, TErrorType>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react';
import { connect } from 'react-redux';
import { Dispatch } from 'redux';
Expand All @@ -21,6 +22,7 @@ import {
TrixtaState,
} from './../../../types/common';
import { TrixtaReactionInstanceComponentProps } from './types';

function TrixtaReactionInstanceComponent({
dispatchSubmitReactionResponse,
roleName,
Expand Down Expand Up @@ -122,7 +124,7 @@ function mapDispatchToProps(
ownProps: TrixtaReactionInstanceComponentProps,
) {
return {
dispatchSubmitReactionResponse: (formData: unknown) =>
dispatchSubmitReactionResponse: (formData: any) =>
dispatch(
submitTrixtaReactionResponse({
formData,
Expand Down
7 changes: 4 additions & 3 deletions src/React/components/reactions/types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {
TrixtaCommon,
TrixtaDispatch,
TrixtaReactionBaseProps,
} from '../../types';
import {
DefaultUnknownType,
TrixtaReactionInstanceDetails,
TrixtaInstanceResponse,
TrixtaReactionInstanceDetails,
} from './../../types/common';

export interface TrixtaReactionComponentArgs<
TInitialData = DefaultUnknownType,
TFormData = DefaultUnknownType,
TSuccessType = DefaultUnknownType,
TErrorType = DefaultUnknownType
> extends TrixtaReactionBaseProps {
submit: TrixtaDispatch<TFormData>;
submit: TrixtaDispatch<any>;
common: TrixtaCommon;
data: TInitialData;
isInProgress: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { renderHook } from '@testing-library/react-hooks';
import { mockStoreProviderWrapper } from '../../../tests/helpers';
// eslint-disable-next-line jest/no-mocks-import
Expand Down
6 changes: 4 additions & 2 deletions src/React/reduxActions/trixtaActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
* @param params.requestEvent - event for data to dispatch to on trixta action before submitting to trixta
* @param params.errorEvent - event for error to dispatch to on trixta action error response
*/
export function submitTrixtaActionResponse<TFormData extends unknown>({
export function submitTrixtaActionResponse<TFormData = never>({
clearResponse = false,
debugMode = false,
actionOptions = {},
Expand All @@ -41,7 +41,9 @@ export function submitTrixtaActionResponse<TFormData extends unknown>({
},
},
...rest
}: SubmitTrixtaActionResponse<TFormData>): SubmitTrixtaActionResponseAction {
}: SubmitTrixtaActionResponse<TFormData>): SubmitTrixtaActionResponseAction<
TFormData
> {
return {
type: SUBMIT_TRIXTA_ACTION_RESPONSE,
payload: {
Expand Down
2 changes: 1 addition & 1 deletion src/React/reduxActions/trixtaReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
* @param params.requestEvent - event for data to dispatch to on trixta reaction before submitting to trixta
* @param params.errorEvent - event for error to dispatch to on trixta reaction error response
*/
export function submitTrixtaReactionResponse<TFormData extends unknown>({
export function submitTrixtaReactionResponse<TFormData = never>({
responseEvent = undefined,
requestEvent = undefined,
errorEvent = undefined,
Expand Down
3 changes: 1 addition & 2 deletions src/React/reduxActions/types/trixtaActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
TrixtaActionDetails,
TrixtaActionResponseDetails,
} from '../../types/actions';
import { DefaultUnknownType } from '../../types/common';
import {
SubmitTrixtaActionResponseFailureAction,
SubmitTrixtaActionResponseSuccessAction,
Expand Down Expand Up @@ -54,7 +53,7 @@ export type ClearTrixtaActionRequestStatusAction = {
};
};

export type SubmitTrixtaActionResponseAction<TFormData = DefaultUnknownType> = {
export type SubmitTrixtaActionResponseAction<TFormData = never> = {
type: typeof SUBMIT_TRIXTA_ACTION_RESPONSE;
payload: {
formData?: TFormData;
Expand Down
4 changes: 1 addition & 3 deletions src/React/reduxActions/types/trixtaReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ export type ClearTrixtaReactionRequestStatusAction = {
};
};

export type SubmitTrixtaReactionResponseAction<
TFormData = DefaultUnknownType
> = {
export type SubmitTrixtaReactionResponseAction<TFormData = never> = {
type: typeof SUBMIT_TRIXTA_REACTION_RESPONSE;
payload: {
formData?: TFormData;
Expand Down
1 change: 1 addition & 0 deletions src/React/sagas/setupTrixtaSaga.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {
all,
fork,
Expand Down
18 changes: 12 additions & 6 deletions src/React/types/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ export interface ClearTrixtaActionRequestStatus {
loadingStatusRef?: string;
}

export interface SubmitTrixtaActionResponse<TFormData = DefaultUnknownType> {
type FormData<T = never> = [T] extends [never]
? { formData?: never }
: {
/**
* Data to submit to Trixta
*/
formData: T;
};
export type SubmitTrixtaActionResponse<TFormData = never> = FormData<
TFormData
> & {
/**
* Name of Trixta role
*/
Expand All @@ -92,10 +102,6 @@ export interface SubmitTrixtaActionResponse<TFormData = DefaultUnknownType> {
* Name of Trixta action
*/
actionName: string;
/**
* Data to submit to Trixta
*/
formData: TFormData;
/**
* Extra data to pass on and receive in response with the key extraData. This can be used
* as needed.
Expand Down Expand Up @@ -146,7 +152,7 @@ export interface SubmitTrixtaActionResponse<TFormData = DefaultUnknownType> {
* If you plan to use the same action / reaction name for the same role, on the same screen, this is when you would make use of this * property
*/
loadingStatusRef?: string;
}
};

export interface TrixtaActionBaseProps extends TrixtaBaseRoleProps {
/**
Expand Down
18 changes: 12 additions & 6 deletions src/React/types/reactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,17 @@ export interface ClearTrixtaReactionRequestStatus {
loadingStatusRef?: string;
}

export interface SubmitTrixtaReactionResponse<TFormData = DefaultUnknownType> {
type FormData<T = never> = [T] extends [never]
? { formData?: never }
: {
/**
* Data to submit to Trixta
*/
formData: T;
};
export type SubmitTrixtaReactionResponse<TFormData = never> = FormData<
TFormData
> & {
/**
* Name of Trixta role
*/
Expand All @@ -94,10 +104,6 @@ export interface SubmitTrixtaReactionResponse<TFormData = DefaultUnknownType> {
* Name of Trixta reaction
*/
reactionName: string;
/**
* Data to submit to Trixta
*/
formData: TFormData;
/**
* Extra data to pass on and receive in response with the key extraData. This can be used
* as needed.
Expand Down Expand Up @@ -136,7 +142,7 @@ export interface SubmitTrixtaReactionResponse<TFormData = DefaultUnknownType> {
* If you plan to use the same action / reaction name for the same role, on the same screen, this is when you would make use of this * property
*/
loadingStatusRef?: string;
}
};

export interface TrixtaReaction {
common: TrixtaCommon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
},
} as ComponentMeta<typeof TrixtaLoginWidget>;

const Template: ComponentStory<typeof TrixtaLoginWidget> = (args, globals) => (
const Template: ComponentStory<typeof TrixtaLoginWidget> = (args) => (
<TrixtaLoginWidget {...args} />
);

Expand Down
6 changes: 1 addition & 5 deletions src/stories/utils/FormComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@


import { FormProps, withTheme } from '@rjsf/core';
import * as React from 'react';
import { Button } from 'react-bootstrap';
import { DefaultUnknownType } from '../../React/types/common';


const ThemedForm = withTheme({});
export interface TrixtaReactJsonSchemaFormProps<TFormData>
extends FormProps<TFormData> {
submittable?: boolean;
}

function TrixtaFormComponent<TFormData = DefaultUnknownType>({
function TrixtaFormComponent<TFormData = never>({
submittable = true,
onSubmit,
idPrefix,
Expand Down
17 changes: 7 additions & 10 deletions src/stories/utils/ReduxDecorator.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { StoryFn } from '@storybook/addons'
import { DecoratorFn } from '@storybook/react'
import React from 'react'
import { Provider } from 'react-redux'
import store from '../store'
import { DecoratorFn } from '@storybook/react';
import React from 'react';
import { Provider } from 'react-redux';
import store from '../store';


export const withStore: DecoratorFn = (Story:StoryFn) => {
export const withStore: DecoratorFn = (Story) => {
return (
<Provider store={store}>
<Story />
</Provider>
)
}

);
};
13 changes: 0 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10571,7 +10571,6 @@ husky@^4.3.8:
slash "^3.0.0"
which-pm-runs "^1.0.0"


husky@^8.0.0:
version "8.0.1"
resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.1.tgz#511cb3e57de3e3190514ae49ed50f6bc3f50b3e9"
Expand Down Expand Up @@ -15820,11 +15819,6 @@ redeyed@~2.1.0:
dependencies:
esprima "~4.0.0"

redux-listener-middleware@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/redux-listener-middleware/-/redux-listener-middleware-0.2.0.tgz#fe80b6a89583d62d1b5e1d386ae18f9f28284b30"
integrity sha512-wLfH18FNx+/mVln7uciP4PGoHgVDJ8L2/xt8AWu2bpkgJA7W179S6CFvef7iELmc/tfO22UoiljmfEf3AcYRIw==

redux-mock-store@^1.5.4:
version "1.5.4"
resolved "https://registry.yarnpkg.com/redux-mock-store/-/redux-mock-store-1.5.4.tgz#90d02495fd918ddbaa96b83aef626287c9ab5872"
Expand Down Expand Up @@ -17013,13 +17007,6 @@ store2@^2.12.0:
resolved "https://registry.yarnpkg.com/store2/-/store2-2.12.0.tgz#e1f1b7e1a59b6083b2596a8d067f6ee88fd4d3cf"
integrity sha512-7t+/wpKLanLzSnQPX8WAcuLCCeuSHoWdQuh9SB3xD0kNOM38DNf+0Oa+wmvxmYueRzkmh6IcdKFtvTa+ecgPDw==

storybook-addon-redux-listener@^0.1.7:
version "0.1.7"
resolved "https://registry.yarnpkg.com/storybook-addon-redux-listener/-/storybook-addon-redux-listener-0.1.7.tgz#a5299dfdb0f183315673a24677b4dd9d50c679a3"
integrity sha512-rV/fPS/E00InE7tLjJktGUjd3V30hBpqHdBoNjo9tymjZ+G/iBsmBJAUxt2VkXh9xy4i04letNGri0JowvVF+Q==
dependencies:
redux-listener-middleware "^0.2.0"

storybook-addon-toolbar-actions@^0.4.8:
version "0.4.8"
resolved "https://registry.yarnpkg.com/storybook-addon-toolbar-actions/-/storybook-addon-toolbar-actions-0.4.8.tgz#4bda041f22bab80bf2be99e26026fffc622a5173"
Expand Down