diff --git a/gradle/changelog/branch_selector.yaml b/gradle/changelog/branch_selector.yaml new file mode 100644 index 0000000000..89b6c9b1bb --- /dev/null +++ b/gradle/changelog/branch_selector.yaml @@ -0,0 +1,2 @@ +- type: Fixed + description: Branch selector display revision if selected instead of first branch ([#1767](https://github.com/scm-manager/scm-manager/pull/1767)) diff --git a/scm-ui/ui-components/src/BranchSelector.tsx b/scm-ui/ui-components/src/BranchSelector.tsx index 27cd0a414c..062221ce57 100644 --- a/scm-ui/ui-components/src/BranchSelector.tsx +++ b/scm-ui/ui-components/src/BranchSelector.tsx @@ -64,6 +64,7 @@ const BranchSelector: FC = ({ branches, onSelectBranch, selectedBranch, l onChange={(branch) => onSelectBranch(branches.filter((b) => b.name === branch)[0])} disabled={!!disabled} value={selectedBranch} + addValueToOptions={true} /> diff --git a/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap b/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap index d07a1eef3f..b7e41bfa8c 100644 --- a/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap +++ b/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap @@ -56524,6 +56524,41 @@ exports[`Storyshots Forms|Radio With HelpText 1`] = ` `; +exports[`Storyshots Forms|Select Add no existing value 1`] = ` +Array [ +
+ +
+ +
+
, +
+ uscss-prometheus +
, +] +`; + exports[`Storyshots Forms|Select Legacy Events 1`] = ` Array [
+ +
+ +
+
, +
+ razor-crest +
, +] +`; + exports[`Storyshots Forms|Select ReactHookForm 1`] = `
{ { { @@ -145,8 +145,64 @@ const LegacyEvents: FC = () => { ); }; +const AddNoExistingValue: FC = () => { + const [value, setValue] = useState("uscss-prometheus"); + + return ( + <> + +
{value}
+ + ); +}; + storiesOf("Forms|Select", module) - .addDecorator(storyFn => {storyFn()}) + .addDecorator((storyFn) => {storyFn()}) + .add("Add no existing value", () => ) .add("Ref", () => ) .add("Legacy Events", () => ) - .add("ReactHookForm", () => ); + .add("ReactHookForm", () => ) + .add("Preselect option", () => ) +; diff --git a/scm-ui/ui-components/src/forms/Select.tsx b/scm-ui/ui-components/src/forms/Select.tsx index 06d9a3cea1..dbf25b3b29 100644 --- a/scm-ui/ui-components/src/forms/Select.tsx +++ b/scm-ui/ui-components/src/forms/Select.tsx @@ -45,6 +45,7 @@ type BaseProps = { defaultValue?: string; readOnly?: boolean; className?: string; + addValueToOptions?: boolean; }; const InnerSelect: FC> = ({ @@ -58,10 +59,17 @@ const InnerSelect: FC> = ({ testId, readOnly, className, + options, + addValueToOptions, ...props }) => { const field = useInnerRef(props.innerRef); + let opts = options; + if (value && addValueToOptions && options.some((o) => o.value === value)) { + opts = [{ label: value, value }, ...options]; + } + const handleInput = (event: ChangeEvent) => { if (props.onChange) { if (isUsingRef(props)) { @@ -113,7 +121,7 @@ const InnerSelect: FC> = ({ disabled={disabled} {...createAttributesForTesting(testId)} > - {props.options.map((opt) => { + {opts.map((opt) => { return (