mirror of
https://github.com/inventree/InvenTree.git
synced 2025-12-21 14:20:25 -06:00
* 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
27 lines
561 B
TypeScript
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);
|
|
}
|