diff --git a/src/App.tsx b/src/App.tsx index 95effb1..0c5021c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,7 +4,7 @@ import { Route, Routes } from 'react-router-dom'; import * as config from '../environment.json'; -import { Document } from './pages/Document'; +import { Document } from './pages/Document/Document'; import buildingFromSource from './pages/GettingStarted/BuildingFromSource.md'; import gswApacheMavenPath from './pages/GettingStarted/GettingStartedWithApacheMaven.md'; import gswGradlePath from './pages/GettingStarted/GettingStartedWithGradle.md'; diff --git a/src/Hooks/types.d.ts b/src/Hooks/types.d.ts new file mode 100644 index 0000000..10b6c41 --- /dev/null +++ b/src/Hooks/types.d.ts @@ -0,0 +1,44 @@ +declare module 'spock-react/hooks-types' { + import { IFeature, ISummary } from 'spock-react-types'; + + export interface IMarkdown { + filePath: string; + } + + export interface ISpec { + className: string; + statistics: { + runs: string; + passed: string; + failed: string; + featureFailures: string; + successRate: string; + duration: string; + }; + title: string; + narrative: string; + headers: string[]; + tags: any; + see: any[]; + features: IFeature[]; + generator: string; + } + + export interface IGetSpec { + fileName: string; + } + + export interface IGenerateSearchEntries { + summary?: ISummary; + } + + export interface IActiveLink { + activeLink: string; + setActiveLink: (newLink: string) => void; + } + + export interface IActiveAnchor { + activeAnchor: string; + setActiveAnchor: (newAnchor: string) => void; + } +} diff --git a/src/Hooks/useActiveAnchor.ts b/src/Hooks/useActiveAnchor.ts index 09ce008..66d09f4 100644 --- a/src/Hooks/useActiveAnchor.ts +++ b/src/Hooks/useActiveAnchor.ts @@ -1,3 +1,4 @@ +import { IActiveAnchor } from 'spock-react/hooks-types'; import { create } from 'zustand'; const getInitialState = () => { @@ -9,10 +10,6 @@ const getInitialState = () => { return pageAndAnchor.length === 2 ? decodeURI(pageAndAnchor[1]) : ''; }; -interface IActiveAnchor { - activeAnchor: string; - setActiveAnchor: (newAnchor: string) => void; -} export const useActiveAnchor = create((set) => ({ activeAnchor: getInitialState(), setActiveAnchor: (newAnchor: string) => { diff --git a/src/Hooks/useActiveLink.ts b/src/Hooks/useActiveLink.ts index 8f60197..eceb24e 100644 --- a/src/Hooks/useActiveLink.ts +++ b/src/Hooks/useActiveLink.ts @@ -1,5 +1,6 @@ import { create } from 'zustand'; import * as config from '../../environment.json'; +import { IActiveLink } from 'spock-react/hooks-types'; const getInitialState = () => { const pageAndAnchor = window.location.pathname.split('#'); @@ -11,10 +12,6 @@ const getInitialState = () => { return page; }; -interface IActiveLink { - activeLink: string; - setActiveLink: (newLink: string) => void; -} export const useActiveLink = create((set) => ({ activeLink: getInitialState(), setActiveLink: (newLink: string) => { diff --git a/src/Hooks/useGenerateSearchEntries.ts b/src/Hooks/useGenerateSearchEntries.ts index 6e3949d..3c6f27c 100644 --- a/src/Hooks/useGenerateSearchEntries.ts +++ b/src/Hooks/useGenerateSearchEntries.ts @@ -1,15 +1,12 @@ import { useEffect, useState } from 'react'; +import { cleanedSearchData } from '../components/Search/generateSearchEntries'; +import { ISpecification } from 'spock-react-types'; +import { IGenerateSearchEntries } from 'spock-react/hooks-types'; import { - cleanedSearchData, IMinimizedSummaryEntry, ISearchEntry, -} from '../components/Search/generateSearchEntries'; -import { ISpecification, ISummary } from './useGetSummary'; - -interface IGenerateSearchEntries { - summary?: ISummary; -} +} from 'spock-react/components/search-types'; export const useGenerateSearchEntries = ( props: IGenerateSearchEntries diff --git a/src/Hooks/useGetSpec.ts b/src/Hooks/useGetSpec.ts index 3d66645..5215bfd 100644 --- a/src/Hooks/useGetSpec.ts +++ b/src/Hooks/useGetSpec.ts @@ -3,44 +3,7 @@ import axios from 'axios'; import { useQuery, UseQueryResult } from '@tanstack/react-query'; import config from '../../environment.json'; - -interface IBlock { - kind: string; - text: string; - code: string[]; -} - -export interface IFeature { - id: string; - result: string; - duration: string; - iterations: { - tags: any; - see: any[]; - extraInfo: any[]; - }; - blocks: IBlock[]; - problems: any[]; -} - -interface ISpec { - className: string; - statistics: { - runs: string; - passed: string; - failed: string; - featureFailures: string; - successRate: string; - duration: string; - }; - title: string; - narrative: string; - headers: string[]; - tags: any; - see: any[]; - features: IFeature[]; - generator: string; -} +import { IGetSpec, ISpec } from 'spock-react/hooks-types'; const getSpec = async (file: string): Promise => { const data = await axios.get(`${config.specUrl}/${file}.json`); @@ -48,10 +11,6 @@ const getSpec = async (file: string): Promise => { return data.data as ISpec; }; -interface IGetSpec { - fileName: string; -} - export const useGetSpec = (props: IGetSpec): UseQueryResult => { const { fileName } = props; diff --git a/src/Hooks/useGetSummary.ts b/src/Hooks/useGetSummary.ts index 12f41c5..006617b 100644 --- a/src/Hooks/useGetSummary.ts +++ b/src/Hooks/useGetSummary.ts @@ -3,6 +3,7 @@ import axios from 'axios'; import { useQuery, UseQueryResult } from '@tanstack/react-query'; import config from '../../environment.json'; +import { ISummary } from 'spock-react-types'; const getSummary = async (): Promise => { const data = await axios.get(config.summaryUrl); @@ -10,41 +11,6 @@ const getSummary = async (): Promise => { return data.data as ISummary; }; -export interface IExecutedFeatures { - id: string; - extraInfo: any[]; -} - -export interface ISpecification { - className: string; - title: string; - narrative: string; - featureCount: string; - failures: string; - errors: string; - skipped: string; - successRate: string; - duration: string; - executedFeatures: IExecutedFeatures[]; - ignoredFeatures: any[]; -} - -export interface ISummary { - generator: string; - project: string; - version: string; - created: string; - statistics: { - runs: string; - passed: string; - failed: string; - featureFailures: string; - successRate: string; - duration: string; - }; - specifications: ISpecification[]; -} - export const useGetSummary = (): UseQueryResult => { return useQuery({ queryKey: ['summary'], diff --git a/src/Hooks/useMarkdown.ts b/src/Hooks/useMarkdown.ts index a8592a5..62ed3c2 100644 --- a/src/Hooks/useMarkdown.ts +++ b/src/Hooks/useMarkdown.ts @@ -1,14 +1,11 @@ import { useQuery } from '@tanstack/react-query'; +import { IMarkdown } from 'spock-react/hooks-types'; const getMarkdown = async (mdFile: string) => { const data = await fetch(mdFile); return await data.text(); }; -interface IMarkdown { - filePath: string; -} - export const useMarkdown = (props: IMarkdown) => { const { filePath } = props; diff --git a/src/components/Feature/Feature.tsx b/src/components/Feature/Feature.tsx index 8cb0164..a286505 100644 --- a/src/components/Feature/Feature.tsx +++ b/src/components/Feature/Feature.tsx @@ -5,7 +5,10 @@ import { Fragment } from 'react'; import { faHashtag } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { IRow, ResponsiveTable, SyntaxHighlighter } from '../shared'; +import { ResponsiveTable, SyntaxHighlighter } from '../shared'; +import { IMinimalFeature } from 'spock-react-types'; +import { IWhereTable } from 'spock-react/components/feature-types'; +import { IRow } from 'spock-react/shared/responsive-table-types'; /* className === unique key for spec @@ -14,23 +17,6 @@ feature.id === unique key for test kind: GIVEN | WHEN | THEN | AND | CLEANUP | WHERE | EXPECT */ -export interface IBlock { - kind: string; - text: string; - /* eslint-disable @typescript-eslint/consistent-indexed-object-style */ - code: string[] | { [key: string]: string[] }; -} - -export interface IFeature { - id: string; - blocks: IBlock[]; -} - -interface IWhereTable { - /* eslint-disable @typescript-eslint/consistent-indexed-object-style */ - data: { [key: string]: string[] }; -} - // It gives you a responsive table with the where-table from the specs const WhereTable = (props: IWhereTable): JSX.Element => { const { data } = props; @@ -56,7 +42,7 @@ const WhereTable = (props: IWhereTable): JSX.Element => { return ; }; -export const Feature = (props: IFeature): JSX.Element => { +export const Feature = (props: IMinimalFeature): JSX.Element => { const { id, blocks } = props; return ( @@ -96,6 +82,7 @@ export const Feature = (props: IFeature): JSX.Element => { Object.keys(block.code).length !== 0 && ( { const { summary } = props; diff --git a/src/components/MainNav/types.d.ts b/src/components/MainNav/types.d.ts new file mode 100644 index 0000000..b2a5706 --- /dev/null +++ b/src/components/MainNav/types.d.ts @@ -0,0 +1,7 @@ +declare module 'spock-react/components/main-nav-types' { + import { ISummary } from 'spock-react-types'; + + export interface IMainNav { + summary: ISummary; + } +} diff --git a/src/components/Search/Search.tsx b/src/components/Search/Search.tsx index 672ea12..7d96eea 100644 --- a/src/components/Search/Search.tsx +++ b/src/components/Search/Search.tsx @@ -3,22 +3,13 @@ import './styles.css'; import { useState } from 'react'; import { Dialog, DialogBackdrop, Separator, useDialogState } from 'reakit'; -import { ISummary } from '../../Hooks'; import { SearchButton } from './SearchButton'; import { SearchFooter } from './SearchFooter'; import { SearchHits } from './SearchHits'; import { SearchInput } from './SearchInput'; +import { ISearch, ISearchHit } from 'spock-react/components/search-types'; -export interface ISearchHit { - score: number; - key: string; -} - -interface ISearchInput { - summary: ISummary; -} - -export const Search = (props: ISearchInput): JSX.Element => { +export const Search = (props: ISearch): JSX.Element => { const { summary } = props; const dialog = useDialogState(); diff --git a/src/components/Search/SearchButton/SearchButton.tsx b/src/components/Search/SearchButton/SearchButton.tsx index 29f280f..83374f0 100644 --- a/src/components/Search/SearchButton/SearchButton.tsx +++ b/src/components/Search/SearchButton/SearchButton.tsx @@ -1,14 +1,10 @@ import './styles.css'; import { DialogDisclosure } from 'reakit'; -import { DialogStateReturn } from 'reakit/ts/Dialog/DialogState'; import { faMagnifyingGlass } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; - -interface ISearchButton { - dialog: DialogStateReturn; -} +import { ISearchButton } from 'spock-react/components/search-button-types'; export const SearchButton = (props: ISearchButton): JSX.Element => { const { dialog } = props; diff --git a/src/components/Search/SearchButton/types.d.ts b/src/components/Search/SearchButton/types.d.ts new file mode 100644 index 0000000..7b4e7ae --- /dev/null +++ b/src/components/Search/SearchButton/types.d.ts @@ -0,0 +1,7 @@ +declare module 'spock-react/components/search-button-types' { + import { DialogStateReturn } from 'reakit/ts/Dialog/DialogState'; + + interface ISearchButton { + dialog: DialogStateReturn; + } +} diff --git a/src/components/Search/SearchHits/SearchCard/SearchCard.tsx b/src/components/Search/SearchHits/SearchCard/SearchCard.tsx index 994d4d5..0190841 100644 --- a/src/components/Search/SearchHits/SearchCard/SearchCard.tsx +++ b/src/components/Search/SearchHits/SearchCard/SearchCard.tsx @@ -5,19 +5,7 @@ import { Link } from 'react-router-dom'; import { faAngleRight } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; - -import { - IExecutedFeatures, - ISpecification, -} from '../../../../Hooks/useGetSummary'; -import { ISearchHit } from '../../Search'; - -interface ISearchCard { - onClick: (e?: any) => void; - hit: ISearchHit; - spec?: ISpecification; - feature?: IExecutedFeatures; -} +import { ISearchCard } from 'spock-react/components/search-card-types'; export const SearchCard = (props: ISearchCard): JSX.Element => { const { onClick, hit, spec, feature } = props; diff --git a/src/components/Search/SearchHits/SearchCard/types.d.ts b/src/components/Search/SearchHits/SearchCard/types.d.ts new file mode 100644 index 0000000..6c2d59c --- /dev/null +++ b/src/components/Search/SearchHits/SearchCard/types.d.ts @@ -0,0 +1,11 @@ +declare module 'spock-react/components/search-card-types' { + import { IExecutedFeatures, ISpecification } from 'spock-react-types'; + import { ISearchHit } from 'spock-react/components/search-types'; + + interface ISearchCard { + onClick: (e?: any) => void; + hit: ISearchHit; + spec?: ISpecification; + feature?: IExecutedFeatures; + } +} diff --git a/src/components/Search/SearchHits/SearchHits.tsx b/src/components/Search/SearchHits/SearchHits.tsx index 6d86341..e0a88db 100644 --- a/src/components/Search/SearchHits/SearchHits.tsx +++ b/src/components/Search/SearchHits/SearchHits.tsx @@ -1,19 +1,9 @@ import './styles.css'; import { nanoid } from 'nanoid'; -import { DialogStateReturn } from 'reakit/ts'; -import { ISummary } from '../../../Hooks/useGetSummary'; -import { ISearchHit } from '../Search'; import { SearchCard } from './SearchCard'; - -interface ISearchHits { - searchHits: ISearchHit[] | null; - setSearchHits: (searchHits: ISearchHit[] | null) => void; - summary: ISummary; - setSearchInput: (input: string) => void; - dialog: DialogStateReturn; -} +import { ISearchHits } from 'spock-react/components/search-hits-types'; export const SearchHits = (props: ISearchHits): JSX.Element => { const { searchHits, summary, setSearchHits, setSearchInput, dialog } = diff --git a/src/components/Search/SearchHits/types.d.ts b/src/components/Search/SearchHits/types.d.ts new file mode 100644 index 0000000..af07ad8 --- /dev/null +++ b/src/components/Search/SearchHits/types.d.ts @@ -0,0 +1,13 @@ +declare module 'spock-react/components/search-hits-types' { + import { ISummary } from 'spock-react-types'; + import { ISearchHit } from 'spock-react/components/search-types'; + import { DialogStateReturn } from 'reakit/ts'; + + interface ISearchHits { + searchHits: ISearchHit[] | null; + setSearchHits: (searchHits: ISearchHit[] | null) => void; + summary: ISummary; + setSearchInput: (input: string) => void; + dialog: DialogStateReturn; + } +} diff --git a/src/components/Search/SearchInput/SearchInput.tsx b/src/components/Search/SearchInput/SearchInput.tsx index 68a18bd..9406568 100644 --- a/src/components/Search/SearchInput/SearchInput.tsx +++ b/src/components/Search/SearchInput/SearchInput.tsx @@ -5,17 +5,10 @@ import { Input } from 'reakit'; import { faMagnifyingGlass } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { ISearchInput } from 'spock-react/components/search-input-types'; +import { ISearchHit } from 'spock-react/components/search-types'; import { useGenerateSearchEntries } from '../../../Hooks/useGenerateSearchEntries'; -import { ISummary } from '../../../Hooks/useGetSummary'; import { getSearchScore } from '../getSearchScore'; -import { ISearchHit } from '../Search'; - -interface ISearchInput { - summary: ISummary; - setSearchHits: (searchHits: ISearchHit[] | null) => void; - setSearchInput: (input: string) => void; - searchInput: string; -} export const SearchInput = (props: ISearchInput): JSX.Element => { const { summary, setSearchHits, setSearchInput, searchInput } = props; diff --git a/src/components/Search/SearchInput/types.d.ts b/src/components/Search/SearchInput/types.d.ts new file mode 100644 index 0000000..b0598c3 --- /dev/null +++ b/src/components/Search/SearchInput/types.d.ts @@ -0,0 +1,11 @@ +declare module 'spock-react/components/search-input-types' { + import { ISummary } from 'spock-react-types'; + import { ISearchHit } from 'spock-react/components/search-types'; + + interface ISearchInput { + summary: ISummary; + setSearchHits: (searchHits: ISearchHit[] | null) => void; + setSearchInput: (input: string) => void; + searchInput: string; + } +} diff --git a/src/components/Search/generateSearchEntries.ts b/src/components/Search/generateSearchEntries.ts index a88f660..7fef9a2 100644 --- a/src/components/Search/generateSearchEntries.ts +++ b/src/components/Search/generateSearchEntries.ts @@ -1,15 +1,7 @@ -export interface IMinimizedSummaryEntry { - className: string; - title: string; - narrative: string; - features: Array<{ id: string }>; -} - -export interface ISearchEntry { - key: string; - href?: string; - keywords: string[]; -} +import { + IMinimizedSummaryEntry, + ISearchEntry, +} from 'spock-react/components/search-types'; const fillWords = [ 'the', diff --git a/src/components/Search/types.d.ts b/src/components/Search/types.d.ts new file mode 100644 index 0000000..9e372f5 --- /dev/null +++ b/src/components/Search/types.d.ts @@ -0,0 +1,25 @@ +declare module 'spock-react/components/search-types' { + import { ISummary } from 'spock-react-types'; + + export interface ISearchHit { + score: number; + key: string; + } + + interface ISearch { + summary: ISummary; + } + + export interface IMinimizedSummaryEntry { + className: string; + title: string; + narrative: string; + features: Array<{ id: string }>; + } + + export interface ISearchEntry { + key: string; + href?: string; + keywords: string[]; + } +} diff --git a/src/components/shared/Layout/Layout.tsx b/src/components/shared/Layout/Layout.tsx index 62e81c8..8dfa412 100644 --- a/src/components/shared/Layout/Layout.tsx +++ b/src/components/shared/Layout/Layout.tsx @@ -2,13 +2,8 @@ import './styles.css'; import { PropsWithChildren } from 'react'; -import { IFeature } from '../../../Hooks'; import { OnPageNav } from './OnPageNav'; - -interface ILayout { - hasOnPageNav?: boolean; - features?: IFeature[]; -} +import { ILayout } from 'spock-react/shared/layout-types'; export const Layout = (props: PropsWithChildren): JSX.Element => { const { hasOnPageNav, children, features } = props; diff --git a/src/components/shared/Layout/OnPageNav.tsx b/src/components/shared/Layout/OnPageNav.tsx index 0b5fa38..de6950c 100644 --- a/src/components/shared/Layout/OnPageNav.tsx +++ b/src/components/shared/Layout/OnPageNav.tsx @@ -1,11 +1,8 @@ import { nanoid } from 'nanoid'; -import { IFeature } from '../../../Hooks'; import { NavAnchor } from '..'; - -interface IOnPageNave { - features: IFeature[]; -} +import { IOnPageNave } from 'spock-react/shared/layout-types'; +import { IMinimalFeature } from 'spock-react-types'; export const OnPageNav = (props: IOnPageNave): JSX.Element => { const { features } = props; @@ -15,7 +12,7 @@ export const OnPageNav = (props: IOnPageNave): JSX.Element => {

On the Page