Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/env error controls #17

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/plugins/validate-spectral/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ export const validateSpec = (jsSpec) => (arg) => {
4: "info",
}
const ruleSet = arg.topbarSelectors.spectralVersion()
const errorsOnly = arg.topbarSelectors.errorsOnly()
const environment = arg.topbarSelectors.spectralEnvironment()

// Create a new AbortController specific to this run of validateSpec
// Has to be stored in the global scope as future calls to validateSpec have to access it
controller = new AbortController();
const { signal } = controller;
// NOTE: This assumes that the REST API is available under the same host
// TODO: This might need to use a different ruleset depending on input
fetch(SPECTRAL_HOST + "/valigator/api/validate?ruleset=" + ruleSet, {
// arg.errActions.newSpecWarning({message: 'hier kommt fehler'})
fetch(`${SPECTRAL_HOST}/valigator/api/validate?environment=${environment}&errors-only=${errorsOnly}&ruleset=${ruleSet}`, {
method: "POST",
headers: {
"Accept": "application/json"
Expand Down
27 changes: 27 additions & 0 deletions src/standalone/topbar/components/SpectralEnvironment.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react"
import PropTypes from "prop-types"

const VALID_OPTIONS = ["DE", "PR"]

function SpectralEnvironment(props) {

const currentValue = props.currentStateF()
const onChange = (event) => {
const value = event.target.value
props.onChange(value)
}

return <div className="spectral-environment-select">
<label htmlFor="spectral-environment">Spectral Regelset:</label>
<select id="spectral-environment" name="spectral-environment" onChange={onChange} defaultValue={currentValue}>
{VALID_OPTIONS.map((opt) => <option key={opt} value={opt}>{opt}</option>)}
</select>
</div>
}

SpectralEnvironment.propTypes = {
onChange: PropTypes.func.isRequired,
currentStateF: PropTypes.func.isRequired
}

export default SpectralEnvironment
20 changes: 20 additions & 0 deletions src/standalone/topbar/components/SpectralErrorsOnly.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';

function SpectralErrorsOnly(props) {
const currentValue = props.currentStateF()
const onChange = (event) => {
const value = event.target.value
props.onChange(value)
}
return (
<label>
Spectral Errors Only
<input
type="checkbox"
onChange={onChange} checked={currentValue}
/>
</label>
);
}

export default SpectralErrorsOnly;
5 changes: 4 additions & 1 deletion src/standalone/topbar/components/Topbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { petStoreOas2Def, petStoreOas3Def } from "../../../plugins/default-defin
import SpectralVersion from "./SpectralVersion"

import Logo from "../assets/logo_small.svg"
import SpectralErrorsOnly from "./SpectralErrorsOnly"
import SpectralEnvironment from "./SpectralEnvironment"

export default class Topbar extends React.Component {
constructor(props, context) {
Expand Down Expand Up @@ -389,8 +391,9 @@ export default class Topbar extends React.Component {
</DropdownMenu> : null}
{AboutMenu && <AboutMenu {...makeMenuOptions("About")} />}
<a className="link" href="https://openapi-validator.apps.lan-dev.ocp.lan.huk-coburg.de/" target="_blank">OpenAPI Payload Validierung</a>
<SpectralErrorsOnly onChange={topbarActions.setErrorsOnly} currentStateF={topbarSelectors.errorsOnly}/>
<SpectralVersion onChange={topbarActions.switchSpectralVersion} currentStateF={topbarSelectors.spectralVersion} />
{NewEditorButton && <NewEditorButton />}
<SpectralEnvironment onChange={topbarActions.switchSpectralEnvironment} currentStateF={topbarSelectors.spectralEnvironment} />
</div>
</div>
</div>
Expand Down
21 changes: 19 additions & 2 deletions src/standalone/topbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,33 @@ export default function() {
type: "SWITCH_SPECTRAL_VERSION",
version
}
},
switchSpectralEnvironment(environment) {
return {
type: "SWITCH_SPECTRAL_ENVIRONMENT",
environment
}
},
setErrorsOnly(errorsOnly) {
return {
type: "SET_ERRORS_ONLY",
errorsOnly
}
}
},
reducers: {
TOPBAR_SHOW_MODAL: (state, action) => state.setIn(["shownModals", action.target], true),
TOPBAR_HIDE_MODAL: (state, action) => state.setIn(["shownModals", action.target], false),
SWITCH_SPECTRAL_VERSION: (state, action) => state.setIn(["spectralVersion"], action.version)
SWITCH_SPECTRAL_VERSION: (state, action) => state.setIn(["spectralVersion"], action.version),
SWITCH_SPECTRAL_ENVIRONMENT: (state, action) => state.setIn(["spectralEnvironment"], action.environment),
SET_ERRORS_ONLY:(state) => state.setIn(["errorsOnly"],!state.getIn(["errorsOnly"],true))
},
selectors: {
showModal: (state, name) => state.getIn(["shownModals", name], false),
spectralVersion: (state) => state.getIn(["spectralVersion"], "v10")
spectralVersion: (state) =>state.getIn(["spectralVersion"], "v10"),
spectralEnvironment: (state) =>state.getIn(["spectralEnvironment"], "DE"),
errorsOnly: (state) => state.getIn(["errorsOnly"],true)

}
}
},
Expand Down
Loading