@oanda/labs-sentiment-widget 1.0.173 → 1.0.175

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/CHANGELOG.md +1372 -0
  2. package/dist/main/SentimentWidget/SentimentWidget.js +10 -10
  3. package/dist/main/SentimentWidget/SentimentWidget.js.map +1 -1
  4. package/dist/main/SentimentWidget/Tool.js +19 -18
  5. package/dist/main/SentimentWidget/Tool.js.map +1 -1
  6. package/dist/main/SentimentWidget/Widget.js +17 -16
  7. package/dist/main/SentimentWidget/Widget.js.map +1 -1
  8. package/dist/main/SentimentWidget/components/SortSwitch/SortSwitch.js +13 -13
  9. package/dist/main/SentimentWidget/components/SortSwitch/SortSwitch.js.map +1 -1
  10. package/dist/main/SentimentWidget/render.js +9 -9
  11. package/dist/main/SentimentWidget/render.js.map +1 -1
  12. package/dist/main/SentimentWidget/types.js.map +1 -1
  13. package/dist/main/SentimentWidget/utils.js.map +1 -1
  14. package/dist/main/gql/getInstrumentSentiment.js +3 -19
  15. package/dist/main/gql/getInstrumentSentiment.js.map +1 -1
  16. package/dist/main/gql/getSentimentList.js +3 -17
  17. package/dist/main/gql/getSentimentList.js.map +1 -1
  18. package/dist/main/gql/types/fragment-masking.js +3 -2
  19. package/dist/main/gql/types/fragment-masking.js.map +1 -1
  20. package/dist/main/gql/types/gql.js +4 -3
  21. package/dist/main/gql/types/gql.js.map +1 -1
  22. package/dist/main/gql/types/graphql.js +154 -154
  23. package/dist/main/gql/types/graphql.js.map +1 -1
  24. package/dist/main/gql/types/index.js.map +1 -1
  25. package/dist/main/index.js +8 -8
  26. package/dist/main/index.js.map +1 -1
  27. package/dist/main/translations/index.js +1 -1
  28. package/dist/main/translations/index.js.map +1 -1
  29. package/dist/main/translations/translations.js.map +1 -1
  30. package/dist/module/SentimentWidget/SentimentWidget.js +10 -10
  31. package/dist/module/SentimentWidget/SentimentWidget.js.map +1 -1
  32. package/dist/module/SentimentWidget/Tool.js +18 -17
  33. package/dist/module/SentimentWidget/Tool.js.map +1 -1
  34. package/dist/module/SentimentWidget/Widget.js +18 -17
  35. package/dist/module/SentimentWidget/Widget.js.map +1 -1
  36. package/dist/module/SentimentWidget/components/SortSwitch/SortSwitch.js +13 -13
  37. package/dist/module/SentimentWidget/components/SortSwitch/SortSwitch.js.map +1 -1
  38. package/dist/module/SentimentWidget/render.js +9 -9
  39. package/dist/module/SentimentWidget/render.js.map +1 -1
  40. package/dist/module/SentimentWidget/types.js.map +1 -1
  41. package/dist/module/SentimentWidget/utils.js.map +1 -1
  42. package/dist/module/gql/getInstrumentSentiment.js +3 -19
  43. package/dist/module/gql/getInstrumentSentiment.js.map +1 -1
  44. package/dist/module/gql/getSentimentList.js +3 -17
  45. package/dist/module/gql/getSentimentList.js.map +1 -1
  46. package/dist/module/gql/types/fragment-masking.js +3 -2
  47. package/dist/module/gql/types/fragment-masking.js.map +1 -1
  48. package/dist/module/gql/types/gql.js +4 -3
  49. package/dist/module/gql/types/gql.js.map +1 -1
  50. package/dist/module/gql/types/graphql.js +154 -154
  51. package/dist/module/gql/types/graphql.js.map +1 -1
  52. package/dist/module/gql/types/index.js +2 -2
  53. package/dist/module/gql/types/index.js.map +1 -1
  54. package/dist/module/index.js +1 -1
  55. package/dist/module/index.js.map +1 -1
  56. package/dist/module/translations/index.js +1 -1
  57. package/dist/module/translations/index.js.map +1 -1
  58. package/dist/module/translations/translations.js.map +1 -1
  59. package/dist/types/SentimentWidget/SentimentWidget.d.ts +1 -1
  60. package/dist/types/SentimentWidget/Tool.d.ts +1 -1
  61. package/dist/types/SentimentWidget/Widget.d.ts +1 -1
  62. package/dist/types/SentimentWidget/components/SortSwitch/SortSwitch.d.ts +2 -2
  63. package/dist/types/SentimentWidget/types.d.ts +2 -2
  64. package/dist/types/SentimentWidget/utils.d.ts +2 -1
  65. package/dist/types/gql/types/gql.d.ts +4 -4
  66. package/dist/types/gql/types/index.d.ts +2 -2
  67. package/dist/types/index.d.ts +1 -1
  68. package/dist/types/translations/index.d.ts +2 -2
  69. package/package.json +3 -3
  70. package/src/SentimentWidget/SentimentWidget.tsx +18 -19
  71. package/src/SentimentWidget/Tool.tsx +94 -78
  72. package/src/SentimentWidget/Widget.tsx +70 -64
  73. package/src/SentimentWidget/components/SortSwitch/SortSwitch.tsx +41 -38
  74. package/src/SentimentWidget/render.tsx +40 -28
  75. package/src/SentimentWidget/types.ts +3 -2
  76. package/src/SentimentWidget/utils.ts +12 -4
  77. package/src/gql/getInstrumentSentiment.ts +2 -8
  78. package/src/gql/getSentimentList.ts +2 -6
  79. package/src/gql/types/fragment-masking.ts +41 -21
  80. package/src/gql/types/gql.ts +12 -5
  81. package/src/gql/types/graphql.ts +225 -47
  82. package/src/gql/types/index.ts +2 -2
  83. package/src/index.ts +1 -1
  84. package/src/translations/index.ts +4 -4
  85. package/src/translations/translations.ts +2 -1
  86. package/test/SortSwitch.test.tsx +11 -7
  87. package/test/Tool.test.tsx +8 -6
  88. package/test/Widget.test.tsx +26 -21
  89. package/test/sortData.test.ts +49 -13
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Locale","en","zhTW","es","th","translations","translation"],"sources":["../../../src/translations/index.ts"],"sourcesContent":["import { Locale, Translations } from '@oanda/mono-i18n';\n\nimport en from './sources/en.json';\nimport zhTW from './sources/zh_TW.json';\nimport es from './sources/es.json';\nimport th from './sources/th.json';\n\nimport { defaultTranslations } from './translations';\n\nexport type TranslationKey = keyof typeof defaultTranslations;\n\nexport const translations: Translations = {\n [Locale.en]: { translation: en },\n [Locale.zhTW]: { translation: zhTW },\n [Locale.es]: { translation: es },\n [Locale.th]: { translation: th },\n};\n"],"mappings":"AAAA,SAASA,MAAM,QAAsB,kBAAkB;AAEvD,OAAOC,EAAE,MAAM,mBAAmB;AAClC,OAAOC,IAAI,MAAM,sBAAsB;AACvC,OAAOC,EAAE,MAAM,mBAAmB;AAClC,OAAOC,EAAE,MAAM,mBAAmB;AAMlC,OAAO,MAAMC,YAA0B,GAAG;EACxC,CAACL,MAAM,CAACC,EAAE,GAAG;IAAEK,WAAW,EAAEL;EAAG,CAAC;EAChC,CAACD,MAAM,CAACE,IAAI,GAAG;IAAEI,WAAW,EAAEJ;EAAK,CAAC;EACpC,CAACF,MAAM,CAACG,EAAE,GAAG;IAAEG,WAAW,EAAEH;EAAG,CAAC;EAChC,CAACH,MAAM,CAACI,EAAE,GAAG;IAAEE,WAAW,EAAEF;EAAG;AACjC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["Locale","en","es","th","zhTW","translations","translation"],"sources":["../../../src/translations/index.ts"],"sourcesContent":["import type { Translations } from '@oanda/mono-i18n';\nimport { Locale } from '@oanda/mono-i18n';\n\nimport en from './sources/en.json';\nimport es from './sources/es.json';\nimport th from './sources/th.json';\nimport zhTW from './sources/zh_TW.json';\nimport type { defaultTranslations } from './translations';\n\nexport type TranslationKey = keyof typeof defaultTranslations;\n\nexport const translations: Translations = {\n [Locale.en]: { translation: en },\n [Locale.zhTW]: { translation: zhTW },\n [Locale.es]: { translation: es },\n [Locale.th]: { translation: th },\n};\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,kBAAkB;AAEzC,OAAOC,EAAE,MAAM,mBAAmB;AAClC,OAAOC,EAAE,MAAM,mBAAmB;AAClC,OAAOC,EAAE,MAAM,mBAAmB;AAClC,OAAOC,IAAI,MAAM,sBAAsB;AAKvC,OAAO,MAAMC,YAA0B,GAAG;EACxC,CAACL,MAAM,CAACC,EAAE,GAAG;IAAEK,WAAW,EAAEL;EAAG,CAAC;EAChC,CAACD,MAAM,CAACI,IAAI,GAAG;IAAEE,WAAW,EAAEF;EAAK,CAAC;EACpC,CAACJ,MAAM,CAACE,EAAE,GAAG;IAAEI,WAAW,EAAEJ;EAAG,CAAC;EAChC,CAACF,MAAM,CAACG,EAAE,GAAG;IAAEG,WAAW,EAAEH;EAAG;AACjC,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"translations.js","names":["defaultTranslations","data_unavailable","pagination_entries_range"],"sources":["../../../src/translations/translations.ts"],"sourcesContent":["export const defaultTranslations = {\n data_unavailable: 'Data unavailable',\n pagination_entries_range: '{{firstItemOnPage}}-{{lastItemOnPage}} of {{itemCount}} entries',\n};\n"],"mappings":"AAAA,OAAO,MAAMA,mBAAmB,GAAG;EACjCC,gBAAgB,EAAE,kBAAkB;EACpCC,wBAAwB,EAAE;AAC5B,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"translations.js","names":["defaultTranslations","data_unavailable","pagination_entries_range"],"sources":["../../../src/translations/translations.ts"],"sourcesContent":["export const defaultTranslations = {\n data_unavailable: 'Data unavailable',\n pagination_entries_range:\n '{{firstItemOnPage}}-{{lastItemOnPage}} of {{itemCount}} entries',\n};\n"],"mappings":"AAAA,OAAO,MAAMA,mBAAmB,GAAG;EACjCC,gBAAgB,EAAE,kBAAkB;EACpCC,wBAAwB,EACtB;AACJ,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
- import { SentimentConfig } from './types';
2
+ import type { SentimentConfig } from './types';
3
3
  declare const SentimentWidget: ({ graphqlUrl, division, instrument, locale, theme, includeDescriptionLabels, isParamError, logoLink, }: SentimentConfig) => React.JSX.Element;
4
4
  export { SentimentWidget };
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
- import { SentimentToolConfig } from './types';
2
+ import type { SentimentToolConfig } from './types';
3
3
  declare const Tool: ({ division }: SentimentToolConfig) => React.JSX.Element;
4
4
  export { Tool };
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
- import { SentimentWidgetConfig } from './types';
2
+ import type { SentimentWidgetConfig } from './types';
3
3
  declare const Widget: ({ instrument, division, includeDescriptionLabels, }: SentimentWidgetConfig) => React.JSX.Element;
4
4
  export { Widget };
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
- import { SortSwitchProps } from './types';
2
+ import type { SortSwitchProps } from './types';
3
3
  declare const SortSwitch: ({ onClickButtonDown, onClickButtonUp, selected, disabled, }: SortSwitchProps) => React.JSX.Element;
4
- export { SortSwitch, };
4
+ export { SortSwitch };
@@ -1,5 +1,5 @@
1
- import { WidgetConfig } from '@oanda/labs-widget-common';
2
- import { Division } from '../gql/types/graphql';
1
+ import type { WidgetConfig } from '@oanda/labs-widget-common';
2
+ import type { Division } from '../gql/types/graphql';
3
3
  export interface SentimentConfig extends WidgetConfig {
4
4
  division: Division;
5
5
  instrument?: string;
@@ -1,4 +1,5 @@
1
- import { GetSentimentListQuery, Sort } from '../gql/types/graphql';
1
+ import type { GetSentimentListQuery } from '../gql/types/graphql';
2
+ import { Sort } from '../gql/types/graphql';
2
3
  export declare const sortData: ({ sentimentList }: GetSentimentListQuery, sort: Sort) => {
3
4
  __typename?: "SentimentInstrument";
4
5
  name: string;
@@ -11,11 +11,11 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
11
11
  * Therefore it is highly recommended to use the babel or swc plugin for production.
12
12
  */
13
13
  declare const documents: {
14
- "\n query GetInstrumentSentiment(\n $name: String!\n $division: Division\n ) {\n sentiment(\n name: $name\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n": DocumentNode<types.GetInstrumentSentimentQuery, types.Exact<{
14
+ '\n query GetInstrumentSentiment(\n $name: String!\n $division: Division\n ) {\n sentiment(\n name: $name\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n': DocumentNode<types.GetInstrumentSentimentQuery, types.Exact<{
15
15
  name: types.Scalars["String"]["input"];
16
16
  division?: types.InputMaybe<types.Division>;
17
17
  }>>;
18
- "\n query GetSentimentList (\n $division: Division\n ) {\n sentimentList (\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n": DocumentNode<types.GetSentimentListQuery, types.Exact<{
18
+ '\n query GetSentimentList (\n $division: Division\n ) {\n sentimentList (\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n': DocumentNode<types.GetSentimentListQuery, types.Exact<{
19
19
  division?: types.InputMaybe<types.Division>;
20
20
  }>>;
21
21
  };
@@ -35,10 +35,10 @@ export declare function graphql(source: string): unknown;
35
35
  /**
36
36
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
37
37
  */
38
- export declare function graphql(source: "\n query GetInstrumentSentiment(\n $name: String!\n $division: Division\n ) {\n sentiment(\n name: $name\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n"): (typeof documents)["\n query GetInstrumentSentiment(\n $name: String!\n $division: Division\n ) {\n sentiment(\n name: $name\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n"];
38
+ export declare function graphql(source: '\n query GetInstrumentSentiment(\n $name: String!\n $division: Division\n ) {\n sentiment(\n name: $name\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n'): (typeof documents)['\n query GetInstrumentSentiment(\n $name: String!\n $division: Division\n ) {\n sentiment(\n name: $name\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n'];
39
39
  /**
40
40
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
41
41
  */
42
- export declare function graphql(source: "\n query GetSentimentList (\n $division: Division\n ) {\n sentimentList (\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n"): (typeof documents)["\n query GetSentimentList (\n $division: Division\n ) {\n sentimentList (\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n"];
42
+ export declare function graphql(source: '\n query GetSentimentList (\n $division: Division\n ) {\n sentimentList (\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n'): (typeof documents)['\n query GetSentimentList (\n $division: Division\n ) {\n sentimentList (\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n'];
43
43
  export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode<infer TType, any> ? TType : never;
44
44
  export {};
@@ -1,2 +1,2 @@
1
- export * from "./fragment-masking";
2
- export * from "./gql";
1
+ export * from './fragment-masking';
2
+ export * from './gql';
@@ -1,2 +1,2 @@
1
- export * from './SentimentWidget/types';
2
1
  export * from './SentimentWidget/SentimentWidget';
2
+ export * from './SentimentWidget/types';
@@ -1,4 +1,4 @@
1
- import { Translations } from '@oanda/mono-i18n';
2
- import { defaultTranslations } from './translations';
1
+ import type { Translations } from '@oanda/mono-i18n';
2
+ import type { defaultTranslations } from './translations';
3
3
  export type TranslationKey = keyof typeof defaultTranslations;
4
4
  export declare const translations: Translations;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oanda/labs-sentiment-widget",
3
- "version": "1.0.173",
3
+ "version": "1.0.175",
4
4
  "description": "Labs Sentiment Widget",
5
5
  "main": "dist/main/index.js",
6
6
  "module": "dist/module/index.js",
@@ -12,7 +12,7 @@
12
12
  "author": "OANDA",
13
13
  "license": "UNLICENSED",
14
14
  "dependencies": {
15
- "@oanda/labs-widget-common": "^1.0.173",
15
+ "@oanda/labs-widget-common": "^1.0.175",
16
16
  "@oanda/mono-i18n": "10.0.1",
17
17
  "graphql": "16.8.1"
18
18
  },
@@ -20,5 +20,5 @@
20
20
  "@graphql-codegen/cli": "5.0.0",
21
21
  "@graphql-codegen/client-preset": "4.1.0"
22
22
  },
23
- "gitHead": "67a7801f99f0bab94dd6067a102761f51de786c1"
23
+ "gitHead": "ffe302e74b4bdf5fb28f1f7be09cfd2cb7672eb3"
24
24
  }
@@ -1,10 +1,11 @@
1
- import React from 'react';
2
1
  import { ApolloClient, InMemoryCache } from '@apollo/client';
3
2
  import { WidgetProvider, WidgetWrapper } from '@oanda/labs-widget-common';
4
- import { Widget } from './Widget';
5
- import { Tool } from './Tool';
6
- import { SentimentConfig } from './types';
3
+ import React from 'react';
4
+
7
5
  import { translations } from '../translations';
6
+ import { Tool } from './Tool';
7
+ import type { SentimentConfig } from './types';
8
+ import { Widget } from './Widget';
8
9
 
9
10
  const SentimentWidget = ({
10
11
  graphqlUrl,
@@ -23,27 +24,25 @@ const SentimentWidget = ({
23
24
 
24
25
  return (
25
26
  <WidgetProvider
26
- locale={locale}
27
- translations={translations}
28
27
  client={client}
28
+ locale={locale}
29
29
  theme={theme}
30
+ translations={translations}
30
31
  >
31
32
  <WidgetWrapper
32
- logoLink={logoLink}
33
- linkArea="logo"
34
33
  isParamError={isParamError}
34
+ linkArea="logo"
35
+ logoLink={logoLink}
35
36
  >
36
- {
37
- instrument
38
- ? (
39
- <Widget
40
- division={division}
41
- instrument={instrument}
42
- includeDescriptionLabels={includeDescriptionLabels}
43
- />
44
- )
45
- : <Tool division={division} />
46
- }
37
+ {instrument ? (
38
+ <Widget
39
+ division={division}
40
+ includeDescriptionLabels={includeDescriptionLabels}
41
+ instrument={instrument}
42
+ />
43
+ ) : (
44
+ <Tool division={division} />
45
+ )}
47
46
  </WidgetWrapper>
48
47
  </WidgetProvider>
49
48
  );
@@ -1,37 +1,43 @@
1
- import React, { useEffect, useState } from 'react';
2
- import classNames from 'classnames';
1
+ import { useQuery } from '@apollo/client';
3
2
  import {
4
- Sentiment,
5
- SentimentHeight,
3
+ ChartError,
4
+ EMPTY_VALUE,
5
+ LastUpdated,
6
6
  Loader,
7
7
  LoaderSize,
8
- ChartError,
9
- Truncate,
8
+ Sentiment,
9
+ SentimentHeight,
10
+ Size,
10
11
  Tooltip,
12
+ Truncate,
11
13
  useLayoutProvider,
12
- Size,
13
- EMPTY_VALUE,
14
- LastUpdated,
15
14
  } from '@oanda/labs-widget-common';
16
- import { useQuery } from '@apollo/client';
17
15
  import { useLocale } from '@oanda/mono-i18n';
16
+ import classNames from 'classnames';
17
+ import React, { useEffect, useState } from 'react';
18
+
19
+ import { INSTRUMENT_TOOLTIP_ID } from '../constant';
18
20
  import { getSentimentList } from '../gql/getSentimentList';
19
- import { SentimentToolConfig } from './types';
20
- import { sortData } from './utils';
21
- import { SelectedArrow, SortSwitch } from './components/SortSwitch';
22
- import {
23
- GetSentimentListQuery, GetSentimentListQueryVariables, SentimentInstrument, Sort,
21
+ import type {
22
+ GetSentimentListQuery,
23
+ GetSentimentListQueryVariables,
24
+ SentimentInstrument,
24
25
  } from '../gql/types/graphql';
25
- import { INSTRUMENT_TOOLTIP_ID } from '../constant';
26
+ import { Sort } from '../gql/types/graphql';
27
+ import { SelectedArrow, SortSwitch } from './components/SortSwitch';
28
+ import type { SentimentToolConfig } from './types';
29
+ import { sortData } from './utils';
26
30
 
27
31
  const Tool = ({ division }: SentimentToolConfig) => {
28
32
  const { size } = useLayoutProvider();
29
33
  const isDesktop = size === Size.DESKTOP;
30
34
  const [sort, setSort] = useState(Sort.Bullish);
31
- const [sortedData, setSortedData] = useState<Omit<SentimentInstrument, 'id'>[]>(new Array(20).fill({}));
35
+ const [sortedData, setSortedData] = useState<
36
+ Omit<SentimentInstrument, 'id'>[]
37
+ >(new Array(20).fill({}));
32
38
  const { loading, data, error } = useQuery<
33
- GetSentimentListQuery,
34
- GetSentimentListQueryVariables
39
+ GetSentimentListQuery,
40
+ GetSentimentListQueryVariables
35
41
  >(getSentimentList, {
36
42
  variables: {
37
43
  division,
@@ -47,75 +53,85 @@ const Tool = ({ division }: SentimentToolConfig) => {
47
53
  setSortedData(sortData(data, sort));
48
54
  setUpdatedTimestamp(data.sentimentList![0]?.updatedAt);
49
55
  }
50
- // eslint-disable-next-line react-hooks/exhaustive-deps
51
56
  }, [data, sort]);
52
57
 
53
58
  return (
54
59
  <>
55
60
  {size && (
56
- <div data-testid="sentiment-tool" className="lw-relative lw-bg-bg-primary lw-text-sm lw-tracking-normal lw-text-text-primary">
57
- {error || sortedData.length === 0 ? (
58
- <div className="lw-flex lw-h-[200px] lw-items-center lw-justify-center lw-border lw-border-solid lw-border-border-primary lw-p-2">
59
- <ChartError />
60
- </div>
61
- ) : (
62
- <>
63
- <div className="lw-flex lw-justify-end lw-pb-5">
64
- <SortSwitch
65
- disabled={loading}
66
- selected={sort === Sort.Bullish ? SelectedArrow.UP : SelectedArrow.DOWN}
67
- onClickButtonDown={() => setSort(Sort.Bearish)}
68
- onClickButtonUp={() => setSort(Sort.Bullish)}
69
- />
61
+ <div
62
+ className="lw-relative lw-bg-bg-primary lw-text-sm lw-tracking-normal lw-text-text-primary"
63
+ data-testid="sentiment-tool"
64
+ >
65
+ {error || sortedData.length === 0 ? (
66
+ <div className="lw-flex lw-h-[200px] lw-items-center lw-justify-center lw-border lw-border-solid lw-border-border-primary lw-p-2">
67
+ <ChartError />
70
68
  </div>
71
- <div className="lw-flex lw-flex-col lw-border lw-border-solid lw-border-border-primary lw-p-2">
72
- <div className="lw-mb-2 lw-flex lw-justify-between lw-font-semibold">
73
- <span className={classNames('lw-uppercase', {
74
- 'lw-ml-40': isDesktop,
75
- 'lw-ml-[7.5rem]': !isDesktop,
76
- })}
77
- >
78
- {lang('net_short')}
79
- </span>
80
- <span className={classNames('lw-text-right lw-uppercase', {
81
- 'lw-mr-10': isDesktop,
82
- })}
83
- >
84
- {lang('net_long')}
85
- </span>
69
+ ) : (
70
+ <>
71
+ <div className="lw-flex lw-justify-end lw-pb-5">
72
+ <SortSwitch
73
+ disabled={loading}
74
+ selected={
75
+ sort === Sort.Bullish
76
+ ? SelectedArrow.UP
77
+ : SelectedArrow.DOWN
78
+ }
79
+ onClickButtonDown={() => setSort(Sort.Bearish)}
80
+ onClickButtonUp={() => setSort(Sort.Bullish)}
81
+ />
86
82
  </div>
87
- {sortedData.map((item, index) => (
88
- <div className="lw-flex lw-h-8 lw-w-full lw-items-center" key={item.name || index}>
89
- <div className="lw-w-[120px] lw-shrink-0">
90
- {loading ? (
91
- <Loader size={LoaderSize.md} />
92
- ) : (
93
- <Truncate
94
- maxWidth={120}
95
- tooltipId={INSTRUMENT_TOOLTIP_ID}
96
- className="lw-pr-2 lw-font-sans lw-text-sm lw-font-bold"
97
- text={item.displayName || '\u2014'}
98
- />
99
- )}
100
- </div>
101
- <Sentiment
102
- isLoading={loading}
103
- height={SentimentHeight.md}
104
- sentiment={item.sentiment}
105
- />
83
+ <div className="lw-flex lw-flex-col lw-border lw-border-solid lw-border-border-primary lw-p-2">
84
+ <div className="lw-mb-2 lw-flex lw-justify-between lw-font-semibold">
85
+ <span
86
+ className={classNames('lw-uppercase', {
87
+ 'lw-ml-40': isDesktop,
88
+ 'lw-ml-[7.5rem]': !isDesktop,
89
+ })}
90
+ >
91
+ {lang('net_short')}
92
+ </span>
93
+ <span
94
+ className={classNames('lw-text-right lw-uppercase', {
95
+ 'lw-mr-10': isDesktop,
96
+ })}
97
+ >
98
+ {lang('net_long')}
99
+ </span>
106
100
  </div>
107
- ))}
101
+ {sortedData.map((item, index) => (
102
+ <div
103
+ key={item.name || index}
104
+ className="lw-flex lw-h-8 lw-w-full lw-items-center"
105
+ >
106
+ <div className="lw-w-[120px] lw-shrink-0">
107
+ {loading ? (
108
+ <Loader size={LoaderSize.md} />
109
+ ) : (
110
+ <Truncate
111
+ className="lw-pr-2 lw-font-sans lw-text-sm lw-font-bold"
112
+ maxWidth={120}
113
+ text={item.displayName || '\u2014'}
114
+ tooltipId={INSTRUMENT_TOOLTIP_ID}
115
+ />
116
+ )}
117
+ </div>
118
+ <Sentiment
119
+ height={SentimentHeight.md}
120
+ isLoading={loading}
121
+ sentiment={item.sentiment}
122
+ />
123
+ </div>
124
+ ))}
125
+ </div>
126
+ </>
127
+ )}
128
+ <Tooltip id={INSTRUMENT_TOOLTIP_ID} />
129
+ {!error && (
130
+ <div className="lw-mt-2 lw-h-8">
131
+ <LastUpdated labelCallback={lang} timestamp={updatedTimestamp} />
108
132
  </div>
109
- </>
110
- )}
111
- <Tooltip id={INSTRUMENT_TOOLTIP_ID} />
112
- {!error
113
- && (
114
- <div className="lw-mt-2 lw-h-8">
115
- <LastUpdated timestamp={updatedTimestamp} labelCallback={lang} />
133
+ )}
116
134
  </div>
117
- )}
118
- </div>
119
135
  )}
120
136
  </>
121
137
  );
@@ -1,22 +1,26 @@
1
- import React from 'react';
2
- import classNames from 'classnames';
1
+ import { useQuery } from '@apollo/client';
3
2
  import {
4
- Sentiment,
5
- SentimentHeight,
6
3
  Error,
4
+ LastUpdated,
7
5
  Loader,
8
6
  LoaderSize,
7
+ Sentiment,
8
+ SentimentHeight,
9
+ Size,
9
10
  Truncate,
10
11
  useLayoutProvider,
11
- Size,
12
- LastUpdated,
13
12
  } from '@oanda/labs-widget-common';
14
13
  import { useLocale } from '@oanda/mono-i18n';
15
- import { useQuery } from '@apollo/client';
16
- import { getInstrumentSentiment } from '../gql/getInstrumentSentiment';
17
- import { SentimentWidgetConfig } from './types';
18
- import { GetInstrumentSentimentQuery, GetInstrumentSentimentQueryVariables } from '../gql/types/graphql';
14
+ import classNames from 'classnames';
15
+ import React from 'react';
16
+
19
17
  import { INSTRUMENT_TOOLTIP_ID } from '../constant';
18
+ import { getInstrumentSentiment } from '../gql/getInstrumentSentiment';
19
+ import type {
20
+ GetInstrumentSentimentQuery,
21
+ GetInstrumentSentimentQueryVariables,
22
+ } from '../gql/types/graphql';
23
+ import type { SentimentWidgetConfig } from './types';
20
24
 
21
25
  const Widget = ({
22
26
  instrument,
@@ -24,8 +28,8 @@ const Widget = ({
24
28
  includeDescriptionLabels = false,
25
29
  }: SentimentWidgetConfig) => {
26
30
  const { loading, data, error } = useQuery<
27
- GetInstrumentSentimentQuery,
28
- GetInstrumentSentimentQueryVariables
31
+ GetInstrumentSentimentQuery,
32
+ GetInstrumentSentimentQueryVariables
29
33
  >(getInstrumentSentiment, {
30
34
  variables: {
31
35
  name: instrument,
@@ -39,65 +43,67 @@ const Widget = ({
39
43
 
40
44
  const { displayName, sentiment, updatedAt } = data?.sentiment?.[0] || {};
41
45
 
42
- const isError = error
43
- || (sentiment?.shortPercent === 0 && sentiment?.longPercent === 0)
44
- || sentiment?.shortPercent === undefined
45
- || sentiment?.longPercent === undefined;
46
+ const isError =
47
+ error ||
48
+ (sentiment?.shortPercent === 0 && sentiment?.longPercent === 0) ||
49
+ sentiment?.shortPercent === undefined ||
50
+ sentiment?.longPercent === undefined;
46
51
 
47
52
  return (
48
53
  <>
49
54
  {size && (
50
- <>
51
- <div
52
- data-testid="sentiment-widget"
53
- className="lw-border lw-border-solid lw-border-border-primary lw-bg-bg-primary lw-p-4 lw-text-sm lw-tracking-normal lw-text-text-primary"
54
- >
55
- {includeDescriptionLabels && !isError
56
- && (
57
- <div className="lw-mb-2 lw-flex lw-justify-between lw-font-semibold">
58
- <span className={classNames('lw-uppercase', {
59
- 'lw-ml-40': isDesktop,
60
- 'lw-ml-[7.5rem]': !isDesktop,
61
- })}
62
- >
63
- {lang('net_short')}
64
- </span>
65
- <span className={classNames('lw-text-right lw-uppercase', {
66
- 'lw-mr-10': isDesktop,
67
- })}
68
- >
69
- {lang('net_long')}
70
- </span>
71
- </div>
72
- )}
73
- <div className="lw-flex lw-items-center lw-justify-between">
74
- <div className="lw-w-[120px] lw-shrink-0">
75
- {loading && <Loader size={LoaderSize.md} />}
76
- {!loading && !isError && (
77
- <Truncate
78
- maxWidth={120}
79
- tooltipId={INSTRUMENT_TOOLTIP_ID}
80
- className="lw-pr-2 lw-font-sans lw-text-sm lw-font-bold"
81
- text={displayName || '\u2014'}
55
+ <>
56
+ <div
57
+ className="lw-border lw-border-solid lw-border-border-primary lw-bg-bg-primary lw-p-4 lw-text-sm lw-tracking-normal lw-text-text-primary"
58
+ data-testid="sentiment-widget"
59
+ >
60
+ {includeDescriptionLabels && !isError && (
61
+ <div className="lw-mb-2 lw-flex lw-justify-between lw-font-semibold">
62
+ <span
63
+ className={classNames('lw-uppercase', {
64
+ 'lw-ml-40': isDesktop,
65
+ 'lw-ml-[7.5rem]': !isDesktop,
66
+ })}
67
+ >
68
+ {lang('net_short')}
69
+ </span>
70
+ <span
71
+ className={classNames('lw-text-right lw-uppercase', {
72
+ 'lw-mr-10': isDesktop,
73
+ })}
74
+ >
75
+ {lang('net_long')}
76
+ </span>
77
+ </div>
78
+ )}
79
+ <div className="lw-flex lw-items-center lw-justify-between">
80
+ <div className="lw-w-[120px] lw-shrink-0">
81
+ {loading && <Loader size={LoaderSize.md} />}
82
+ {!loading && !isError && (
83
+ <Truncate
84
+ className="lw-pr-2 lw-font-sans lw-text-sm lw-font-bold"
85
+ maxWidth={120}
86
+ text={displayName || '\u2014'}
87
+ tooltipId={INSTRUMENT_TOOLTIP_ID}
88
+ />
89
+ )}
90
+ </div>
91
+ <Sentiment
92
+ height={SentimentHeight.md}
93
+ isLoading={loading}
94
+ sentiment={sentiment}
95
+ withError={false}
82
96
  />
83
- )}
84
97
  </div>
85
- <Sentiment
86
- withError={false}
87
- isLoading={loading}
88
- height={SentimentHeight.md}
89
- sentiment={sentiment}
90
- />
91
- </div>
92
98
 
93
- {!loading && isError && <Error />}
94
- </div>
95
- {!isError && updatedAt && (
96
- <div className="lw-mt-2 lw-h-8">
97
- <LastUpdated timestamp={updatedAt} labelCallback={lang} />
98
- </div>
99
- )}
100
- </>
99
+ {!loading && isError && <Error />}
100
+ </div>
101
+ {!isError && updatedAt && (
102
+ <div className="lw-mt-2 lw-h-8">
103
+ <LastUpdated labelCallback={lang} timestamp={updatedAt} />
104
+ </div>
105
+ )}
106
+ </>
101
107
  )}
102
108
  </>
103
109
  );