Files
teleport/web/packages/shared/utils/getDurationText.ts
T
Rafał Cieślak dd9c042a68 Connect: Show resource search errors in the search bar (#24520)
* Move tshd test helpers to a better location

* Support passing no props to tshd test helpers

* Refactor ResourcesService getServerByHostname tests

* Move pluralize to shared package

* SearchContext: Rename `opened` to `isOpen`

* ActionPicker story: Show auxiliary items in a separate column

* ActionPicker: Split getClusterName into two functions

getClusterName used to not return the name of the cluster if there's only
a single cluster present. Some places needed to get the cluster name
no matter what, such as the modal with resource errors that will be added
to ActionPicker.

* Refactor resource search to use Promise.allSettled

* useSearchAttempts has been renamed to useActionAttempts
* useActionAttempts returns resourceSearchAttempt in order to supply errors
  from ResourcesService.searchResources to ActionPicker.

* SearchContext: Implement lockOpen

We'll want to display error details in a modal. While the user interacts
with the modal, we don't want to close the search bar and reset the results.

So instead, we are going to force the search bar to stay open until the
user closes the modal. This will use the lockOpen function from this commit.

* Add modal for showing resource search errors

* Refactor mockedSearchContext to not be a top-level mutable var

* Show an item in search bar with resource search errors

* ResourceSearchError: Add instanceof check to tests, include clusterUri in message

* Make isLockedOpen into a ref

* Use table tests for lockOpen tests

* Revert "Make isLockedOpen into a ref"

This reverts commit 07f4206cc2.

* Move capitalization to ResourceSearchError.messageWithClusterName

* ResourceSearchError: Use `public` in constructor

* Connect: Improve focus management in search bar (#24665)
2023-04-17 12:46:39 +00:00

37 lines
1018 B
TypeScript

/**
* Copyright 2023 Gravitational, Inc
*
* Licensed 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 { pluralize } from './text';
export function getDurationText(hrs: number, mins: number, secs: number) {
if (!hrs && !mins) {
return `${secs} secs`;
}
const hrText = pluralize(hrs, 'hr');
const minText = pluralize(mins, 'min');
if (!hrs) {
return `${mins} ${minText}`;
}
if (hrs && !mins) {
return `${hrs} ${hrText}`;
}
return `${hrs} ${hrText} and ${mins} ${minText}`;
}