123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- import React from 'react';
- import * as ReactRouter from 'react-router';
- import styled from '@emotion/styled';
- import pick from 'lodash/pick';
- import {Client} from 'app/api';
- import Feature from 'app/components/acl/feature';
- import Alert from 'app/components/alert';
- import Breadcrumbs from 'app/components/breadcrumbs';
- import LightWeightNoProjectMessage from 'app/components/lightWeightNoProjectMessage';
- import PageHeading from 'app/components/pageHeading';
- import SearchBar from 'app/components/searchBar';
- import {t} from 'app/locale';
- import {PageContent, PageHeader} from 'app/styles/organization';
- import space from 'app/styles/space';
- import {Organization} from 'app/types';
- import withApi from 'app/utils/withApi';
- import withOrganization from 'app/utils/withOrganization';
- import AsyncView from 'app/views/asyncView';
- import {DashboardListItem} from '../types';
- import DashboardList from './dashboardList';
- type Props = {
- api: Client;
- organization: Organization;
- location: Location;
- router: ReactRouter.InjectedRouter;
- } & AsyncView['props'];
- type State = {
- dashboards: DashboardListItem[] | null;
- dashboardsPageLinks: string;
- } & AsyncView['state'];
- class ManageDashboards extends AsyncView<Props, State> {
- getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
- const {organization, location} = this.props;
- return [
- [
- 'dashboards',
- `/organizations/${organization.slug}/dashboards/`,
- {
- query: {
- ...pick(location.query, ['cursor', 'query']),
- per_page: '9',
- },
- },
- ],
- ];
- }
- onDashboardsChange() {
- this.reloadData();
- }
- handleSearch(query: string) {
- const {location, router} = this.props;
- router.push({
- pathname: location.pathname,
- query: {...location.query, cursor: undefined, query},
- });
- }
- getQuery() {
- const {query} = this.props.location.query;
- return typeof query === 'string' ? query : undefined;
- }
- renderActions() {
- return (
- <StyledActions>
- <StyledSearchBar
- defaultQuery=""
- query={this.getQuery()}
- placeholder={t('Search Dashboards')}
- onSearch={query => this.handleSearch(query)}
- />
- </StyledActions>
- );
- }
- renderNoAccess() {
- return (
- <PageContent>
- <Alert type="warning">{t("You don't have access to this feature")}</Alert>
- </PageContent>
- );
- }
- renderDashboards() {
- const {dashboards, dashboardsPageLinks} = this.state;
- const {organization, location, api} = this.props;
- return (
- <DashboardList
- api={api}
- dashboards={dashboards}
- organization={organization}
- pageLinks={dashboardsPageLinks}
- location={location}
- onDashboardsChange={() => this.onDashboardsChange()}
- />
- );
- }
- getTitle() {
- return t('Manage Dashboards');
- }
- renderBody() {
- const {organization} = this.props;
- return (
- <Feature
- organization={organization}
- features={['dashboards-manage']}
- renderDisabled={this.renderNoAccess}
- >
- <LightWeightNoProjectMessage organization={organization}>
- <PageContent>
- <Breadcrumbs
- crumbs={[
- {
- label: 'Dashboards',
- to: `/organizations/${organization.slug}/dashboards/`,
- },
- {
- label: 'Manage Dashboards',
- },
- ]}
- />
- <PageHeader>
- <PageHeading>{t('Manage Dashboards')}</PageHeading>
- </PageHeader>
- {this.renderActions()}
- {this.renderDashboards()}
- </PageContent>
- </LightWeightNoProjectMessage>
- </Feature>
- );
- }
- }
- const StyledSearchBar = styled(SearchBar)`
- flex-grow: 1;
- `;
- const StyledActions = styled('div')`
- display: grid;
- grid-template-columns: auto max-content min-content;
- @media (max-width: ${p => p.theme.breakpoints[0]}) {
- grid-template-columns: auto;
- }
- align-items: center;
- margin-bottom: ${space(3)};
- `;
- export default withApi(withOrganization(ManageDashboards));
|