diff --git a/frontend/common/useInfiniteScroll.ts b/frontend/common/useInfiniteScroll.ts index a10967cf4395..c3cd56b40338 100644 --- a/frontend/common/useInfiniteScroll.ts +++ b/frontend/common/useInfiniteScroll.ts @@ -4,6 +4,7 @@ import { PagedRequest } from './types/requests' import { PagedResponse } from './types/responses' import { QueryDefinition } from '@reduxjs/toolkit/query' import useThrottle from './useThrottle' +import { SubscriptionOptions } from '@reduxjs/toolkit/src/query/core/apiState' const useInfiniteScroll = < REQ extends PagedRequest<{}>, @@ -12,17 +13,24 @@ const useInfiniteScroll = < useGetDataListQuery: UseQuery>, queryParameters: REQ, throttle = 100, + queryOptions?: SubscriptionOptions & { + skip?: boolean + refetchOnMountOrArgChange?: boolean | number + }, ) => { const [localPage, setLocalPage] = useState(1) const [combinedData, setCombinedData] = useState(null) const [loadingCombinedData, setLoadingCombinedData] = useState(false) const [q, setQ] = useState('') - const queryResponse = useGetDataListQuery({ - ...queryParameters, - page: localPage, - q, - }) + const queryResponse = useGetDataListQuery( + { + ...queryParameters, + page: localPage, + q, + }, + queryOptions, + ) useEffect( () => { diff --git a/frontend/web/components/ExternalResourcesLinkTab.tsx b/frontend/web/components/ExternalResourcesLinkTab.tsx index f3deb304f4f1..fffd7d99fa83 100644 --- a/frontend/web/components/ExternalResourcesLinkTab.tsx +++ b/frontend/web/components/ExternalResourcesLinkTab.tsx @@ -1,15 +1,11 @@ import React, { FC, useState } from 'react' -import MyRepositoriesSelect from './MyRepositoriesSelect' import ExternalResourcesTable, { ExternalResourcesTableBase, } from './ExternalResourcesTable' import { ExternalResource, GithubResource } from 'common/types/responses' -import { GitHubResourceSelectProvider } from './GitHubResourceSelectProvider' import { useCreateExternalResourceMutation } from 'common/services/useExternalResource' import Constants from 'common/constants' -import Button from './base/forms/Button' import GitHubResourcesSelect from './GitHubResourcesSelect' -import _ from 'lodash' import AppActions from 'common/dispatcher/app-actions' type ExternalResourcesLinkTabType = { @@ -21,170 +17,69 @@ type ExternalResourcesLinkTabType = { } type AddExternalResourceRowType = ExternalResourcesTableBase & { - linkedExternalResources?: ExternalResource[] + selectedResources?: ExternalResource[] environmentId: string + githubId: string } -type GitHubStatusType = { - value: number - label: string -} - -const AddExternalResourceRow: FC = ({ +const ExternalResourcesLinkTab: FC = ({ environmentId, featureId, - linkedExternalResources, + githubId, organisationId, projectId, - repoName, - repoOwner, }) => { - const [externalResourceType, setExternalResourceType] = useState('') - const [featureExternalResource, setFeatureExternalResource] = useState< - GithubResource | undefined - >(undefined) - const [lastSavedResource, setLastSavedResource] = useState< - string | undefined - >(undefined) - const [createExternalResource] = useCreateExternalResourceMutation() const githubTypes = Object.values(Constants.resourceTypes).filter( (v) => v.type === 'GITHUB', ) - return ( -
- - { - return options - }} - value={selectedOption} - size='select-md' - placeholder={'Select Your Resource'} - onChange={(v: GitHubResourcesValueType) => { - setSelectedOption(v) - onChange(v?.value) - }} - isClearable={true} - options={githubResources?.map((i: GithubResource) => { - return { - label: `${i.title} #${i.number}`, - value: i, - } - })} - noOptionsMessage={() => - isLoading - ? 'Loading...' - : isFetching - ? 'Refreshing data ...' - : 'No Results found' - } - onInputChange={(e: any) => { - setSearchText(e) - searchItems(Utils.safeParseEventValue(e)) - }} - components={{ - Control: CustomControl, - MenuList, - }} - data={{ searchText }} - /> -
+ <> + +
+ +
+ { + return options + }} + value={null} + size='select-md' + placeholder={'Select Your Resource'} + onChange={(v: GitHubResourcesValueType) => { + setSelectedOption(null) + onChange(v?.value) + }} + options={data?.results + .filter((v) => !value?.includes(v.html_url)) + .map((i: GithubResource) => { + return { + label: `${i.title} #${i.number}`, + value: i, + } + })} + noOptionsMessage={() => + isLoading || isFetching ? ( +
+ +
+ ) : ( + 'No Results found' + ) + } + onInputChange={(e: any) => { + setSearchText(e) + searchItems(Utils.safeParseEventValue(e)) + }} + data={{ searchText }} + /> +
+ )} + ) } diff --git a/frontend/web/components/MyRepositoriesSelect.tsx b/frontend/web/components/MyRepositoriesSelect.tsx index 36457bfb8129..8e6cbbde559c 100644 --- a/frontend/web/components/MyRepositoriesSelect.tsx +++ b/frontend/web/components/MyRepositoriesSelect.tsx @@ -5,6 +5,7 @@ import RepositoriesSelect from './RepositoriesSelect' type MyRepositoriesSelectType = { githubId: string orgId: string + value?: string onChange: (value: string) => void } @@ -12,6 +13,7 @@ const MyRepositoriesSelect: FC = ({ githubId, onChange, orgId, + value, }) => { const { data } = useGetGithubRepositoriesQuery({ github_id: githubId, @@ -27,16 +29,11 @@ const MyRepositoriesSelect: FC = ({ }, [data]) return ( -
- {!!data?.results.length && data?.results.length !== 1 && ( - <> - - - )} -
+ ) } diff --git a/frontend/web/components/RepositoriesSelect.tsx b/frontend/web/components/RepositoriesSelect.tsx index 02074c28ffd7..4faa6708a590 100644 --- a/frontend/web/components/RepositoriesSelect.tsx +++ b/frontend/web/components/RepositoriesSelect.tsx @@ -3,6 +3,7 @@ import { GithubRepository } from 'common/types/responses' export type RepositoriesSelectType = { disabled?: boolean + value?: string repositories: GithubRepository[] | undefined onChange: (value: string) => void } @@ -11,22 +12,25 @@ const RepositoriesSelect: FC = ({ disabled, onChange, repositories, + value, }) => { + const options = repositories?.map((i: GithubRepository) => { + return { + label: `${i.repository_name} - ${i.repository_owner}`, + value: `${i.repository_name}/${i.repository_owner}`, + } + }) return ( -
- onChange(v?.value)} + options={options} + value={options?.find((v) => v.value === value)} + /> ) } diff --git a/frontend/web/project/project-components.js b/frontend/web/project/project-components.js index 4b25d4c2548a..651d539e0c74 100644 --- a/frontend/web/project/project-components.js +++ b/frontend/web/project/project-components.js @@ -100,6 +100,16 @@ const Option = (props) => { global.Select = class extends PureComponent { static displayName = 'Select' + componentDidUpdate() { + if ( + this.props.autoSelect && + this.props.options?.length && + !this.props.value + ) { + this.props.onChange(this.props.options[0]) + } + } + render() { const props = this.props return E2E ? ( @@ -131,6 +141,7 @@ global.Select = class extends PureComponent {
) : (
{ e.stopPropagation() }}