forked from janus-idp/backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a way to execute the stored scorecards from the database and s…
…tore the result in the db as well janus-idp#17 kubesmarts/akrivis#17 Create a way to define scorecards and put them inside a database #16 kubesmarts/akrivis#16
- Loading branch information
Showing
34 changed files
with
1,227 additions
and
728 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 @@ | ||
export type { ScoreCard } from './types'; | ||
export type { ScoreCardResult } from './types'; | ||
export type { ScoreCardBackendClient } from './RulesClient'; | ||
export { scoreCardApiRef } from './api'; | ||
export type { ScoreCardApi } from './api'; |
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,102 @@ | ||
import React, { useCallback } from 'react'; | ||
|
||
import { useApi } from '@backstage/core-plugin-api'; | ||
|
||
import { | ||
Modal, | ||
ModalVariant, | ||
Wizard, | ||
WizardStep, | ||
} from '@patternfly/react-core'; | ||
|
||
import { ScoreCardApi, scoreCardApiRef } from '../../api'; | ||
import { YamlEditor } from './YamlEditor'; | ||
|
||
type Props = { | ||
isModalOpen: boolean; | ||
cardId: number | undefined; | ||
onAfterCreate: any; | ||
}; | ||
|
||
export const CardForm = ({ | ||
isModalOpen = false, | ||
cardId = undefined, | ||
onAfterCreate = () => {}, | ||
}: Props) => { | ||
const scoreCardApi: ScoreCardApi = useApi(scoreCardApiRef); | ||
|
||
const [modalOpenState, setModalOpen] = React.useState(isModalOpen); | ||
const [cardValue, setCardValue] = React.useState(''); | ||
const [configValue, setConfigValue] = React.useState(''); | ||
|
||
const load = useCallback(() => { | ||
const id = cardId ?? -1; | ||
if (id >= 0) { | ||
scoreCardApi.getCardData(id).then(cardData => { | ||
setCardValue(cardData.cardDefinition); | ||
setConfigValue(cardData.configurationDefinition); | ||
setModalOpen(isModalOpen); | ||
}); | ||
} else { | ||
setModalOpen(isModalOpen); | ||
} | ||
}, [scoreCardApi, isModalOpen, cardId]); | ||
|
||
React.useEffect(() => { | ||
load(); | ||
}, [load]); | ||
|
||
const handleCardInputChange = (value: string | undefined) => { | ||
if (value !== undefined) { | ||
setCardValue(value); | ||
} | ||
}; | ||
|
||
const handleConfigInputChange = (value: string | undefined) => { | ||
if (value !== undefined) { | ||
setConfigValue(value); | ||
} | ||
}; | ||
|
||
const handleModalToggle = () => { | ||
setModalOpen(!isModalOpen); | ||
}; | ||
|
||
const createCard = () => { | ||
scoreCardApi | ||
.createCard({ definition: cardValue }, { definition: configValue }) | ||
.then(() => { | ||
setModalOpen(false); | ||
onAfterCreate(); | ||
}); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
className="pf-v5-theme-dark" | ||
variant={ModalVariant.large} | ||
title="Create a Card" | ||
description="Card something" | ||
isOpen={modalOpenState} | ||
onClose={handleModalToggle} | ||
> | ||
<Wizard | ||
height={400} | ||
title="Basic wizard" | ||
onSave={createCard} | ||
onClose={handleModalToggle} | ||
> | ||
<WizardStep name="Configuration" id="config-step"> | ||
<YamlEditor value={configValue} onChange={handleConfigInputChange} /> | ||
</WizardStep> | ||
<WizardStep | ||
name="Card" | ||
id="card-step" | ||
footer={{ nextButtonText: 'Finish' }} | ||
> | ||
<YamlEditor value={cardValue} onChange={handleCardInputChange} /> | ||
</WizardStep> | ||
</Wizard> | ||
</Modal> | ||
); | ||
}; |
Oops, something went wrong.