Files
InvenTree/src/frontend/src/functions/tables.tsx
Oliver 8c10b98fe8 [React] Update part parameters table (#5731)
* Implement simple "PartVariantTable" component

- Not yet nested
- More work needed for table nesting

* Fix issue rendering same image multiple times

- Use useId hook to generate random key

* Update PartParameter list API endpoint

- Allow part_detail extra field
- Add FilterSet class
- Allow filter to include variants

* Update PartParameterTable

- Display part column
- Allow returned parts to include templates of base part
- Hide actions for templated parameters

* Fix some code smells
2023-10-18 00:41:05 +11:00

27 lines
561 B
TypeScript

/**
* Reduce an input string to a given length, adding an ellipsis if necessary
* @param str - String to shorten
* @param len - Length to shorten to
*/
export function shortenString({
str,
len = 100
}: {
str: string | undefined;
len?: number;
}) {
// Ensure that the string is a string
str = str ?? '';
str = str.toString();
// If the string is already short enough, return it
if (str.length <= len) {
return str;
}
// Otherwise, shorten it
let N = Math.floor(len / 2 - 1);
return str.slice(0, N) + '...' + str.slice(-N);
}