Skip to content

Commit 9d7e092

Browse files
authored
Merge pull request #185 from ThinkDeepTech/hm/select-business-ui
2 parents f025513 + 4d923bc commit 9d7e092

File tree

6 files changed

+70
-31
lines changed

6 files changed

+70
-31
lines changed

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@babel/plugin-proposal-class-properties": "^7.2.3",
3434
"@babel/plugin-proposal-decorators": "^7.2.3",
3535
"@babel/plugin-transform-runtime": "^7.1.0",
36-
"@babel/preset-env": "^7.12.10",
36+
"@babel/preset-env": "^7.16.0",
3737
"@babel/runtime": "^7.0.0",
3838
"@web/dev-server-esbuild": "^0.2.12",
3939
"babel-eslint": "^10.0.1",
@@ -57,9 +57,6 @@
5757
"serve": "^10.1.1",
5858
"wait-on": "^6.0.0"
5959
},
60-
"resolutions": {
61-
"graphql": "^15.8.0"
62-
},
6360
"workspaces": [
6461
"packages/*"
6562
],

packages/deep-graphql-binding/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"dependencies": {
3333
"@graphql-tools/delegate": "^8.4.3",
3434
"@graphql-tools/graphql-file-loader": "^7.3.3",
35-
"@graphql-tools/load": "^7.4.1",
35+
"@graphql-tools/load": "7.4.1",
3636
"@graphql-tools/schema": "^8.3.1",
3737
"@graphql-tools/utils": "^8.5.4",
3838
"graphql": "^15.8.0",

packages/deep-template-analyzer/deep-analyzer-page-summary.js

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import {ApolloMutationController} from '@apollo-elements/core';
2-
import {ApolloQuery, css, html} from '@apollo-elements/lit-apollo';
1+
import {
2+
ApolloMutationController,
3+
ApolloQueryController,
4+
} from '@apollo-elements/core';
5+
import {LitElement, css, html} from '@apollo-elements/lit-apollo';
36
import '@google-web-components/google-chart';
47
import '@material/mwc-button';
8+
import '@material/mwc-list/mwc-list-item';
9+
import '@material/mwc-select';
510
import '@material/mwc-textfield';
611
import '@thinkdeep/deep-button/deep-button.mjs';
712
import '@thinkdeep/deep-card/deep-card.mjs';
@@ -11,9 +16,10 @@ import {translate} from 'lit-element-i18n';
1116
import CollectEconomicData from './graphql/CollectEconomicData.mutation.graphql';
1217
import GetSentiment from './graphql/GetSentiment.query.graphql';
1318

14-
export default class DeepAnalyzerPageSummary extends ApolloQuery {
19+
export default class DeepAnalyzerPageSummary extends LitElement {
1520
static get properties() {
1621
return {
22+
query: {type: Object},
1723
mutation: {type: Object},
1824
selectedSentiments: {type: Array},
1925
};
@@ -22,12 +28,13 @@ export default class DeepAnalyzerPageSummary extends ApolloQuery {
2228
constructor() {
2329
super();
2430

25-
this.query = GetSentiment;
26-
27-
this.variables = {
28-
economicEntityName: 'Google',
29-
economicEntityType: 'BUSINESS',
30-
};
31+
this.query = new ApolloQueryController(this, GetSentiment, {
32+
variables: {
33+
economicEntityName: 'Google',
34+
economicEntityType: 'BUSINESS',
35+
},
36+
onData: this._triggerUpdate.bind(this),
37+
});
3138

3239
this.mutation = new ApolloMutationController(this, CollectEconomicData);
3340

@@ -38,12 +45,14 @@ export default class DeepAnalyzerPageSummary extends ApolloQuery {
3845
super.connectedCallback();
3946

4047
this.addEventListener('google-chart-select', this._handleChartSelection);
48+
this.addEventListener('selected', this._onSelect);
4149
}
4250

4351
disconnectedCallback() {
4452
super.disconnectedCallback();
4553

4654
this.removeEventListener('google-chart-select', this._handleChartSelection);
55+
this.removeEventListener('selected', this._onSelect);
4756
}
4857

4958
static get styles() {
@@ -60,7 +69,7 @@ export default class DeepAnalyzerPageSummary extends ApolloQuery {
6069
${translate('translations:startCollectingLabel')}
6170
<mwc-textfield
6271
label="Business name"
63-
@input="${debounce(this._setCompanyName.bind(this), 350)}"
72+
@input="${debounce(this._onInput.bind(this), 350)}"
6473
></mwc-textfield>
6574
<mwc-button
6675
raised
@@ -69,18 +78,24 @@ export default class DeepAnalyzerPageSummary extends ApolloQuery {
6978
icon="input"
7079
></mwc-button>
7180
72-
<div>
73-
<google-chart
74-
type="line"
75-
options="{&quot;title&quot;: &quot;Sentiment as a function of time&quot; }"
76-
cols="[{&quot;label&quot;: &quot;Timestamp&quot;, &quot;type&quot;: &quot;number&quot;}, {&quot;label&quot;: &quot;Sentiment&quot;, &quot;type&quot;: &quot;number&quot;}]"
77-
rows="[${
78-
this.data?.sentiments?.map((sentiment) =>
79-
JSON.stringify([sentiment.timestamp, sentiment.score])
80-
)
81-
}]"
82-
></google-chart>
83-
</div>
81+
<mwc-select label="Select a business">
82+
<mwc-list-item value="Google">Google</mwc-list-item>
83+
<mwc-list-item value="Amazon">Amazon</mwc-list-item>
84+
<mwc-list-item value="PetCo">PetCo</mwc-list-item>
85+
<mwc-list-item value="Tesla">Tesla</mwc-list-item>
86+
<mwc-list-item value="Ford">Ford</mwc-list-item>
87+
</mwc-select>
88+
89+
<google-chart
90+
type="line"
91+
options="{&quot;title&quot;: &quot;Sentiment as a function of time&quot; }"
92+
cols="[{&quot;label&quot;: &quot;Timestamp&quot;, &quot;type&quot;: &quot;number&quot;}, {&quot;label&quot;: &quot;Sentiment&quot;, &quot;type&quot;: &quot;number&quot;}]"
93+
rows="[${
94+
this.query?.data?.sentiments?.map((sentiment) =>
95+
JSON.stringify([sentiment.timestamp, sentiment.score])
96+
)
97+
}]"
98+
></google-chart>
8499
85100
${
86101
this.selectedSentiments.map((sentiment) =>
@@ -111,7 +126,7 @@ export default class DeepAnalyzerPageSummary extends ApolloQuery {
111126

112127
const selectedPoint = googleChart.rows[selectedRow];
113128

114-
this.data?.sentiments?.forEach((sentiment) => {
129+
this.query?.data?.sentiments?.forEach((sentiment) => {
115130
if (this._hasMatchingData(sentiment, selectedPoint)) {
116131
this.selectedSentiments.push(sentiment);
117132
}
@@ -132,13 +147,39 @@ export default class DeepAnalyzerPageSummary extends ApolloQuery {
132147
);
133148
}
134149

135-
_setCompanyName({explicitOriginalTarget}) {
150+
/**
151+
* Handle input.
152+
* @param {HTMLElement} explicitOriginalTarget - The input element containing the business for which data will be collected.
153+
*/
154+
_onInput({explicitOriginalTarget}) {
136155
const companyName = explicitOriginalTarget.value;
137156
this.mutation.variables = {
138157
economicEntityName: companyName,
139158
economicEntityType: 'BUSINESS',
140159
};
141160
}
161+
162+
/**
163+
* Find the selected business and add it to the query variables.
164+
*/
165+
_onSelect() {
166+
const businessName = this.shadowRoot.querySelector('[aria-selected="true"]')
167+
.value;
168+
this.query.variables = {
169+
economicEntityName: businessName,
170+
economicEntityType: 'BUSINESS',
171+
};
172+
}
173+
174+
/**
175+
* Trigger an update to the DOM.
176+
*
177+
* NOTE: This is used because the google-chart wasn't dynamically updating as a result of data fetch.
178+
* This happened to solve the issue.
179+
*/
180+
_triggerUpdate() {
181+
this.requestUpdate();
182+
}
142183
}
143184

144185
customElements.define('deep-analyzer-page-summary', DeepAnalyzerPageSummary);

packages/deep-template-analyzer/deep-template-analyzer.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ export class DeepTemplateAnalyzer extends i18nMixin(LitElement) {
144144
${this.styles}
145145
146146
<mwc-top-app-bar-fixed>
147-
<mwc-icon-button icon="menu" slot="navigationIcon"></mwc-icon-button>
148-
149147
<div slot="title">${this.companyName}</div>
150148
151149
<mwc-icon-button

packages/deep-template-analyzer/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
"@google-web-components/google-chart": "^5.0.0",
7171
"@material/mwc-button": "^0.25.3",
7272
"@material/mwc-icon-button": "^0.25.3",
73+
"@material/mwc-list": "^0.25.3",
74+
"@material/mwc-select": "^0.25.3",
7375
"@material/mwc-textfield": "^0.25.3",
7476
"@material/mwc-top-app-bar-fixed": "^0.25.3",
7577
"@thinkdeep/deep-button": "^0.0.8",

packages/tools/web-dev-server.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO: Update to @rollup/plugin-graphql
12
import rollupGraphQL from '@apollo-elements/rollup-plugin-graphql';
23
import rollupReplace from '@rollup/plugin-replace';
34
import { fromRollup } from '@web/dev-server-rollup';

0 commit comments

Comments
 (0)