Skip to content

Commit b82fec5

Browse files
Merge pull request #1934 from carbon-design-system/feat-hotspot-exposedemohotspots
feat(hotspot): need to expose the onFetchDynamicDemoHotspots method to the DashboardEditor
2 parents 2a592fc + 08f2276 commit b82fec5

6 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/components/CardEditor/CardEditForm/CardEditForm.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ const CardEditForm = ({
191191
currentBreakpoint,
192192
availableDimensions,
193193
testID,
194+
// eslint-disable-next-line react/prop-types
195+
onFetchDynamicDemoHotspots,
194196
}) => {
195197
const mergedI18n = { ...defaultProps.i18n, ...i18n };
196198
const [showEditor, setShowEditor] = useState(false);
@@ -242,6 +244,7 @@ const CardEditForm = ({
242244
getValidDataItems={getValidDataItems}
243245
getValidTimeRanges={getValidTimeRanges}
244246
currentBreakpoint={currentBreakpoint}
247+
onFetchDynamicDemoHotspots={onFetchDynamicDemoHotspots}
245248
/>
246249
</Tab>
247250
<Tab label={mergedI18n.settingsTabLabel}>

src/components/CardEditor/CardEditForm/CardEditFormContent.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ const CardEditFormContent = ({
9999
getValidTimeRanges,
100100
currentBreakpoint,
101101
availableDimensions,
102+
// eslint-disable-next-line react/prop-types
103+
onFetchDynamicDemoHotspots,
102104
}) => {
103105
const { type, timeRange } = cardConfig;
104106
const mergedI18n = { ...defaultProps.i18n, ...i18n };
@@ -142,6 +144,7 @@ const CardEditFormContent = ({
142144
dataItems={dataItems}
143145
availableDimensions={availableDimensions}
144146
translateWithId={handleTranslation}
147+
onFetchDynamicDemoHotspots={onFetchDynamicDemoHotspots}
145148
/>
146149
) : type === CARD_TYPES.TABLE ? (
147150
<TableCardFormContent

src/components/CardEditor/CardEditForm/CardEditFormItems/ImageCardFormItems/ImageCardFormContent.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ const propTypes = {
3939
* ex: { manufacturer: ['Rentech', 'GHI Industries'], deviceid: ['73000', '73001', '73002'] }
4040
*/
4141
availableDimensions: PropTypes.shape({}),
42+
/** call back to retrieve the dynamic demo hotspots, by default just returns one example dynamic hotspot, override to return true hotspots.
43+
* See HotspotEditorModal propTypes for params and details */
44+
onFetchDynamicDemoHotspots: PropTypes.func,
4245
};
4346

4447
const defaultProps = {
@@ -51,6 +54,7 @@ const defaultProps = {
5154
},
5255
dataItems: [],
5356
availableDimensions: {},
57+
onFetchDynamicDemoHotspots: () => Promise.resolve([{ x: 50, y: 50 }]),
5458
};
5559

5660
const ImageCardFormItems = ({
@@ -60,6 +64,7 @@ const ImageCardFormItems = ({
6064
dataItems,
6165
availableDimensions,
6266
translateWithId,
67+
onFetchDynamicDemoHotspots,
6368
}) => {
6469
const [isHotspotModalShowing, setIsHotspotModalShowing] = useState(false);
6570
const mergedI18n = { ...defaultProps.i18n, ...i18n };
@@ -94,8 +99,7 @@ const ImageCardFormItems = ({
9499
onClose={handleCloseHotspotEditor}
95100
translateWithId={translateWithId}
96101
i18n={mergedI18n}
97-
// TODO go get the hotspots from the real data layer
98-
onFetchDynamicHotspots={() => Promise.resolve([{ x: 10, y: 10 }])}
102+
onFetchDynamicDemoHotspots={onFetchDynamicDemoHotspots}
99103
/>
100104
) : null}
101105
<div

src/components/CardEditor/CardEditor.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ const CardEditor = ({
145145
i18n,
146146
currentBreakpoint,
147147
testID,
148+
// eslint-disable-next-line react/prop-types
149+
onFetchDynamicDemoHotspots,
148150
}) => {
149151
const mergedI18n = { ...defaultProps.i18n, ...i18n };
150152

@@ -191,6 +193,7 @@ const CardEditor = ({
191193
availableDimensions={availableDimensions}
192194
i18n={mergedI18n}
193195
currentBreakpoint={currentBreakpoint}
196+
onFetchDynamicDemoHotspots={onFetchDynamicDemoHotspots}
194197
/>
195198
)}
196199
</div>

src/components/DashboardEditor/DashboardEditor.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ const DashboardEditor = ({
340340
availableDimensions,
341341
isLoading,
342342
i18n,
343+
// eslint-disable-next-line react/prop-types
344+
onFetchDynamicDemoHotspots, // needed for the hotspoteditormodal, see the proptypes for more details
343345
}) => {
344346
const mergedI18n = useMemo(() => ({ ...defaultProps.i18n, ...i18n }), [i18n]);
345347
// Need to keep track of whether the image gallery is open or not
@@ -696,6 +698,7 @@ const DashboardEditor = ({
696698
availableDimensions={availableDimensions}
697699
i18n={mergedI18n}
698700
currentBreakpoint={currentBreakpoint}
701+
onFetchDynamicDemoHotspots={onFetchDynamicDemoHotspots}
699702
/>
700703
</ErrorBoundary>
701704
</div>

src/components/HotspotEditorModal/HotspotEditorModal.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,13 @@ const propTypes = {
136136
/** Callback for modal cancel button and close icon button */
137137
onClose: PropTypes.func.isRequired,
138138
/**
139-
* Callback to fetch dynamic hotstpots. Returns a Propmise that resolves to an array of demo hotspots
140-
* matching the x & y source in param {maxHotspots, xSource, ySource }.
139+
* Callback to fetch dynamic hotstpots. Should returns a Promise that resolves to an array of demo hotspots
140+
* matching the x & y source. Called with one param, an object with 3 values
141+
* {
142+
* maxHotspots: maximum number to return,
143+
* xSource: the name of the data item to use as the xSource,
144+
* ySource: the name of the data item to use as the ySource
145+
* }.
141146
* */
142147
onFetchDynamicDemoHotspots: PropTypes.func,
143148
/** Callback for modal save button returns the entire updated card config */

0 commit comments

Comments
 (0)