From 18a9aca9a1c86509ee02169cf6b54657d9b8703c Mon Sep 17 00:00:00 2001 From: Nicholas King Date: Tue, 25 May 2021 11:13:24 -0700 Subject: [PATCH 1/4] Put selected text ids in Redux store --- development/index.html | 1 + frontend/MainContainer.tsx | 30 +++++++++++------------------- frontend/actions.ts | 7 +++++++ frontend/reducers.ts | 15 +++++++++++++-- transformerviz/assets/index.html | 1 + 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/development/index.html b/development/index.html index e667447..7439887 100644 --- a/development/index.html +++ b/development/index.html @@ -11,6 +11,7 @@ window.API_SERVICE_ENVIRONMENT = { port: 5000 }; window.APP_STATE = { analysisResults: [], + selectedTextIds: [], error: null, loading: false }; diff --git a/frontend/MainContainer.tsx b/frontend/MainContainer.tsx index 9cecc88..5f92678 100644 --- a/frontend/MainContainer.tsx +++ b/frontend/MainContainer.tsx @@ -5,7 +5,8 @@ import { requestGenerateText, setGeneratedTextResults, generateTextFailed, - generateText + generateText, + selectText } from './actions'; import TextGenerationControl from "./components/TextGenerationControl"; import TextGenerationResults from "./components/TextGenerationResults"; @@ -16,36 +17,25 @@ type ContainerProps = { analysisResults: AnalyzedText[], error: any, loading: any, + selectedTextIds: Array, requestGenerateText: Function, setGeneratedTextResults: Function, generateTextFailed: any, generateText: any + selectText: Function } const Container: React.FunctionComponent = ({ analysisResults, error, loading, + selectedTextIds, requestGenerateText, setGeneratedTextResults, generateTextFailed, - generateText + generateText, + selectText }) => { - const [selectedTextIds, setSelectedTextIds] = useState(new Array()); - console.log("Container state: ", selectedTextIds) - - const onSelectTextId = (id: number) => { - if (selectedTextIds.includes(id)) { - console.log(`Deselecting ${id}`) - // Deselect - setSelectedTextIds(selectedTextIds.filter(item => item != id)); - } else { - console.log(`Selecting ${id}`) - // Add to selected ids - setSelectedTextIds([...selectedTextIds, id]); - } - } - const getDetailedAnalysisComponent = () => { if (selectedTextIds.length == 0) { return (); @@ -65,7 +55,7 @@ const Container: React.FunctionComponent = ({ analysisResults={analysisResults} loading={loading} error={error} - onSelectTextId={onSelectTextId} + onSelectTextId={selectText} selectedTextIds={selectedTextIds} /> {getDetailedAnalysisComponent()} @@ -78,6 +68,7 @@ function mapStateToProps (state) { analysisResults: state.analysisResults, error: state.error, loading: state.loading, + selectedTextIds: state.selectedTextIds, }; } @@ -86,7 +77,8 @@ function mapDispatchToProps (dispatch) { requestGenerateText: requestGenerateText, setGeneratedTextResults: setGeneratedTextResults, generateTextFailed: generateTextFailed, - generateText: generateText + generateText: generateText, + selectText: selectText }, dispatch); } diff --git a/frontend/actions.ts b/frontend/actions.ts index 22e9237..48565e4 100644 --- a/frontend/actions.ts +++ b/frontend/actions.ts @@ -30,6 +30,12 @@ function generateText(config) { } } +function selectText(id: number) { + return { + type: "SELECT_TEXT", + id: id + } +} export { @@ -37,4 +43,5 @@ export { setGeneratedTextResults, generateTextFailed, generateText, + selectText, }; diff --git a/frontend/reducers.ts b/frontend/reducers.ts index 308412f..a595e05 100644 --- a/frontend/reducers.ts +++ b/frontend/reducers.ts @@ -1,9 +1,10 @@ -import AnalyzedText from "./models/AnalyzedText" +import AnalyzedText from "./models/AnalyzedText"; const rawInitialState = { analysisResults: [], + selectedTextIds: [], error: null, - loading: false + loading: false, } const initialState = window["APP_STATE"] || rawInitialState; @@ -20,6 +21,16 @@ function rootReducer(state = initialState, action) { case "SET_GENERATED_TEXT_RESULTS": const analysisResults = action.text_generation_results?.map((result) => new AnalyzedText(result)); return Object.assign({}, state, {loading: false, analysisResults: analysisResults, error: null}); + + case "SELECT_TEXT": + const id = action.id; + let textIds = state.selectedTextIds; + if (state.selectedTextIds.includes(id)) { + textIds = textIds.filter(item => item != id); + } else { + textIds = [...textIds, id]; + } + return Object.assign({}, state, {selectedTextIds: textIds}); default: return state diff --git a/transformerviz/assets/index.html b/transformerviz/assets/index.html index a5b9d5b..0dc343e 100644 --- a/transformerviz/assets/index.html +++ b/transformerviz/assets/index.html @@ -13,6 +13,7 @@ window.APP_STATE = { analysisResults: [], + selectedTextIds: [], error: null, loading: false }; From 34941f5325f75deb5836a3b5c32ff179bbeded09 Mon Sep 17 00:00:00 2001 From: Nicholas King Date: Tue, 25 May 2021 11:39:30 -0700 Subject: [PATCH 2/4] Fix bar chart centering --- frontend/components/PerspectiveScoresBarChart.tsx | 9 +++++---- frontend/components/TextGenerationResults.tsx | 12 ++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/frontend/components/PerspectiveScoresBarChart.tsx b/frontend/components/PerspectiveScoresBarChart.tsx index 27e5fc1..1eadd10 100644 --- a/frontend/components/PerspectiveScoresBarChart.tsx +++ b/frontend/components/PerspectiveScoresBarChart.tsx @@ -11,6 +11,7 @@ type PerspectiveScoresBarChartState = { type PerspectiveScoresBarChartProps = { id: number, + width: number, scores: any, defaultSelectedScore: string } @@ -52,7 +53,7 @@ class PerspectiveScoresBarChart extends Component

Generated Results

@@ -62,8 +58,8 @@ class TextGenerationResults extends React.Component {item.id} -
- +
+
) @@ -158,7 +161,9 @@ class TextGenerationControl extends React.Component<
-
- - - - - - - - +
+
+ + +
+
+ Max Length + + [1-100] + Min Length + + [1-100] +
+
+ Num. Beams + + [1-100] + Top K + +
+
+
+ + +
); diff --git a/frontend/components/TextGenerationResults.tsx b/frontend/components/TextGenerationResults.tsx index f51dfbc..217697a 100644 --- a/frontend/components/TextGenerationResults.tsx +++ b/frontend/components/TextGenerationResults.tsx @@ -1,4 +1,5 @@ import React from "react"; +import { ComboBox, IComboBoxOption, Stack } from "office-ui-fabric-react" import AnalyzedText from "../models/AnalyzedText"; import PerspectiveScoresBarChart from "./PerspectiveScoresBarChart"; @@ -48,11 +49,46 @@ class TextGenerationResults extends React.Component -

Generated Results

+

Generated Results

+ + + + {this.props.analysisResults.map((item) =>
From 0e396dde03aaf413404dd8f552a7b11b468c063a Mon Sep 17 00:00:00 2001 From: Nicholas King Date: Tue, 25 May 2021 13:52:27 -0700 Subject: [PATCH 4/4] Use mask to prevent NaN input, adjust form layout --- frontend/app.css | 7 ++ frontend/components/TextGenerationControl.tsx | 69 ++++++++++++------- 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/frontend/app.css b/frontend/app.css index 04a3cab..fa85492 100644 --- a/frontend/app.css +++ b/frontend/app.css @@ -35,6 +35,13 @@ h1 { grid-template-columns: 1fr 2fr 2fr 3fr; } +.stacked-text-field-grid { + display: grid; + grid-template-rows: 1fr 1fr; + grid-template-columns: 1fr 2fr; + align-items: center; +} + .ms-Checkbox-label { font-weight: 600; } \ No newline at end of file diff --git a/frontend/components/TextGenerationControl.tsx b/frontend/components/TextGenerationControl.tsx index 0832265..7557f25 100644 --- a/frontend/components/TextGenerationControl.tsx +++ b/frontend/components/TextGenerationControl.tsx @@ -2,6 +2,7 @@ import React, { FunctionComponent } from "react"; import ReactDOM from "react-dom"; import { Fabric } from "office-ui-fabric-react/lib/Fabric"; import { TextField } from "office-ui-fabric-react/lib/TextField"; +import { MaskedTextField } from "office-ui-fabric-react/lib/TextField"; import { PrimaryButton } from "office-ui-fabric-react/lib/Button"; import { Checkbox, Stack, Slider } from "office-ui-fabric-react"; import { FiChevronUp, FiChevronDown } from "react-icons/fi"; @@ -198,37 +199,53 @@ class TextGenerationControl extends React.Component< checked={this.state.earlyStopping} />
-
+
Max Length - - [1-100] +
+ + [1-100] +
Min Length - - [1-100] +
+ + [1-100] +
-
+
Num. Beams - - [1-100] +
+ + [1-100] +
Top K - -
+
+ +
+