generated from remarkablemark/jira-dashboard-gadget
-
-
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.
- Loading branch information
1 parent
432f3e4
commit 5383f65
Showing
26 changed files
with
611 additions
and
198 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Inline } from '@atlaskit/primitives'; | ||
|
||
import { useFormValuesStore } from '../../hooks'; | ||
import { DeleteButton, TextArea, TextField } from '../../shared'; | ||
|
||
interface Props { | ||
index: number; | ||
showLabel?: boolean; | ||
} | ||
|
||
export default function FormulaSection(props: Props) { | ||
const formValues = useFormValuesStore(); | ||
|
||
return ( | ||
<Inline space="space.050"> | ||
<TextArea | ||
name={`formula[${props.index}]`} | ||
label={props.showLabel && 'Math Formula'} | ||
value={formValues.formula[props.index]} | ||
spellCheck={false} | ||
onChange={(event) => { | ||
formValues.updateFormValue( | ||
'formula', | ||
props.index, | ||
event.target.value, | ||
); | ||
}} | ||
style={{ flexGrow: 1, maxWidth: 400 }} | ||
isRequired | ||
/> | ||
|
||
<TextArea | ||
name={`label[${props.index}]`} | ||
label={props.showLabel && 'Label'} | ||
value={formValues.label[props.index]} | ||
onChange={(event) => { | ||
formValues.updateFormValue('label', props.index, event.target.value); | ||
}} | ||
style={{ flexGrow: 1, maxWidth: 300 }} | ||
isRequired | ||
/> | ||
|
||
<TextField | ||
name={`decimal[${props.index}]`} | ||
label={props.showLabel && 'Decimals'} | ||
value={formValues.decimal[props.index]} | ||
onChange={(event) => { | ||
formValues.updateFormValue( | ||
'decimal', | ||
props.index, | ||
(event.target as HTMLInputElement).value, | ||
); | ||
}} | ||
type="number" | ||
min={0} | ||
width={55} | ||
isRequired | ||
/> | ||
|
||
<DeleteButton | ||
label="Delete formula" | ||
onClick={() => formValues.deleteFormula(props.index)} | ||
offsetLabel={props.showLabel} | ||
/> | ||
</Inline> | ||
); | ||
} |
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,33 @@ | ||
import { Code } from '@atlaskit/code'; | ||
import { FormSection } from '@atlaskit/form'; | ||
import { Box } from '@atlaskit/primitives'; | ||
|
||
import { useFormValuesStore } from '../../hooks'; | ||
import { AddButton } from '../../shared'; | ||
import FormulaSection from './FormulaSection'; | ||
|
||
export default function Formulas() { | ||
const { formula, addFormula } = useFormValuesStore(); | ||
|
||
return ( | ||
<> | ||
<FormSection | ||
title="Formulas" | ||
description={ | ||
<> | ||
Mathematical calculations using variables. For example:{' '} | ||
<Code>a + b</Code> or <Code>var_1 / var_2 * 100</Code>. | ||
</> | ||
} | ||
> | ||
{formula.map((_, index) => ( | ||
<FormulaSection key={index} index={index} showLabel={!index} /> | ||
))} | ||
</FormSection> | ||
|
||
<Box padding="space.050" /> | ||
|
||
<AddButton label="Add formula" onClick={addFormula} /> | ||
</> | ||
); | ||
} |
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 @@ | ||
export { default } from './Formulas'; |
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,15 +1,14 @@ | ||
import Spinner from '@atlaskit/spinner'; | ||
import { view } from '@forge/bridge'; | ||
|
||
import { useFormValues } from '../hooks'; | ||
import Edit from './Edit'; | ||
|
||
export default function EditContext() { | ||
const formValues = useFormValues(); | ||
const { isLoading } = useFormValues(); | ||
|
||
if (!formValues) { | ||
if (isLoading) { | ||
return <Spinner label="Loading" />; | ||
} | ||
|
||
return <Edit formValues={formValues} view={view} />; | ||
return <Edit />; | ||
} |
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,46 @@ | ||
import { ErrorMessage } from '@atlaskit/form'; | ||
import { useState } from 'react'; | ||
|
||
import { useFormValuesStore } from '../../hooks'; | ||
import { TextArea, type TextAreaProps } from '../../shared'; | ||
|
||
interface Props extends TextAreaProps { | ||
index: number; | ||
} | ||
|
||
export default function VariableField(props: Props) { | ||
const { index, ...restProps } = props; | ||
const [error, setError] = useState(''); | ||
const formValues = useFormValuesStore(); | ||
|
||
function validate(value?: unknown) { | ||
if (!value || typeof value !== 'string') { | ||
setError(''); | ||
} else if (!/^[a-zA-Z]/.test(value)) { | ||
setError('Variable must start with a letter'); | ||
} else if (/\s/.test(value)) { | ||
setError('Variable must not contain whitespace'); | ||
} else if (!/^[a-zA-Z0-9_]+$/.test(value)) { | ||
setError('Variable must not contain special characters'); | ||
} else { | ||
setError(''); | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<TextArea | ||
{...restProps} | ||
spellCheck={false} | ||
onChange={(event) => { | ||
formValues.updateFormValue('variable', index, event.target.value); | ||
validate(event.target.value); | ||
}} | ||
style={{ flexGrow: 1, maxWidth: 200 }} | ||
isRequired | ||
/> | ||
|
||
{error && <ErrorMessage>{error}</ErrorMessage>} | ||
</> | ||
); | ||
} |
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,70 @@ | ||
import { Field } from '@atlaskit/form'; | ||
import { Inline } from '@atlaskit/primitives'; | ||
import Select from '@atlaskit/select'; | ||
|
||
import { useFormValuesStore } from '../../hooks'; | ||
import { DeleteButton, TextArea } from '../../shared'; | ||
import VariableField from './VariableField'; | ||
|
||
interface Props { | ||
index: number; | ||
showLabel?: boolean; | ||
} | ||
|
||
export default function VariableSection(props: Props) { | ||
const formValues = useFormValuesStore(); | ||
|
||
return ( | ||
<Inline space="space.050"> | ||
<VariableField | ||
name={`variable[${props.index}]`} | ||
label={props.showLabel && 'Variable'} | ||
value={formValues.variable[props.index]} | ||
index={props.index} | ||
/> | ||
|
||
<Field<string, HTMLSelectElement> | ||
name={`function[${props.index}]`} | ||
label={props.showLabel && 'Function'} | ||
> | ||
{({ fieldProps }) => ( | ||
<Select | ||
{...fieldProps} | ||
options={[ | ||
{ | ||
label: 'COUNT', | ||
value: 'COUNT', | ||
}, | ||
]} | ||
value={formValues.function[props.index]} | ||
onChange={(event) => { | ||
formValues.updateFormValue( | ||
'function', | ||
props.index, | ||
event?.value || '', | ||
); | ||
}} | ||
required | ||
/> | ||
)} | ||
</Field> | ||
|
||
<TextArea | ||
name={`jql[${props.index}]`} | ||
label={props.showLabel && 'JQL'} | ||
value={formValues.jql[props.index]} | ||
spellCheck={false} | ||
onChange={(event) => { | ||
formValues.updateFormValue('jql', props.index, event.target.value); | ||
}} | ||
style={{ flexGrow: 1, maxWidth: 800 }} | ||
/> | ||
|
||
<DeleteButton | ||
label="Delete variable" | ||
onClick={() => formValues.deleteVariable(props.index)} | ||
offsetLabel={props.showLabel} | ||
/> | ||
</Inline> | ||
); | ||
} |
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,33 @@ | ||
import { Code } from '@atlaskit/code'; | ||
import { FormSection } from '@atlaskit/form'; | ||
import { Box } from '@atlaskit/primitives'; | ||
|
||
import { useFormValuesStore } from '../../hooks'; | ||
import { AddButton } from '../../shared'; | ||
import VariableSection from './VariableSection'; | ||
|
||
export default function Variables() { | ||
const { variable, addVariable } = useFormValuesStore(); | ||
|
||
return ( | ||
<> | ||
<FormSection | ||
title="Variables" | ||
description={ | ||
<> | ||
Data used in formula calculations. For example: <Code>a</Code> or{' '} | ||
<Code>var_1</Code>. | ||
</> | ||
} | ||
> | ||
{variable.map((_, index) => ( | ||
<VariableSection key={index} index={index} showLabel={!index} /> | ||
))} | ||
</FormSection> | ||
|
||
<Box padding="space.050" /> | ||
|
||
<AddButton label="Add variable" onClick={addVariable} /> | ||
</> | ||
); | ||
} |
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 @@ | ||
export { default } from './Variables'; |
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,5 @@ | ||
export { useFormValuesStore } from '../store/formValuesStore'; | ||
export * from './useForgeContext'; | ||
export * from './useFormValues'; | ||
export * from './useId'; | ||
export * from './useGetFormValues'; | ||
export * from './useJiraSearch'; |
Oops, something went wrong.