Skip to content

Commit

Permalink
add checkbox for restarting existing recordings
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Feb 7, 2023
1 parent 44c14f7 commit d9e73d9
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/app/CreateRecording/CreateRecording.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { CustomRecordingForm } from './CustomRecordingForm';
import { SnapshotRecordingForm } from './SnapshotRecordingForm';

export interface CreateRecordingProps {
restartExisting?: boolean;
name?: string;
templateName?: string;
templateType?: TemplateType;
Expand All @@ -69,6 +70,7 @@ const Comp: React.FC<RouteComponentProps<Record<string, never>, StaticContext, C

const prefilled = React.useMemo(
() => ({
restartExisting: props.location?.state?.restartExisting,
name: props.location?.state?.name,
templateName: props.location?.state?.templateName,
templateType: props.location?.state?.templateType,
Expand Down
20 changes: 20 additions & 0 deletions src/app/CreateRecording/CustomRecordingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import { EventTemplate } from './CreateRecording';

export interface CustomRecordingFormProps {
prefilled?: {
restartExisting?: boolean;
name?: string;
templateName?: string;
templateType?: TemplateType;
Expand Down Expand Up @@ -102,6 +103,7 @@ export const CustomRecordingForm: React.FC<CustomRecordingFormProps> = ({ prefil
: ValidatedOptions.error
: ValidatedOptions.default
);
const [restartExisting, setRestartExisting] = React.useState(prefilled?.restartExisting || false);
const [continuous, setContinuous] = React.useState((prefilled?.duration || 30) < 1);
const [archiveOnStop, setArchiveOnStop] = React.useState(true);
const [duration, setDuration] = React.useState(prefilled?.duration || 30);
Expand Down Expand Up @@ -138,6 +140,13 @@ export const CustomRecordingForm: React.FC<CustomRecordingFormProps> = ({ prefil
[addSubscription, context.api, history, setLoading]
);

const handleRestartExistingChange = React.useCallback(
(checked) => {
setRestartExisting(checked);
},
[setRestartExisting]
);

const handleContinuousChange = React.useCallback(
(checked) => {
setContinuous(checked);
Expand Down Expand Up @@ -260,6 +269,7 @@ export const CustomRecordingForm: React.FC<CustomRecordingFormProps> = ({ prefil
}

const options: RecordingOptions = {
restart: restartExisting,
toDisk: toDisk,
maxAge: toDisk ? (continuous ? maxAge * maxAgeUnits : undefined) : undefined,
maxSize: toDisk ? maxSize * maxSizeUnits : undefined,
Expand Down Expand Up @@ -287,6 +297,7 @@ export const CustomRecordingForm: React.FC<CustomRecordingFormProps> = ({ prefil
nameValid,
notifications,
recordingName,
restartExisting,
toDisk,
handleCreateRecording,
]);
Expand Down Expand Up @@ -408,6 +419,15 @@ export const CustomRecordingForm: React.FC<CustomRecordingFormProps> = ({ prefil
onChange={handleRecordingNameChange}
validated={nameValid}
/>
<Checkbox
label="Restart if recording already exists"
isChecked={restartExisting}
isDisabled={loading}
onChange={handleRestartExistingChange}
aria-label="restartExisting checkbox"
id="recording-restart-existing"
name="recording-restart-existing"
/>
</FormGroup>
<FormGroup
label="Duration"
Expand Down
1 change: 1 addition & 0 deletions src/app/Dashboard/Charts/ChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export const ChartCard: React.FC<ChartCardProps> = (props) => {
history.push({
pathname: '/recordings/create',
state: {
restartExisting: true,
name: RECORDING_NAME,
templateName: 'Profiling',
templateType: 'TARGET',
Expand Down
4 changes: 4 additions & 0 deletions src/app/Shared/Services/Api.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ export class ApiService {
form.append('archiveOnStop', String(recordingAttributes.archiveOnStop));
}
if (recordingAttributes.options) {
if (recordingAttributes.options.restart) {
form.append('restart', String(recordingAttributes.options.restart));
}
if (recordingAttributes.options.toDisk != null) {
form.append('toDisk', String(recordingAttributes.options.toDisk));
}
Expand Down Expand Up @@ -1351,6 +1354,7 @@ export interface EventTemplate {
}

export interface RecordingOptions {
restart?: boolean;
toDisk?: boolean;
maxSize?: number;
maxAge?: number;
Expand Down
1 change: 1 addition & 0 deletions src/test/CreateRecording/CustomRecordingForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ describe('<CustomRecordingForm />', () => {
duration: 30,
archiveOnStop: true,
options: {
restart: false,
toDisk: true,
maxAge: undefined,
maxSize: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@ Array [
type="text"
value=""
/>
<div
className="pf-c-check"
>
<input
aria-invalid={false}
aria-label="restartExisting checkbox"
checked={false}
className="pf-c-check__input"
data-ouia-component-id="OUIA-Generated-Checkbox-1"
data-ouia-component-type="PF4/Checkbox"
data-ouia-safe={true}
disabled={false}
id="recording-restart-existing"
name="recording-restart-existing"
onChange={[Function]}
required={false}
type="checkbox"
/>
<label
className="pf-c-check__label"
htmlFor="recording-restart-existing"
>
Restart if recording already exists
</label>
</div>
<div
aria-live="polite"
className="pf-c-form__helper-text"
Expand Down Expand Up @@ -111,7 +136,7 @@ Array [
aria-label="Continuous checkbox"
checked={false}
className="pf-c-check__input"
data-ouia-component-id="OUIA-Generated-Checkbox-1"
data-ouia-component-id="OUIA-Generated-Checkbox-2"
data-ouia-component-type="PF4/Checkbox"
data-ouia-safe={true}
disabled={false}
Expand Down Expand Up @@ -140,7 +165,7 @@ Array [
aria-label="ArchiveOnStop checkbox"
checked={true}
className="pf-c-check__input"
data-ouia-component-id="OUIA-Generated-Checkbox-2"
data-ouia-component-id="OUIA-Generated-Checkbox-3"
data-ouia-component-type="PF4/Checkbox"
data-ouia-safe={true}
disabled={false}
Expand Down Expand Up @@ -530,7 +555,7 @@ Array [
aria-invalid={false}
checked={true}
className="pf-c-check__input"
data-ouia-component-id="OUIA-Generated-Checkbox-3"
data-ouia-component-id="OUIA-Generated-Checkbox-4"
data-ouia-component-type="PF4/Checkbox"
data-ouia-safe={true}
disabled={false}
Expand Down

0 comments on commit d9e73d9

Please sign in to comment.