Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding posts count to dashboard #2476

Merged
merged 7 commits into from
Nov 21, 2021
Merged

Adding posts count to dashboard #2476

merged 7 commits into from
Nov 21, 2021

Conversation

nguyenhung15913
Copy link
Contributor

@nguyenhung15913 nguyenhung15913 commented Nov 16, 2021

Issue This PR Addresses

Fixes #2419

Type of Change

  • Bugfix: Change which fixes an issue
  • New Feature: Change which adds functionality
  • Documentation Update: Change which improves documentation
  • UI: Change which improves UI

Description

  • Added cors to Satellite options at src/api/posts/src/index.js to expose x-total-count header.
  • Added a component to show posts count at src/api/status/public/index.html
  • Added postCounts.js at src/api/status/public to fetch and get the total of posts
  • Added host API to connectSrc of Satellite options, and cors at src/api/status/src/server.js

Note: I worked with postsCount.js locally using fetch to get the x-total-count header from https://localhost/v1/posts and it worked. However, with https://dev.api.telescope.cdot.systems/v1/posts, response.headers.get(x-total-count) will return null.

To test locally:

  • In src/api/status/env.local, include API_HOST=http://localhost/v1/posts
  • Comment on <base href="/v1/status/" /> in src/api/status/public/index.html (This line however is required in production)
  • add process.env.API_HOST to connectSrc in src/api/status/src/server.js
  • Change fetch url to 'http://localhost/v1/posts' instead in src/api/status/public/js/post/index.js
  • Run posts service in the root directory npm run services:start posts
  • Run npm run dev in src/api/status
    Here is the screenshot of working posts count:
    image

Checklist

  • Quality: This PR builds and passes our npm test and works locally
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not (if applicable)
  • Documentation: This PR includes updated/added documentation to user exposed functionality or configuration variables are added/changed or an explanation of why it does not(if applicable)

@gitpod-io
Copy link

gitpod-io bot commented Nov 16, 2021

Copy link
Contributor

@menghif menghif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting Total Posts: N/A when running this. Is there something I need to change before running it?

src/api/status/src/server.js Outdated Show resolved Hide resolved
src/api/status/public/index.html Outdated Show resolved Hide resolved
src/api/status/public/index.html Outdated Show resolved Hide resolved
src/api/status/public/index.html Show resolved Hide resolved
src/api/status/public/postsCount.js Outdated Show resolved Hide resolved
src/api/status/public/postsCount.js Outdated Show resolved Hide resolved
src/api/status/src/server.js Outdated Show resolved Hide resolved
src/api/status/env.local Outdated Show resolved Hide resolved
@nguyenhung15913
Copy link
Contributor Author

I'm getting Total Posts: N/A when running this. Is there something I need to change before running it?

Hi Mengi, you should change the URL in the fetch in postsCount.js to https://localhost/v1/posts. run npm run services:start posts in the root folder. This will resolve the issue. This is because as I mentioned, It only worked when you work locally.

Copy link
Contributor

@menghif menghif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File name should be changed to: posts-count.js

src/api/status/public/index.html Outdated Show resolved Hide resolved
@humphd
Copy link
Contributor

humphd commented Nov 18, 2021

This needs a rebase

Copy link
Contributor

@Andrewnt219 Andrewnt219 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include a screenshot of your work in the PR?

src/api/status/public/index.html Show resolved Hide resolved
src/api/status/public/js/posts-count.js Outdated Show resolved Hide resolved
src/api/status/public/js/posts-count.js Outdated Show resolved Hide resolved
src/api/posts/package.json Outdated Show resolved Hide resolved
src/api/status/env.local Outdated Show resolved Hide resolved
src/api/status/public/index.html Show resolved Hide resolved
src/api/status/public/js/post/index.js Outdated Show resolved Hide resolved
src/api/status/public/script.js Outdated Show resolved Hide resolved
src/api/status/public/js/post/index.js Outdated Show resolved Hide resolved
src/api/status/public/js/post/index.js Outdated Show resolved Hide resolved
src/api/status/public/js/post/index.js Outdated Show resolved Hide resolved
@humphd
Copy link
Contributor

humphd commented Nov 20, 2021

You need to revert the changes I mentioned, so that it can pull in the proper ones when you rebase onto master.

Copy link
Contributor

@Andrewnt219 Andrewnt219 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rebase is correct now, I tested on local but the "http://localhost/v1/posts" return an empty array (probably not your fault). Other than that, everything is great.

@@ -1307,5 +1328,6 @@ <h6 class="mt-3">Thank you for sharing!</h6>
<!-- Telescope JS Files -->
<script src="js/github-stats.js"></script>
<script src="js/feed/index.js"></script>
<script type="module" src="js/index.js"></script>
Copy link
Contributor

@Andrewnt219 Andrewnt219 Nov 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nguyenhung15913 this should be changed to js/pages/dashboard.js.

EDIT: can you also export the functions in github-stats.js and feed/index.js, add them to the load even of js/pages/dashboard.js just like your function?

Copy link
Contributor

@Andrewnt219 Andrewnt219 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go, just revert the unnecessary change and squash all the commits.

tatus Outdated Show resolved Hide resolved
Copy link
Contributor

@Andrewnt219 Andrewnt219 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rebase went wrong again...

@@ -18,7 +18,7 @@ TELESCOPE_HOST=http://localhost:3000

# The host where all the microservices run (e.g., http://localhost)
# NOTE: if you change this, change all other occurrences below too.
API_HOST=localhost
API_HOST=http://localhost
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert.

docker/docker-compose.yml Outdated Show resolved Hide resolved
package.json Outdated
@@ -82,8 +82,8 @@
"opml-generator": "1.1.1",
"passport": "0.4.1",
"passport-saml": "3.1.2",
"pino": "7.3.0",
"pino-elasticsearch": "6.2.0",
"pino": "6.11.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert.

src/api/status/env.local Outdated Show resolved Hide resolved
  rebased
  Make functions more precise
  Fixed PR
  commit before rebasing
  added files back after aborting rebase
  commit after rebase
  final fix
  update package.json of posts
  commit b4 rebase
  commit 2
  fixed before rebase
src/api/status/public/js/pages/dashboard.js Outdated Show resolved Hide resolved
src/api/status/src/server.js Outdated Show resolved Hide resolved
Copy link
Contributor

@Andrewnt219 Andrewnt219 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

I tested locally and this should be ready to merge @humphd.

import { getFeedCount } from '../feed/index.js';
import { getGitHubData } from '../github-stats.js';

window.addEventListener('load', (event) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: event isn't used, you should remove it.

@humphd humphd merged commit d7241b0 into Seneca-CDOT:master Nov 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show Posts count on status dashboard
6 participants