') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); [Angular-Apollo-Tailwind] Add filters milestones on PRs by iansamz · Pull Request #653 · thisdot/starter.dev-github-showcases · GitHub
Skip to content
Open
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
9 changes: 8 additions & 1 deletion angular-apollo-tailwind/src/app/gql/models/repo-pulls.ts
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { Label, PageInfo } from '../github.schema';
import { Label, Milestone, PageInfo } from '../github.schema';

export interface RepoPullRequests {
pageInfo: PageInfo;
Expand All@@ -21,6 +21,13 @@ export interface RepoPullRequest {
labelCount: number;
}

export interface RepoPullRequestDetails {
openPullRequests: RepoPullRequests;
closedPullRequests: RepoPullRequests;
milestones: Milestone[];
labels: Label[];
}

export enum PULL_REQUESTS_TYPE {
ISSUE = 'issue',
PULL_REQUEST = 'pull',
Expand Down
16 changes: 16 additions & 0 deletions angular-apollo-tailwind/src/app/gql/queries/repo-pulls.query.gql
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,22 @@ query RepoPullRequests(
) {
repository(owner: $owner, name: $name) {
id
milestones(first: 100, states: [OPEN]) {
nodes {
id
closed
description
number
title
}
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
totalCount
}
openPullRequests: pullRequests(
first: $first
last: $last
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,14 +38,14 @@
buttonClassName="filterButton"
(setFilter)="handleLabelClick($event)"
></app-filter-dropdown>
<!-- <app-filter-dropdown
<app-filter-dropdown
name="Milestones"
description="Filter by milestone"
[current]="currentMilestone"
[items]="milestoneOptions"
buttonClassName="filterButton"
(setFilter)="handleMilestoneClick($event)"
></app-filter-dropdown> -->
></app-filter-dropdown>
<app-filter-dropdown
name="Sort"
description="Sort by"
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -52,7 +52,7 @@ export class PullRequestFiltersComponent {
@Input() openCount = 0;
@Input() closedCount = 0;
@Input() currentMilestone: string | null = null;
@Input() set milestones(val: Milestone[]) {
@Input() set milestones(val: Milestone[] | null | undefined) {
if (val) {
const a = val as Milestone[];
const b = [{ title: 'PullRequest with no milestone', id: '' }, ...a];
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
import { Label, RepoPullRequest, RepoPullRequestsQuery } from '../gql';
import {
Label,
Milestone,
RepoPullRequest,
RepoPullRequestDetails,
RepoPullRequestsQuery,
} from '../gql';

export const parsePullRequests = (connection: any) => {
if (!connection) {
Expand DownExpand Up@@ -58,11 +64,34 @@ export const parsePullRequests = (connection: any) => {
return { pullRequests, totalCount, pageInfo };
};

export const parsePullRequestsQuery = (data: RepoPullRequestsQuery) => {
const parseMilestones = (milestones: any) => {
const nodes = milestones.nodes;
return nodes.reduce((milestones: Milestone[], milestone: Milestone) => {
if (!milestone) {
return milestones;
}

return [
...milestones,
{
id: milestone.id,
closed: milestone.closed,
title: milestone.title,
number: milestone.number,
description: milestone.description,
},
];
}, []);
};

export const parsePullRequestsQuery = (
data: RepoPullRequestsQuery,
): RepoPullRequestDetails => {
const openPullRequests = parsePullRequests(data.repository?.openPullRequests);
const closedPullRequests = parsePullRequests(
data.repository?.closedPullRequests,
);
const milestones = parseMilestones(data.repository?.milestones);

const labelMap = [
...closedPullRequests.pullRequests,
Expand All@@ -82,6 +111,7 @@ export const parsePullRequestsQuery = (data: RepoPullRequestsQuery) => {
return {
openPullRequests,
closedPullRequests,
milestones,
labels: Object.values(labelMap) as Label[],
};
};
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,7 +25,7 @@
[openCount]="(openPullRequestsCount$ | async)!"
[closedCount]="(closedPullRequestsCount$ | async)!"
[currentMilestone]="milestone$ | async"
[milestones]="(milestones$ | async)!"
[milestones]="milestones$ | async"
[currentLabel]="label$ | async"
[labels]="(labels$ | async)!"
[sort]="sort$ | async"
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,9 @@ export class PullRequestsComponent implements OnInit {
this.pullRequestsStore.openPullRequestsCount$;
readonly closedPullRequestsCount$ =
this.pullRequestsStore.closedPullRequestsCount$;
readonly pageInfo$ = this.pullRequestsStore.pageInfo$;

// Filter store selectors
readonly label$ = this.pullRequestsStore.label$;
readonly labels$ = this.pullRequestsStore.labels$;
readonly milestone$ = this.pullRequestsStore.milestone$;
Expand All@@ -25,7 +28,6 @@ export class PullRequestsComponent implements OnInit {
readonly type$ = this.pullRequestsStore.type$;
readonly sort$ = this.pullRequestsStore.sort$;
readonly hasActiveFilters$ = this.pullRequestsStore.hasActiveFilters$;
readonly pageInfo$ = this.pullRequestsStore.pageInfo$;

constructor(private pullRequestsStore: PullRequestsStore) {}

Expand All@@ -35,6 +37,7 @@ export class PullRequestsComponent implements OnInit {

setMilestone(milestone: string) {
this.pullRequestsStore.setMilestone(milestone);
this.pullRequestsStore.getPullRequests$();
}

setLabel(label: string) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -248,9 +248,14 @@ export class PullRequestsStore extends ComponentStore<FilterState> {
.valueChanges.pipe(
tapResponse(
(res) => {
const { openPullRequests, closedPullRequests, labels } =
parsePullRequestsQuery(res.data);

const {
openPullRequests,
closedPullRequests,
milestones,
labels,
} = parsePullRequestsQuery(res.data);

this.setMilestones(milestones);
this.setLabels(labels);
this.setOpenPullRequests(openPullRequests);
this.setClosedPullRequests(closedPullRequests);
Expand Down
4 changes: 2 additions & 2 deletions angular-apollo-tailwind/src/environments/environment.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,9 +12,9 @@

export const environment = {
production: false,
apiUrl: 'https://api.starter.dev',
apiUrl: '',
graphApiUrl: 'https://api.github.com/graphql',
redirectUrl: 'http://localhost:4200/redirect',
redirectUrl: 'https://localhost:4200/redirect',
};

/*
Expand Down