This commit is contained in:
Madhurya Liyanage 2023-05-10 15:25:16 +05:30
commit 122db8b2b2
2 changed files with 41 additions and 6 deletions

View File

@ -176,6 +176,9 @@ export default function TaskShow() {
if (disabled) { if (disabled) {
return; return;
} }
if (!formObject) {
navigate(`/tasks`);
}
let queryParams = ''; let queryParams = '';
if (submitType === FormSubmitType.Draft) { if (submitType === FormSubmitType.Draft) {
queryParams = '?save_as_draft=true'; queryParams = '?save_as_draft=true';
@ -347,20 +350,21 @@ export default function TaskShow() {
if (task.state === 'READY') { if (task.state === 'READY') {
let submitButtonText = 'Submit'; let submitButtonText = 'Submit';
let saveAsDraftButton = null; let closeButton = null;
if (task.typename === 'ManualTask') { if (task.typename === 'ManualTask') {
submitButtonText = 'Continue'; submitButtonText = 'Continue';
} else if (task.typename === 'UserTask') { } else if (task.typename === 'UserTask') {
saveAsDraftButton = ( closeButton = (
<Button <Button
id="save-as-draft-button" id="close-button"
disabled={disabled} disabled={disabled}
kind="secondary" kind="secondary"
title="Save changes without submitting."
onClick={() => onClick={() =>
handleFormSubmit(currentFormObject, null, FormSubmitType.Draft) handleFormSubmit(currentFormObject, null, FormSubmitType.Draft)
} }
> >
Save as draft Close
</Button> </Button>
); );
} }
@ -369,7 +373,7 @@ export default function TaskShow() {
<Button type="submit" id="submit-button" disabled={disabled}> <Button type="submit" id="submit-button" disabled={disabled}>
{submitButtonText} {submitButtonText}
</Button> </Button>
{saveAsDraftButton} {closeButton}
<> <>
{task.signal_buttons.map((signal) => ( {task.signal_buttons.map((signal) => (
<Button <Button

View File

@ -19,7 +19,8 @@ function SelectWidget({
placeholder, placeholder,
rawErrors = [], rawErrors = [],
}: WidgetProps) { }: WidgetProps) {
const { enumOptions, enumDisabled } = options; const { enumOptions } = options;
let { enumDisabled } = options;
const emptyValue = multiple ? [] : ''; const emptyValue = multiple ? [] : '';
@ -56,6 +57,36 @@ function SelectWidget({
errorMessageForField = rawErrors[0]; errorMessageForField = rawErrors[0];
} }
// ok. so in safari, the select widget showed the first option, whereas in chrome it forced you to select an option.
// this change causes causes safari to act a little bit more like chrome, but it's different because we are actually adding
// an element to the dropdown.
//
// https://stackoverflow.com/a/7944490/6090676 safari detection
let isSafari = false;
const ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('safari') != -1) {
if (ua.indexOf('chrome') === -1) {
isSafari = true;
}
}
if (isSafari) {
if (enumOptions && enumOptions[0].value !== '') {
enumOptions.unshift({
value: '',
label: '',
});
}
// enumDisabled is a list of values for which the option should be disabled.
// we don't really want users to select the fake empty option we are creating here.
// they cannot select it in chrome, after all.
// google is always right. https://news.ycombinator.com/item?id=35862041
if (enumDisabled === undefined) {
enumDisabled = [];
}
enumDisabled.push('');
}
// maybe use placeholder somehow. it was previously jammed into the helperText field, // maybe use placeholder somehow. it was previously jammed into the helperText field,
// but allowing ui:help to grab that spot seems much more appropriate. // but allowing ui:help to grab that spot seems much more appropriate.