mirror of https://github.com/apache/druid.git
Fix home view styling (#9444)
This commit is contained in:
parent
3016057178
commit
32cd47bc8e
|
@ -0,0 +1,27 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`plural pair if needed works when both counts exist 1`] = `
|
||||||
|
<p
|
||||||
|
class="plural-pair-if-needed"
|
||||||
|
>
|
||||||
|
2 running tasks, 1 pending task
|
||||||
|
</p>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`plural pair if needed works when no counts exist 1`] = `null`;
|
||||||
|
|
||||||
|
exports[`plural pair if needed works when only first count exists 1`] = `
|
||||||
|
<p
|
||||||
|
class="plural-pair-if-needed"
|
||||||
|
>
|
||||||
|
2 running tasks
|
||||||
|
</p>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`plural pair if needed works when only second count exists 1`] = `
|
||||||
|
<p
|
||||||
|
class="plural-pair-if-needed"
|
||||||
|
>
|
||||||
|
1 pending task
|
||||||
|
</p>
|
||||||
|
`;
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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 { render } from '@testing-library/react';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { PluralPairIfNeeded } from './plural-pair-if-needed';
|
||||||
|
|
||||||
|
describe('plural pair if needed', () => {
|
||||||
|
it('works when both counts exist', () => {
|
||||||
|
const pluralPairIfNeeded = (
|
||||||
|
<PluralPairIfNeeded
|
||||||
|
firstCount={2}
|
||||||
|
firstSingular="running task"
|
||||||
|
secondCount={1}
|
||||||
|
secondSingular="pending task"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
const { container } = render(pluralPairIfNeeded);
|
||||||
|
expect(container.firstChild).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('works when only first count exists', () => {
|
||||||
|
const pluralPairIfNeeded = (
|
||||||
|
<PluralPairIfNeeded
|
||||||
|
firstCount={2}
|
||||||
|
firstSingular="running task"
|
||||||
|
secondCount={0}
|
||||||
|
secondSingular="pending task"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
const { container } = render(pluralPairIfNeeded);
|
||||||
|
expect(container.firstChild).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('works when only second count exists', () => {
|
||||||
|
const pluralPairIfNeeded = (
|
||||||
|
<PluralPairIfNeeded
|
||||||
|
firstCount={0}
|
||||||
|
firstSingular="running task"
|
||||||
|
secondCount={1}
|
||||||
|
secondSingular="pending task"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
const { container } = render(pluralPairIfNeeded);
|
||||||
|
expect(container.firstChild).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('works when no counts exist', () => {
|
||||||
|
const pluralPairIfNeeded = (
|
||||||
|
<PluralPairIfNeeded
|
||||||
|
firstCount={0}
|
||||||
|
firstSingular="running task"
|
||||||
|
secondCount={0}
|
||||||
|
secondSingular="pending task"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
const { container } = render(pluralPairIfNeeded);
|
||||||
|
expect(container.firstChild).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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 { compact, pluralIfNeeded } from '../../utils';
|
||||||
|
|
||||||
|
export interface PluralPairIfNeededProps {
|
||||||
|
firstCount: number;
|
||||||
|
firstSingular: string;
|
||||||
|
secondCount: number;
|
||||||
|
secondSingular: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PluralPairIfNeeded = React.memo(function PluralPairIfNeeded(
|
||||||
|
props: PluralPairIfNeededProps,
|
||||||
|
) {
|
||||||
|
const { firstCount, firstSingular, secondCount, secondSingular } = props;
|
||||||
|
|
||||||
|
const text = compact([
|
||||||
|
firstCount ? pluralIfNeeded(firstCount, firstSingular) : undefined,
|
||||||
|
secondCount ? pluralIfNeeded(secondCount, secondSingular) : undefined,
|
||||||
|
]).join(', ');
|
||||||
|
if (!text) return null;
|
||||||
|
return <p className="plural-pair-if-needed">{text}</p>;
|
||||||
|
});
|
|
@ -94,7 +94,7 @@ export class DatasourcesCard extends React.PureComponent<
|
||||||
loading={datasourceCountLoading}
|
loading={datasourceCountLoading}
|
||||||
error={datasourceCountError}
|
error={datasourceCountError}
|
||||||
>
|
>
|
||||||
{pluralIfNeeded(datasourceCount, 'datasource')}
|
<p>{pluralIfNeeded(datasourceCount, 'datasource')}</p>
|
||||||
</HomeViewCard>
|
</HomeViewCard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,4 +20,17 @@
|
||||||
.bp3-card {
|
.bp3-card {
|
||||||
height: 170px;
|
height: 170px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.bp3-dark a.home-view-card,
|
||||||
|
.bp3-dark a.home-view-card:hover {
|
||||||
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,5 @@
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: $standard-padding;
|
gap: $standard-padding;
|
||||||
grid-template-columns: 1fr 1fr 1fr 1fr;
|
grid-template-columns: 1fr 1fr 1fr 1fr;
|
||||||
|
padding: 0 60px;
|
||||||
& > a {
|
|
||||||
text-decoration: inherit;
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ import { IconNames } from '@blueprintjs/icons';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { compact, lookupBy, pluralIfNeeded, queryDruidSql, QueryManager } from '../../../utils';
|
import { PluralPairIfNeeded } from '../../../components/plural-pair-if-needed/plural-pair-if-needed';
|
||||||
|
import { lookupBy, queryDruidSql, QueryManager } from '../../../utils';
|
||||||
import { Capabilities } from '../../../utils/capabilities';
|
import { Capabilities } from '../../../utils/capabilities';
|
||||||
import { HomeViewCard } from '../home-view-card/home-view-card';
|
import { HomeViewCard } from '../home-view-card/home-view-card';
|
||||||
|
|
||||||
|
@ -42,20 +43,6 @@ export interface ServicesCardState {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ServicesCard extends React.PureComponent<ServicesCardProps, ServicesCardState> {
|
export class ServicesCard extends React.PureComponent<ServicesCardProps, ServicesCardState> {
|
||||||
static renderPluralIfNeededPair(
|
|
||||||
count1: number,
|
|
||||||
singular1: string,
|
|
||||||
count2: number,
|
|
||||||
singular2: string,
|
|
||||||
): JSX.Element | undefined {
|
|
||||||
const text = compact([
|
|
||||||
count1 ? pluralIfNeeded(count1, singular1) : undefined,
|
|
||||||
count2 ? pluralIfNeeded(count2, singular2) : undefined,
|
|
||||||
]).join(', ');
|
|
||||||
if (!text) return;
|
|
||||||
return <p>{text}</p>;
|
|
||||||
}
|
|
||||||
|
|
||||||
private serviceQueryManager: QueryManager<Capabilities, any>;
|
private serviceQueryManager: QueryManager<Capabilities, any>;
|
||||||
|
|
||||||
constructor(props: ServicesCardProps, context: any) {
|
constructor(props: ServicesCardProps, context: any) {
|
||||||
|
@ -147,20 +134,30 @@ export class ServicesCard extends React.PureComponent<ServicesCardProps, Service
|
||||||
loading={serviceCountLoading}
|
loading={serviceCountLoading}
|
||||||
error={serviceCountError}
|
error={serviceCountError}
|
||||||
>
|
>
|
||||||
{ServicesCard.renderPluralIfNeededPair(
|
<PluralPairIfNeeded
|
||||||
overlordCount,
|
firstCount={overlordCount}
|
||||||
'overlord',
|
firstSingular="overlord"
|
||||||
coordinatorCount,
|
secondCount={coordinatorCount}
|
||||||
'coordinator',
|
secondSingular="coordinator"
|
||||||
)}
|
/>
|
||||||
{ServicesCard.renderPluralIfNeededPair(routerCount, 'router', brokerCount, 'broker')}
|
<PluralPairIfNeeded
|
||||||
{ServicesCard.renderPluralIfNeededPair(
|
firstCount={routerCount}
|
||||||
historicalCount,
|
firstSingular="router"
|
||||||
'historical',
|
secondCount={brokerCount}
|
||||||
middleManagerCount,
|
secondSingular="broker"
|
||||||
'middle manager',
|
/>
|
||||||
)}
|
<PluralPairIfNeeded
|
||||||
{ServicesCard.renderPluralIfNeededPair(peonCount, 'peon', indexerCount, 'indexer')}
|
firstCount={historicalCount}
|
||||||
|
firstSingular="historical"
|
||||||
|
secondCount={middleManagerCount}
|
||||||
|
secondSingular="middle manager"
|
||||||
|
/>
|
||||||
|
<PluralPairIfNeeded
|
||||||
|
firstCount={peonCount}
|
||||||
|
firstSingular="peon"
|
||||||
|
secondCount={indexerCount}
|
||||||
|
secondSingular="indexer"
|
||||||
|
/>
|
||||||
</HomeViewCard>
|
</HomeViewCard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { IconNames } from '@blueprintjs/icons';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { PluralPairIfNeeded } from '../../../components/plural-pair-if-needed/plural-pair-if-needed';
|
||||||
import { lookupBy, pluralIfNeeded, queryDruidSql, QueryManager } from '../../../utils';
|
import { lookupBy, pluralIfNeeded, queryDruidSql, QueryManager } from '../../../utils';
|
||||||
import { Capabilities } from '../../../utils/capabilities';
|
import { Capabilities } from '../../../utils/capabilities';
|
||||||
import { HomeViewCard } from '../home-view-card/home-view-card';
|
import { HomeViewCard } from '../home-view-card/home-view-card';
|
||||||
|
@ -124,8 +125,12 @@ GROUP BY 1`,
|
||||||
loading={taskCountLoading}
|
loading={taskCountLoading}
|
||||||
error={taskCountError}
|
error={taskCountError}
|
||||||
>
|
>
|
||||||
{Boolean(runningTaskCount) && <p>{pluralIfNeeded(runningTaskCount, 'running task')}</p>}
|
<PluralPairIfNeeded
|
||||||
{Boolean(pendingTaskCount) && <p>{pluralIfNeeded(pendingTaskCount, 'pending task')}</p>}
|
firstCount={runningTaskCount}
|
||||||
|
firstSingular="running task"
|
||||||
|
secondCount={pendingTaskCount}
|
||||||
|
secondSingular="pending task"
|
||||||
|
/>
|
||||||
{Boolean(successTaskCount) && <p>{pluralIfNeeded(successTaskCount, 'successful task')}</p>}
|
{Boolean(successTaskCount) && <p>{pluralIfNeeded(successTaskCount, 'successful task')}</p>}
|
||||||
{Boolean(waitingTaskCount) && <p>{pluralIfNeeded(waitingTaskCount, 'waiting task')}</p>}
|
{Boolean(waitingTaskCount) && <p>{pluralIfNeeded(waitingTaskCount, 'waiting task')}</p>}
|
||||||
{Boolean(failedTaskCount) && <p>{pluralIfNeeded(failedTaskCount, 'failed task')}</p>}
|
{Boolean(failedTaskCount) && <p>{pluralIfNeeded(failedTaskCount, 'failed task')}</p>}
|
||||||
|
|
Loading…
Reference in New Issue