Merge pull request #99 from anuraghazra/feat/archive-badge
feat: show archive badge if repo is archived
This commit is contained in:
		
						commit
						f27daeb931
					
				
					 3 changed files with 28 additions and 1 deletions
				
			
		| 
						 | 
					@ -9,6 +9,7 @@ const fetcher = (variables, token) => {
 | 
				
			||||||
        name
 | 
					        name
 | 
				
			||||||
        nameWithOwner
 | 
					        nameWithOwner
 | 
				
			||||||
        isPrivate
 | 
					        isPrivate
 | 
				
			||||||
 | 
					        isArchived
 | 
				
			||||||
        stargazers {
 | 
					        stargazers {
 | 
				
			||||||
          totalCount
 | 
					          totalCount
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@ const renderRepoCard = (repo, options = {}) => {
 | 
				
			||||||
    description,
 | 
					    description,
 | 
				
			||||||
    primaryLanguage,
 | 
					    primaryLanguage,
 | 
				
			||||||
    stargazers,
 | 
					    stargazers,
 | 
				
			||||||
 | 
					    isArchived,
 | 
				
			||||||
    forkCount,
 | 
					    forkCount,
 | 
				
			||||||
  } = repo;
 | 
					  } = repo;
 | 
				
			||||||
  const { title_color, icon_color, text_color, bg_color, show_owner } = options;
 | 
					  const { title_color, icon_color, text_color, bg_color, show_owner } = options;
 | 
				
			||||||
| 
						 | 
					@ -31,19 +32,33 @@ const renderRepoCard = (repo, options = {}) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const totalStars = kFormatter(stargazers.totalCount);
 | 
					  const totalStars = kFormatter(stargazers.totalCount);
 | 
				
			||||||
  const totalForks = kFormatter(forkCount);
 | 
					  const totalForks = kFormatter(forkCount);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const archiveBadge = isArchived
 | 
				
			||||||
 | 
					    ? `
 | 
				
			||||||
 | 
					    <g data-testid="archive-badge" class="archive-badge" transform="translate(320, 38)">
 | 
				
			||||||
 | 
					      <rect stroke="${textColor}" stroke-width="1" width="70" height="20" x="-12" y="-14" ry="10" rx="10"></rect>
 | 
				
			||||||
 | 
					      <text fill="${textColor}">Archived</text>
 | 
				
			||||||
 | 
					    </g>
 | 
				
			||||||
 | 
					    `
 | 
				
			||||||
 | 
					    : "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return `
 | 
					  return `
 | 
				
			||||||
    <svg width="400" height="${height}" viewBox="0 0 400 ${height}" fill="none" xmlns="http://www.w3.org/2000/svg">
 | 
					    <svg version="1.1" width="400" height="${height}" viewBox="0 0 400 ${height}" fill="none" xmlns="http://www.w3.org/2000/svg">
 | 
				
			||||||
      <style>
 | 
					      <style>
 | 
				
			||||||
      .header { font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${titleColor} }
 | 
					      .header { font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${titleColor} }
 | 
				
			||||||
      .description { font: 400 13px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
 | 
					      .description { font: 400 13px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
 | 
				
			||||||
      .gray { font: 400 12px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
 | 
					      .gray { font: 400 12px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
 | 
				
			||||||
      .icon { fill: ${iconColor} }
 | 
					      .icon { fill: ${iconColor} }
 | 
				
			||||||
 | 
					      .archive-badge { font: 600 12px 'Segoe UI', Ubuntu, Sans-Serif; }
 | 
				
			||||||
 | 
					      .archive-badge rect { opacity: 0.2 }
 | 
				
			||||||
      </style>
 | 
					      </style>
 | 
				
			||||||
      <rect data-testid="card-border" x="0.5" y="0.5" width="399" height="99%" rx="4.5" fill="${bgColor}" stroke="#E4E2E2"/>
 | 
					      <rect data-testid="card-border" x="0.5" y="0.5" width="399" height="99%" rx="4.5" fill="${bgColor}" stroke="#E4E2E2"/>
 | 
				
			||||||
      <svg class="icon" x="25" y="25" viewBox="0 0 16 16" version="1.1" width="16" height="16">
 | 
					      <svg class="icon" x="25" y="25" viewBox="0 0 16 16" version="1.1" width="16" height="16">
 | 
				
			||||||
        ${icons.contribs}
 | 
					        ${icons.contribs}
 | 
				
			||||||
      </svg>
 | 
					      </svg>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      ${archiveBadge}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      <text x="50" y="38" class="header">${header}</text>
 | 
					      <text x="50" y="38" class="header">${header}</text>
 | 
				
			||||||
      <text class="description" x="25" y="70">${encodeHTML(desc)}</text>
 | 
					      <text class="description" x="25" y="70">${encodeHTML(desc)}</text>
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -147,4 +147,15 @@ describe("Test renderRepoCard", () => {
 | 
				
			||||||
      "#252525"
 | 
					      "#252525"
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  it("should render archive badge if repo is archived", () => {
 | 
				
			||||||
 | 
					    document.body.innerHTML = renderRepoCard({
 | 
				
			||||||
 | 
					      ...data_repo.repository,
 | 
				
			||||||
 | 
					      isArchived: true,
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    expect(queryByTestId(document.body, "archive-badge")).toHaveTextContent(
 | 
				
			||||||
 | 
					      "Archived"
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue