-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
Changes from 6 commits
04b9511
53e48eb
d8a46d7
2c929c2
a74c4cf
9a62025
85b5f4b
75de383
ef9db61
38eef0b
52ab6df
7f1f367
85aace1
4a5f9cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
EuiFlexGrid, | ||
EuiFlexItem, | ||
} from '@elastic/eui'; | ||
|
||
import { SampleDataSetCard } from './sample_data_set_card'; | ||
|
||
import { | ||
listSampleDataSets, | ||
installSampleDataSet, | ||
uninstallSampleDataSet | ||
} from '../sample_data_sets'; | ||
|
||
export class SampleDataSetCards extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
sampleDataSets: [], | ||
}; | ||
} | ||
|
||
componentWillUnmount() { | ||
this._isMounted = false; | ||
} | ||
|
||
async componentDidMount() { | ||
this._isMounted = true; | ||
|
||
this.loadSampleDataSets(); | ||
} | ||
|
||
loadSampleDataSets = async () => { | ||
const sampleDataSets = await listSampleDataSets(); | ||
|
||
if (!this._isMounted) { | ||
return; | ||
} | ||
|
||
this.setState({ | ||
sampleDataSets: sampleDataSets | ||
.map((sampleDataSet) => { | ||
sampleDataSet.isProcessing = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this is modifying the returned object. When we have typescript, the structure of |
||
return sampleDataSet; | ||
}) | ||
.sort((a, b) => { | ||
return a.name.toLowerCase().localeCompare(b.name.toLowerCase()); | ||
}), | ||
}); | ||
} | ||
|
||
install = async (id) => { | ||
const { | ||
getConfig, | ||
setConfig, | ||
clearIndexPatternsCache, | ||
} = this.props; | ||
|
||
const targetSampleDataSet = this.state.sampleDataSets.find((sampleDataSet) => { | ||
return sampleDataSet.id === id; | ||
}); | ||
targetSampleDataSet.isProcessing = true; | ||
|
||
this.setState({ | ||
sampleDataSets: this.state.sampleDataSets.map((sampleDataSet) => { | ||
if (sampleDataSet.id === id) { | ||
return targetSampleDataSet; | ||
} | ||
return sampleDataSet; | ||
}), | ||
}); | ||
|
||
await installSampleDataSet(id, targetSampleDataSet.name, targetSampleDataSet.defaultIndex, | ||
getConfig, setConfig, clearIndexPatternsCache); | ||
if (!this._isMounted) { | ||
return; | ||
} | ||
|
||
this.loadSampleDataSets(); | ||
} | ||
|
||
uninstall = async (id) => { | ||
const { | ||
getConfig, | ||
setConfig, | ||
clearIndexPatternsCache, | ||
} = this.props; | ||
|
||
const targetSampleDataSet = this.state.sampleDataSets.find((sampleDataSet) => { | ||
return sampleDataSet.id === id; | ||
}); | ||
targetSampleDataSet.isProcessing = true; | ||
|
||
this.setState({ | ||
sampleDataSets: this.state.sampleDataSets.map((sampleDataSet) => { | ||
if (sampleDataSet.id === id) { | ||
return targetSampleDataSet; | ||
} | ||
return sampleDataSet; | ||
}), | ||
}); | ||
|
||
await uninstallSampleDataSet(id, targetSampleDataSet.name, targetSampleDataSet.defaultIndex, | ||
getConfig, setConfig, clearIndexPatternsCache); | ||
if (!this._isMounted) { | ||
return; | ||
} | ||
|
||
this.loadSampleDataSets(); | ||
} | ||
|
||
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={sampleDataSet.isProcessing} | ||
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, | ||
}; |
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.
I guess these are returned from the objects in
listSampleDataSets
? Our folder structure of core plugins makes it difficult to push common consts in an intuitive place (the server side code of this is far away). If we typescripted this and the files in../sample_data_sets
we could at least show that the object being returned has astatus
and is one ofinstalled
ornot_installed
. Suppose that's fine for this PR but I think it'd be really helpful to understand and follow this code if it was in typescript.