-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP for performance seed to test pagination and search
- Loading branch information
Showing
14 changed files
with
308 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@import "../styles/vars.scss"; | ||
@import "../styles/vars"; | ||
|
||
.mod-system { | ||
padding-top: 25px; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, {useState} from "react"; | ||
import I18n from "../locale/I18n"; | ||
import "./PerformanceSeed.scss"; | ||
import {Button, Loader} from "@surfnet/sds"; | ||
import {performanceSeed} from "../api"; | ||
|
||
|
||
export const PerformanceSeed = () => { | ||
const [seed, setSeed] = useState(null); | ||
const [millis, setMillis] = useState(0); | ||
const [loading, setLoading] = useState(false); | ||
|
||
if (loading) { | ||
return <Loader/> | ||
} | ||
|
||
const doPerformanceSeed = () => { | ||
setLoading(true); | ||
setMillis(new Date().getTime()) | ||
performanceSeed().then(res => { | ||
setSeed(res); | ||
setLoading(false); | ||
setMillis(new Date().getTime() - millis); | ||
}) | ||
} | ||
|
||
return ( | ||
<div className="mod-performance-seed-container"> | ||
<div className="mod-performance-seed"> | ||
<div className="actions"> | ||
<p>{I18n.t("system.performanceSeedInfo")}</p> | ||
<Button onClick={doPerformanceSeed} | ||
txt={I18n.t("system.performanceSeed")} | ||
/> | ||
</div> | ||
{seed && | ||
<div className="results"> | ||
<p>{I18n.t("system.performanceMillis", {millis: millis})}</p> | ||
<code className="results"> | ||
{JSON.stringify(seed, null, 4)} | ||
</code> | ||
</div>} | ||
</div> | ||
|
||
|
||
</div>) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@import "../styles/mixins"; | ||
|
||
.mod-performance-seed-container { | ||
background-color: white; | ||
|
||
.mod-performance-seed { | ||
@include page; | ||
padding: 20px 0; | ||
|
||
.actions { | ||
display: flex; | ||
gap: 40px; | ||
align-items: center; | ||
} | ||
|
||
code.results { | ||
margin-top: 20px; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package access.seed; | ||
|
||
|
||
import java.util.Locale; | ||
import java.util.Random; | ||
|
||
public class NameGenerator { | ||
|
||
private static final Random random = new Random(); | ||
|
||
private static final String[] consonants = new String[]{ | ||
"al", "an", "ar", "as", "at", "ea", "ed", "en", "er", "es", "ha", "he", "hi", "in", "is", "it", | ||
"le", "me", "nd", "ne", "ng", "nt", "on", "or", "ou", "re", "se", "st", "te", "th", "ti", "to", | ||
"ve", "wa", "it" | ||
}; | ||
private static final String[] vowels = new String[]{"a", "e", "i", "o", "u", "y"}; | ||
|
||
|
||
public static String generate() { | ||
int baseMaxLength = 18; | ||
int maxLength = random.nextInt((int) (baseMaxLength * 0.5), baseMaxLength + 1); | ||
StringBuilder result = new StringBuilder(); | ||
while (result.length() < maxLength) { | ||
String part = maxLength % 2 == 0 ? vowels[random.nextInt(vowels.length)] : consonants[random.nextInt(consonants.length)]; | ||
result.append(part); | ||
} | ||
|
||
while (result.length() > maxLength) { | ||
result.deleteCharAt(result.length() - 1); | ||
} | ||
return capitalize(clean(result)); | ||
} | ||
|
||
private static String capitalize(final StringBuilder sb) { | ||
return sb.substring(0, 1).toUpperCase(Locale.ROOT) + sb.substring(1); | ||
} | ||
|
||
private static StringBuilder clean(final StringBuilder sb) { | ||
int codePoint = sb.codePointAt(0); | ||
if (!Character.isAlphabetic(codePoint)) { | ||
sb.deleteCharAt(0); | ||
} | ||
codePoint = sb.codePointAt(sb.length() - 1); | ||
if (!Character.isAlphabetic(codePoint)) { | ||
sb.deleteCharAt(sb.length() - 1); | ||
} | ||
return sb; | ||
} | ||
|
||
} |
Oops, something went wrong.