|
Packit Service |
eebd6f |
import React from "react";
|
|
Packit Service |
eebd6f |
import { FormattedMessage, defineMessages, injectIntl, intlShape } from "react-intl";
|
|
Packit Service |
eebd6f |
import PropTypes from "prop-types";
|
|
Packit Service |
eebd6f |
import { connect } from "react-redux";
|
|
Packit Service |
eebd6f |
import { Button, EmptyStatePrimary } from "@patternfly/react-core";
|
|
Packit Service |
eebd6f |
import { ExclamationCircleIcon } from "@patternfly/react-icons";
|
|
Packit Service |
eebd6f |
import Layout from "../../components/Layout/Layout";
|
|
Packit Service |
eebd6f |
import BlueprintsDataList from "../../components/ListView/BlueprintsDataList";
|
|
Packit Service |
eebd6f |
import CreateBlueprint from "../../components/Modal/CreateBlueprint";
|
|
Packit Service |
eebd6f |
import EmptyState from "../../components/EmptyState/EmptyState";
|
|
Packit Service |
eebd6f |
import EmptyStateInactive from "../../components/EmptyState/EmptyStateInactive";
|
|
Packit Service |
eebd6f |
import Loading from "../../components/Loading/Loading";
|
|
Packit Service |
eebd6f |
import BlueprintsToolbar from "../../components/Toolbar/BlueprintsToolbar";
|
|
Packit Service |
eebd6f |
import { fetchingBlueprints } from "../../core/actions/blueprints";
|
|
Packit Service |
eebd6f |
import { fetchingModalManageSourcesContents } from "../../core/actions/modals";
|
|
Packit Service |
eebd6f |
import { blueprintsSortSetKey, blueprintsSortSetValue } from "../../core/actions/sort";
|
|
Packit Service |
eebd6f |
import {
|
|
Packit Service |
eebd6f |
blueprintsFilterAddValue,
|
|
Packit Service |
eebd6f |
blueprintsFilterRemoveValue,
|
|
Packit Service |
eebd6f |
blueprintsFilterClearValues,
|
|
Packit Service |
eebd6f |
} from "../../core/actions/filter";
|
|
Packit Service |
eebd6f |
import { makeGetSortedBlueprints, makeGetFilteredBlueprints } from "../../core/selectors";
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
const messages = defineMessages({
|
|
Packit Service |
eebd6f |
blueprintsTitle: {
|
|
Packit Service |
eebd6f |
defaultMessage: "Blueprints",
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
emptyMessage: {
|
|
Packit Service |
eebd6f |
defaultMessage:
|
|
Packit Service |
eebd6f |
"Create a blueprint to define the contents that will be included in the images you create. " +
|
|
Packit Service |
eebd6f |
"Images can be produced in a variety of output formats.",
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
emptyTitle: {
|
|
Packit Service |
eebd6f |
defaultMessage: "No Blueprints",
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
errorGenericTitle: {
|
|
Packit Service |
eebd6f |
defaultMessage: "An Error Occurred",
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
noResultsMessage: {
|
|
Packit Service |
eebd6f |
defaultMessage: "Modify your filter criteria to get results.",
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
noResultsTitle: {
|
|
Packit Service |
eebd6f |
defaultMessage: "No Results Match the Filter Criteria",
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
});
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
class BlueprintsPage extends React.Component {
|
|
Packit Service |
eebd6f |
constructor(props) {
|
|
Packit Service |
eebd6f |
super(props);
|
|
Packit Service |
eebd6f |
this.setNotifications = this.setNotifications.bind(this);
|
|
Packit Service |
eebd6f |
}
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
componentDidMount() {
|
|
Packit Service |
eebd6f |
const { formatMessage } = this.props.intl;
|
|
Packit Service |
eebd6f |
document.title = formatMessage(messages.blueprintsTitle);
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
if (this.props.blueprintsLoading === true) {
|
|
Packit Service |
eebd6f |
this.props.fetchingBlueprints();
|
|
Packit Service |
eebd6f |
this.props.fetchingModalManageSourcesContents();
|
|
Packit Service |
eebd6f |
}
|
|
Packit Service |
eebd6f |
}
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
setNotifications() {
|
|
Packit Service |
eebd6f |
this.layout.setNotifications();
|
|
Packit Service |
eebd6f |
}
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
render() {
|
|
Packit Service |
eebd6f |
const {
|
|
Packit Service |
eebd6f |
blueprints,
|
|
Packit Service |
eebd6f |
manageSources,
|
|
Packit Service |
eebd6f |
blueprintSortKey,
|
|
Packit Service |
eebd6f |
blueprintSortValue,
|
|
Packit Service |
eebd6f |
blueprintsSortSetValue,
|
|
Packit Service |
eebd6f |
blueprintFilters,
|
|
Packit Service |
eebd6f |
blueprintsFilterAddValue,
|
|
Packit Service |
eebd6f |
blueprintsFilterRemoveValue,
|
|
Packit Service |
eebd6f |
blueprintsFilterClearValues,
|
|
Packit Service |
eebd6f |
blueprintsError,
|
|
Packit Service |
eebd6f |
blueprintsLoading,
|
|
Packit Service |
eebd6f |
} = this.props;
|
|
Packit Service |
eebd6f |
const { formatMessage } = this.props.intl;
|
|
Packit Service |
eebd6f |
return (
|
|
Packit Service |
eebd6f |
<Layout className="container-fluid" ref={(c) => (this.layout = c)}>
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
blueprintNames={blueprints.map((blueprint) => blueprint.present.id)}
|
|
Packit Service |
eebd6f |
emptyState={blueprints.length === 0 && blueprintFilters.filterValues.length === 0}
|
|
Packit Service |
eebd6f |
errorState={blueprintsError !== null}
|
|
Packit Service |
eebd6f |
filters={blueprintFilters}
|
|
Packit Service |
eebd6f |
filterRemoveValue={blueprintsFilterRemoveValue}
|
|
Packit Service |
eebd6f |
filterClearValues={blueprintsFilterClearValues}
|
|
Packit Service |
eebd6f |
filterAddValue={blueprintsFilterAddValue}
|
|
Packit Service |
eebd6f |
sortKey={blueprintSortKey}
|
|
Packit Service |
eebd6f |
sortValue={blueprintSortValue}
|
|
Packit Service |
eebd6f |
sortSetValue={blueprintsSortSetValue}
|
|
Packit Service |
eebd6f |
manageSources={manageSources}
|
|
Packit Service |
eebd6f |
/>
|
|
Packit Service |
eebd6f |
{(blueprintsLoading === true && <Loading />) ||
|
|
Packit Service |
0c2606 |
(blueprintsError === undefined && (
|
|
Packit Service |
0c2606 |
<EmptyStateInactive fetchingBlueprints={this.props.fetchingBlueprints} />
|
|
Packit Service |
0c2606 |
)) ||
|
|
Packit Service |
eebd6f |
(blueprintsError !== null &&
|
|
Packit Service |
0c2606 |
(((blueprintsError.problem === "access-denied" || blueprintsError.message === "not-found") && (
|
|
Packit Service |
eebd6f |
<EmptyStateInactive fetchingBlueprints={this.props.fetchingBlueprints} />
|
|
Packit Service |
eebd6f |
)) || (
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
title={formatMessage(messages.errorGenericTitle)}
|
|
Packit Service |
eebd6f |
icon={ExclamationCircleIcon}
|
|
Packit Service |
eebd6f |
message={blueprintsError.message}
|
|
Packit Service |
eebd6f |
/>
|
|
Packit Service |
eebd6f |
))) ||
|
|
Packit Service |
eebd6f |
(blueprints.length > 0 && (
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
blueprints={blueprints.map((blueprint) => blueprint.present)}
|
|
Packit Service |
eebd6f |
setNotifications={this.setNotifications}
|
|
Packit Service |
eebd6f |
layout={this.layout}
|
|
Packit Service |
eebd6f |
ariaLabel={formatMessage(messages.blueprintsTitle)}
|
|
Packit Service |
eebd6f |
/>
|
|
Packit Service |
eebd6f |
)) ||
|
|
Packit Service |
eebd6f |
(blueprintFilters.filterValues.length === 0 && (
|
|
Packit Service |
eebd6f |
<EmptyState title={formatMessage(messages.emptyTitle)} message={formatMessage(messages.emptyMessage)}>
|
|
Packit Service |
eebd6f |
<EmptyStatePrimary>
|
|
Packit Service |
eebd6f |
<CreateBlueprint blueprintNames={blueprints.map((blueprint) => blueprint.present.id)} />
|
|
Packit Service |
eebd6f |
</EmptyStatePrimary>
|
|
Packit Service |
eebd6f |
</EmptyState>
|
|
Packit Service |
eebd6f |
)) || (
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
title={formatMessage(messages.noResultsTitle)}
|
|
Packit Service |
eebd6f |
message={formatMessage(messages.noResultsMessage)}
|
|
Packit Service |
eebd6f |
>
|
|
Packit Service |
eebd6f |
<EmptyStatePrimary>
|
|
Packit Service |
eebd6f |
<Button variant="link" type="button" onClick={blueprintsFilterClearValues}>
|
|
Packit Service |
eebd6f |
<FormattedMessage defaultMessage="Clear All Filters" />
|
|
Packit Service |
eebd6f |
</Button>
|
|
Packit Service |
eebd6f |
</EmptyStatePrimary>
|
|
Packit Service |
eebd6f |
</EmptyState>
|
|
Packit Service |
eebd6f |
)}
|
|
Packit Service |
eebd6f |
</Layout>
|
|
Packit Service |
eebd6f |
);
|
|
Packit Service |
eebd6f |
}
|
|
Packit Service |
eebd6f |
}
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
BlueprintsPage.propTypes = {
|
|
Packit Service |
eebd6f |
fetchingModalManageSourcesContents: PropTypes.func,
|
|
Packit Service |
eebd6f |
fetchingBlueprints: PropTypes.func,
|
|
Packit Service |
eebd6f |
blueprints: PropTypes.arrayOf(PropTypes.object),
|
|
Packit Service |
eebd6f |
manageSources: PropTypes.shape({
|
|
Packit Service |
eebd6f |
fetchingSources: PropTypes.bool,
|
|
Packit Service |
eebd6f |
sources: PropTypes.objectOf(PropTypes.object),
|
|
Packit Service |
eebd6f |
error: PropTypes.object,
|
|
Packit Service |
eebd6f |
}),
|
|
Packit Service |
eebd6f |
blueprintSortKey: PropTypes.string,
|
|
Packit Service |
eebd6f |
blueprintSortValue: PropTypes.string,
|
|
Packit Service |
eebd6f |
blueprintFilters: PropTypes.shape({
|
|
Packit Service |
eebd6f |
defaultFilterType: PropTypes.string,
|
|
Packit Service |
eebd6f |
filterTypes: PropTypes.arrayOf(PropTypes.object),
|
|
Packit Service |
eebd6f |
filterValues: PropTypes.arrayOf(PropTypes.object),
|
|
Packit Service |
eebd6f |
}),
|
|
Packit Service |
eebd6f |
blueprintsSortSetValue: PropTypes.func,
|
|
Packit Service |
eebd6f |
blueprintsFilterAddValue: PropTypes.func,
|
|
Packit Service |
eebd6f |
blueprintsFilterRemoveValue: PropTypes.func,
|
|
Packit Service |
eebd6f |
blueprintsFilterClearValues: PropTypes.func,
|
|
Packit Service |
eebd6f |
blueprintsError: PropTypes.shape({
|
|
Packit Service |
eebd6f |
message: PropTypes.string,
|
|
Packit Service |
eebd6f |
options: PropTypes.object,
|
|
Packit Service |
eebd6f |
problem: PropTypes.string,
|
|
Packit Service |
eebd6f |
url: PropTypes.string,
|
|
Packit Service |
eebd6f |
}),
|
|
Packit Service |
eebd6f |
blueprintsLoading: PropTypes.bool,
|
|
Packit Service |
eebd6f |
intl: intlShape.isRequired,
|
|
Packit Service |
eebd6f |
};
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
BlueprintsPage.defaultProps = {
|
|
Packit Service |
eebd6f |
fetchingModalManageSourcesContents() {},
|
|
Packit Service |
eebd6f |
fetchingBlueprints() {},
|
|
Packit Service |
eebd6f |
blueprints: [],
|
|
Packit Service |
eebd6f |
manageSources: {},
|
|
Packit Service |
eebd6f |
blueprintSortKey: "",
|
|
Packit Service |
eebd6f |
blueprintSortValue: "",
|
|
Packit Service |
eebd6f |
blueprintFilters: {},
|
|
Packit Service |
eebd6f |
blueprintsSortSetValue() {},
|
|
Packit Service |
eebd6f |
blueprintsFilterAddValue() {},
|
|
Packit Service |
eebd6f |
blueprintsFilterRemoveValue() {},
|
|
Packit Service |
eebd6f |
blueprintsFilterClearValues() {},
|
|
Packit Service |
eebd6f |
blueprintsError: {},
|
|
Packit Service |
eebd6f |
blueprintsLoading: false,
|
|
Packit Service |
eebd6f |
};
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
const makeMapStateToProps = () => {
|
|
Packit Service |
eebd6f |
const getSortedBlueprints = makeGetSortedBlueprints();
|
|
Packit Service |
eebd6f |
const getFilteredBlueprints = makeGetFilteredBlueprints();
|
|
Packit Service |
eebd6f |
const mapStateToProps = (state) => {
|
|
Packit Service |
eebd6f |
if (getSortedBlueprints(state) !== undefined) {
|
|
Packit Service |
eebd6f |
return {
|
|
Packit Service |
eebd6f |
manageSources: state.modals.manageSources,
|
|
Packit Service |
eebd6f |
blueprints: getFilteredBlueprints(state, getSortedBlueprints(state)),
|
|
Packit Service |
eebd6f |
blueprintSortKey: state.sort.blueprints.key,
|
|
Packit Service |
eebd6f |
blueprintSortValue: state.sort.blueprints.value,
|
|
Packit Service |
eebd6f |
blueprintFilters: state.filter.blueprints,
|
|
Packit Service |
eebd6f |
blueprintsError: state.blueprints.errorState,
|
|
Packit Service |
eebd6f |
blueprintsLoading: state.blueprints.fetchingBlueprints,
|
|
Packit Service |
eebd6f |
};
|
|
Packit Service |
eebd6f |
}
|
|
Packit Service |
eebd6f |
return {
|
|
Packit Service |
eebd6f |
manageSources: state.modals.manageSources,
|
|
Packit Service |
eebd6f |
blueprints: state.blueprints.blueprintList,
|
|
Packit Service |
eebd6f |
blueprintSortKey: state.sort.blueprints.key,
|
|
Packit Service |
eebd6f |
blueprintSortValue: state.sort.blueprints.value,
|
|
Packit Service |
eebd6f |
blueprintFilters: state.filter.blueprints,
|
|
Packit Service |
eebd6f |
blueprintsError: state.blueprints.errorState,
|
|
Packit Service |
eebd6f |
blueprintsLoading: state.blueprints.fetchingBlueprints,
|
|
Packit Service |
eebd6f |
};
|
|
Packit Service |
eebd6f |
};
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
return mapStateToProps;
|
|
Packit Service |
eebd6f |
};
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
const mapDispatchToProps = (dispatch) => ({
|
|
Packit Service |
eebd6f |
fetchingBlueprints: () => {
|
|
Packit Service |
eebd6f |
dispatch(fetchingBlueprints());
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
fetchingModalManageSourcesContents: () => {
|
|
Packit Service |
eebd6f |
dispatch(fetchingModalManageSourcesContents());
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
blueprintsSortSetKey: (key) => {
|
|
Packit Service |
eebd6f |
dispatch(blueprintsSortSetKey(key));
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
blueprintsSortSetValue: (value) => {
|
|
Packit Service |
eebd6f |
dispatch(blueprintsSortSetValue(value));
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
blueprintsFilterAddValue: (value) => {
|
|
Packit Service |
eebd6f |
dispatch(blueprintsFilterAddValue(value));
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
blueprintsFilterRemoveValue: (value) => {
|
|
Packit Service |
eebd6f |
dispatch(blueprintsFilterRemoveValue(value));
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
blueprintsFilterClearValues: (value) => {
|
|
Packit Service |
eebd6f |
dispatch(blueprintsFilterClearValues(value));
|
|
Packit Service |
eebd6f |
},
|
|
Packit Service |
eebd6f |
});
|
|
Packit Service |
eebd6f |
|
|
Packit Service |
eebd6f |
export default connect(makeMapStateToProps, mapDispatchToProps)(injectIntl(BlueprintsPage));
|