-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Sample Data Home section which also fixes flaky sample data functional test #21655
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
04b9511
add retry to sample data unstall test
nreese 53e48eb
fix flaky sample data test
nreese d8a46d7
remove retry around expect
nreese 2c929c2
simplify solution
nreese a74c4cf
remove onRequestComplete and just track status in state
nreese 9a62025
move all state into new SampleDataSetCards
nreese 85b5f4b
Merge branch 'master' of https://github.com/elastic/kibana into issue…
nreese 75de383
track processing status in seperate object than sampleDataSets
nreese ef9db61
Merge branch 'master' of https://github.com/elastic/kibana into issue…
nreese 38eef0b
display toast notifications from SampleDataSetCards component
nreese 52ab6df
Merge branch 'master' of https://github.com/elastic/kibana into issue…
nreese 7f1f367
remove checks for toast notifications, just causing flakyness
nreese 85aace1
only load sample data set status on initial component load
nreese 4a5f9cc
set processing to false when there is an install failure
nreese File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
src/core_plugins/kibana/public/home/components/sample_data_set_cards.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import _ from 'lodash'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
EuiFlexGrid, | ||
EuiFlexItem, | ||
} from '@elastic/eui'; | ||
|
||
import { | ||
SampleDataSetCard, | ||
INSTALLED_STATUS, | ||
UNINSTALLED_STATUS, | ||
} from './sample_data_set_card'; | ||
|
||
import { toastNotifications } from 'ui/notify'; | ||
|
||
import { | ||
listSampleDataSets, | ||
installSampleDataSet, | ||
uninstallSampleDataSet | ||
} from '../sample_data_sets'; | ||
|
||
export class SampleDataSetCards extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
sampleDataSets: [], | ||
processingStatus: {}, | ||
}; | ||
} | ||
|
||
componentWillUnmount() { | ||
this._isMounted = false; | ||
} | ||
|
||
async componentDidMount() { | ||
this._isMounted = true; | ||
|
||
this.loadSampleDataSets(); | ||
} | ||
|
||
loadSampleDataSets = async () => { | ||
let sampleDataSets; | ||
try { | ||
sampleDataSets = await listSampleDataSets(); | ||
} catch (fetchError) { | ||
toastNotifications.addDanger({ | ||
title: `Unable to load sample data sets list`, | ||
text: `${fetchError.message}`, | ||
}); | ||
sampleDataSets = []; | ||
} | ||
|
||
if (!this._isMounted) { | ||
return; | ||
} | ||
|
||
this.setState({ | ||
sampleDataSets: sampleDataSets | ||
.sort((a, b) => { | ||
return a.name.toLowerCase().localeCompare(b.name.toLowerCase()); | ||
}), | ||
processingStatus: {}, | ||
}); | ||
} | ||
|
||
install = async (id) => { | ||
const { | ||
getConfig, | ||
setConfig, | ||
clearIndexPatternsCache, | ||
} = this.props; | ||
|
||
const targetSampleDataSet = this.state.sampleDataSets.find((sampleDataSet) => { | ||
return sampleDataSet.id === id; | ||
}); | ||
|
||
this.setState((prevState) => ({ | ||
processingStatus: { ...prevState.processingStatus, [id]: true } | ||
})); | ||
|
||
try { | ||
await installSampleDataSet(id, targetSampleDataSet.defaultIndex, getConfig, setConfig, clearIndexPatternsCache); | ||
} catch (fetchError) { | ||
if (this._isMounted) { | ||
this.setState((prevState) => ({ | ||
processingStatus: { ...prevState.processingStatus, [id]: true } | ||
})); | ||
} | ||
toastNotifications.addDanger({ | ||
title: `Unable to install sample data set: ${targetSampleDataSet.name}`, | ||
text: `${fetchError.message}`, | ||
}); | ||
return; | ||
} | ||
|
||
this.setState((prevState) => ({ | ||
processingStatus: { ...prevState.processingStatus, [id]: false }, | ||
sampleDataSets: prevState.sampleDataSets.map(sampleDataSet => { | ||
if (sampleDataSet.id === id) { | ||
sampleDataSet.status = INSTALLED_STATUS; | ||
} | ||
return sampleDataSet; | ||
}), | ||
})); | ||
toastNotifications.addSuccess({ | ||
title: `${targetSampleDataSet.name} installed`, | ||
['data-test-subj']: 'sampleDataSetInstallToast' | ||
}); | ||
} | ||
|
||
uninstall = async (id) => { | ||
const { | ||
getConfig, | ||
setConfig, | ||
clearIndexPatternsCache, | ||
} = this.props; | ||
|
||
const targetSampleDataSet = this.state.sampleDataSets.find((sampleDataSet) => { | ||
return sampleDataSet.id === id; | ||
}); | ||
|
||
this.setState((prevState) => ({ | ||
processingStatus: { ...prevState.processingStatus, [id]: true } | ||
})); | ||
|
||
try { | ||
await uninstallSampleDataSet(id, targetSampleDataSet.defaultIndex, getConfig, setConfig, clearIndexPatternsCache); | ||
} catch (fetchError) { | ||
if (this._isMounted) { | ||
this.setState((prevState) => ({ | ||
processingStatus: { ...prevState.processingStatus, [id]: false } | ||
})); | ||
} | ||
toastNotifications.addDanger({ | ||
title: `Unable to uninstall sample data set: ${targetSampleDataSet.name}`, | ||
text: `${fetchError.message}`, | ||
}); | ||
return; | ||
} | ||
|
||
this.setState((prevState) => ({ | ||
processingStatus: { ...prevState.processingStatus, [id]: false }, | ||
sampleDataSets: prevState.sampleDataSets.map(sampleDataSet => { | ||
if (sampleDataSet.id === id) { | ||
sampleDataSet.status = UNINSTALLED_STATUS; | ||
} | ||
return sampleDataSet; | ||
}), | ||
})); | ||
toastNotifications.addSuccess({ | ||
title: `${targetSampleDataSet.name} uninstalled`, | ||
['data-test-subj']: 'sampleDataSetUninstallToast' | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<EuiFlexGrid columns={4}> | ||
{ | ||
this.state.sampleDataSets.map(sampleDataSet => { | ||
return ( | ||
<EuiFlexItem key={sampleDataSet.id}> | ||
<SampleDataSetCard | ||
id={sampleDataSet.id} | ||
description={sampleDataSet.description} | ||
name={sampleDataSet.name} | ||
launchUrl={this.props.addBasePath(`/app/kibana#/dashboard/${sampleDataSet.overviewDashboard}`)} | ||
status={sampleDataSet.status} | ||
isProcessing={_.get(this.state.processingStatus, sampleDataSet.id, false)} | ||
statusMsg={sampleDataSet.statusMsg} | ||
previewUrl={this.props.addBasePath(sampleDataSet.previewImagePath)} | ||
onInstall={this.install} | ||
onUninstall={this.uninstall} | ||
/> | ||
</EuiFlexItem> | ||
); | ||
}) | ||
} | ||
</EuiFlexGrid> | ||
); | ||
} | ||
} | ||
|
||
SampleDataSetCards.propTypes = { | ||
getConfig: PropTypes.func.isRequired, | ||
setConfig: PropTypes.func.isRequired, | ||
clearIndexPatternsCache: PropTypes.func.isRequired, | ||
addBasePath: PropTypes.func.isRequired, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be
[id]: false
?