make orderBy direction optional
Signed-off-by: Paul Cowan <paul.cowan@cutting.scot>
This commit is contained in:
@@ -110,7 +110,7 @@ export const gitHubIssuesApi = (
|
||||
field: 'UPDATED_AT',
|
||||
direction: 'DESC',
|
||||
},
|
||||
}: IssuesByRepoOptions = {},
|
||||
}: IssuesByRepoOptions,
|
||||
): Promise<IssuesByRepo> => {
|
||||
const graphql = await getOctokit();
|
||||
const safeNames: Array<string> = [];
|
||||
@@ -137,14 +137,17 @@ export const gitHubIssuesApi = (
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`
|
||||
---------------------------------------------------
|
||||
${createIssueByRepoQuery(repositories, itemsPerRepo, { filterBy })}
|
||||
${createIssueByRepoQuery(repositories, itemsPerRepo, { filterBy, orderBy })}
|
||||
---------------------------------------------------
|
||||
`);
|
||||
|
||||
let issuesByRepo: IssuesByRepo = {};
|
||||
try {
|
||||
issuesByRepo = await graphql(
|
||||
createIssueByRepoQuery(repositories, itemsPerRepo, { filterBy }),
|
||||
createIssueByRepoQuery(repositories, itemsPerRepo, {
|
||||
filterBy,
|
||||
orderBy,
|
||||
}),
|
||||
);
|
||||
} catch (e) {
|
||||
if (e.data) {
|
||||
@@ -168,7 +171,7 @@ export const gitHubIssuesApi = (
|
||||
|
||||
function formatFilterValue(value: IssuesFilters[keyof IssuesFilters]): string {
|
||||
if (Array.isArray(value)) {
|
||||
return `[ ${value.map(formatFilterValue).join(', ')}`;
|
||||
return `[ ${value.map(formatFilterValue).join(', ')}]`;
|
||||
}
|
||||
|
||||
return typeof value === 'string' ? `\"${value}\"` : `${value}`;
|
||||
@@ -189,9 +192,9 @@ function createFilterByClause(filterBy?: IssuesFilters): string {
|
||||
return [`${field}: ${value.join(', ')}`];
|
||||
}
|
||||
|
||||
return [`${field}: ${formatFilterValue}`];
|
||||
return [`${field}: ${formatFilterValue(value)}`];
|
||||
})
|
||||
.join(', ');
|
||||
.join(', ');
|
||||
}
|
||||
|
||||
function createIssueByRepoQuery(
|
||||
|
||||
@@ -32,18 +32,22 @@ import { IssuesByRepoOptions } from '../../types';
|
||||
export type GitHubIssuesProps = {
|
||||
itemsPerPage?: number;
|
||||
itemsPerRepo?: number;
|
||||
queryOptions?: IssuesByRepoOptions;
|
||||
filterBy?: IssuesByRepoOptions['filterBy'];
|
||||
orderBy?: IssuesByRepoOptions['orderBy'];
|
||||
};
|
||||
|
||||
export const GitHubIssues = (props: GitHubIssuesProps) => {
|
||||
const { itemsPerPage = 10, itemsPerRepo = 40, queryOptions } = props;
|
||||
const { itemsPerPage = 10, itemsPerRepo = 40, filterBy, orderBy } = props;
|
||||
|
||||
const { repositories } = useEntityGitHubRepositories();
|
||||
const {
|
||||
isLoading,
|
||||
gitHubIssuesByRepo: issuesByRepository,
|
||||
retry,
|
||||
} = useGetIssuesByRepoFromGitHub(repositories, itemsPerRepo, queryOptions);
|
||||
} = useGetIssuesByRepoFromGitHub(repositories, itemsPerRepo, {
|
||||
filterBy,
|
||||
orderBy,
|
||||
});
|
||||
|
||||
if (!repositories.length) {
|
||||
return <NoRepositoriesInfo />;
|
||||
|
||||
@@ -29,6 +29,6 @@ export interface IssuesByRepoOptions {
|
||||
filterBy?: IssuesFilters;
|
||||
orderBy?: {
|
||||
field: 'CREATED_AT' | 'UPDATED_AT' | 'COMMENTS';
|
||||
direction: 'ASC' | 'DESC';
|
||||
direction?: 'ASC' | 'DESC';
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user