From 1afb066041f68ef5b730741c432f5c71d4546d0d Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Wed, 16 Oct 2024 21:48:30 -0400 Subject: [PATCH 1/4] Got Visualization stories working in UT-HAI fork. --- .storybook/preview.js | 24 +++++++++++++++++++ .../VisualisationTutorial.stories.js | 7 ++++-- .../Visualization.stories.js | 8 +++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/.storybook/preview.js b/.storybook/preview.js index 8627357..180ba53 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -1,5 +1,29 @@ /** @type { import('@storybook/react').Preview } */ import "./style.css" +import { getMath, getComments } from "./utils"; + +// Needed at the very least for Graph component stories of UT-HAI client-deliberation. +import jquery from 'jquery'; +global.$ = jquery; +global.jQuery = jquery; + +// This is where we mock responses for PolisNet endpoints. +// TODO: Create a storybook plugin to do this dynamically. +function ajax_responses(responses) { + return function (params) { + const mockedPathname = new URL(params.url).pathname + const mockResponse = responses[mockedPathname] + var deferred = global.$.Deferred().resolve(mockResponse) + return deferred + }; +} + +global.$.ajax = ajax_responses({ + '/api/v3/math/pca2': getMath(), + '/api/v3/comments': [getComments()], + '/api/v3/votes': [], + '/api/v3/votes/famous': [], +}) const isGithubBuild = !!process.env["GITHUB_REPOSITORY"] const preview = { diff --git a/stories/UT-HAI/client-deliberation/VisualisationTutorial.stories.js b/stories/UT-HAI/client-deliberation/VisualisationTutorial.stories.js index 7635dd2..c69f0bd 100644 --- a/stories/UT-HAI/client-deliberation/VisualisationTutorial.stories.js +++ b/stories/UT-HAI/client-deliberation/VisualisationTutorial.stories.js @@ -8,7 +8,10 @@ export default { } // TODO: Need to mock PolisNet API calls. -const Template = (args) =>
Not Yet Implemented
+const Template = (args) => export const Default = Template.bind({}) -Default.args = {} +Default.args = { + // In theory, something happens at 15, but doesn't seem to work. + currentIndex: 14, +} diff --git a/stories/UT-HAI/client-deliberation/Visualization.stories.js b/stories/UT-HAI/client-deliberation/Visualization.stories.js index 70bef9c..4e01984 100644 --- a/stories/UT-HAI/client-deliberation/Visualization.stories.js +++ b/stories/UT-HAI/client-deliberation/Visualization.stories.js @@ -2,13 +2,17 @@ import React from 'react' import Visualization from '../../../codebases/UT-HAI/client-deliberation/src/components/Visualization' import { withDelibThemeUi } from '../../../.storybook/decorators' + + export default { component: Visualization, decorators: [withDelibThemeUi], } -// TODO: Need to mock PolisNet API calls. -const Template = (args) =>
Not Yet Implemented
+const Template = (args) => export const Default = Template.bind({}) +// No props on this component. +// We pass in all data by mocking jQuery $.ajax calls made by PolisNet. +// See: .storybook/preview.js Default.args = {} From bd68cd5bd0299dd39b8a7bf13054d752c594e362 Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Mon, 21 Oct 2024 12:06:20 -0400 Subject: [PATCH 2/4] Added a build step to fail PRs when they silently fail. h/t @thomassth --- .github/workflows/deploy-github-pages.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/deploy-github-pages.yml b/.github/workflows/deploy-github-pages.yml index 8b6d447..57bb80d 100644 --- a/.github/workflows/deploy-github-pages.yml +++ b/.github/workflows/deploy-github-pages.yml @@ -37,6 +37,17 @@ jobs: # Done manually so we can checkout submodule checkout: false + - name: Fail if PR portion of build failed + if: ${{ github.event_name == 'pull_request_target' }} + shell: bash + env: + DIRECTORY: dist/storybook-bundle/PR-${{ github.event.number }} + run: | + if [ ! -d "$DIRECTORY" ]; then + echo Pull Request build directory "$DIRECTORY does not exist." + exit 1 + fi + # See: https://github.com/ouzi-dev/commit-status-updater/pull/533 - uses: patcon/commit-status-updater@patch-1 if: ${{ github.event_name == 'pull_request_target' }} From 1797e360528801156c1ce9b5b2f1be79bdf6d696 Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Mon, 21 Oct 2024 12:28:38 -0400 Subject: [PATCH 3/4] Debug to confirm failure. --- .github/workflows/deploy-github-pages.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-github-pages.yml b/.github/workflows/deploy-github-pages.yml index 57bb80d..e7e3b15 100644 --- a/.github/workflows/deploy-github-pages.yml +++ b/.github/workflows/deploy-github-pages.yml @@ -9,7 +9,7 @@ on: # - force changes to our GitHub Pages website, # - force commit status updates, # unless the permissions key below is changed. - pull_request_target: + pull_request: types: [opened, synchronize, reopened] # Be careful about changing these, due to pull_request_target trigger. @@ -38,10 +38,11 @@ jobs: checkout: false - name: Fail if PR portion of build failed - if: ${{ github.event_name == 'pull_request_target' }} + if: ${{ github.event_name == 'pull_request' }} shell: bash env: - DIRECTORY: dist/storybook-bundle/PR-${{ github.event.number }} + #DIRECTORY: dist/storybook-bundle/PR-${{ github.event.number }} + DIRECTORY: dist/storybook-bundle/PR-19 run: | if [ ! -d "$DIRECTORY" ]; then echo Pull Request build directory "$DIRECTORY does not exist." From 150f0ee6b43964a3abe000418a65058ddcc45d41 Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Mon, 21 Oct 2024 15:28:06 -0400 Subject: [PATCH 4/4] Works! Back to non-debug code. --- .github/workflows/deploy-github-pages.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-github-pages.yml b/.github/workflows/deploy-github-pages.yml index e7e3b15..57bb80d 100644 --- a/.github/workflows/deploy-github-pages.yml +++ b/.github/workflows/deploy-github-pages.yml @@ -9,7 +9,7 @@ on: # - force changes to our GitHub Pages website, # - force commit status updates, # unless the permissions key below is changed. - pull_request: + pull_request_target: types: [opened, synchronize, reopened] # Be careful about changing these, due to pull_request_target trigger. @@ -38,11 +38,10 @@ jobs: checkout: false - name: Fail if PR portion of build failed - if: ${{ github.event_name == 'pull_request' }} + if: ${{ github.event_name == 'pull_request_target' }} shell: bash env: - #DIRECTORY: dist/storybook-bundle/PR-${{ github.event.number }} - DIRECTORY: dist/storybook-bundle/PR-19 + DIRECTORY: dist/storybook-bundle/PR-${{ github.event.number }} run: | if [ ! -d "$DIRECTORY" ]; then echo Pull Request build directory "$DIRECTORY does not exist."