Skip to content

Commit

Permalink
Hide piped disabled, show only when edit application (#5590)
Browse files Browse the repository at this point in the history
Signed-off-by: kypham <[email protected]>
  • Loading branch information
hongky-1994 authored Feb 20, 2025
1 parent 3b4f988 commit acde5ae
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ const ApplicationFormManualV0: FC<ApplicationFormProps> = ({

const classes = useStyles();
const ps = useAppSelector((state) => selectAllPipeds(state));
const pipeds = ps
.filter((piped) => !piped.disabled)
const pipedOptions = ps
.filter((piped) => !piped.disabled || piped.id === detailApp?.pipedId)
.sort((a, b) => sortFunc(a.name, b.name));

const selectedPiped = useAppSelector(selectPipedById(values.pipedId));
Expand Down Expand Up @@ -278,12 +278,13 @@ const ApplicationFormManualV0: FC<ApplicationFormProps> = ({
pipedId: value,
});
}}
options={pipeds.map((piped) => ({
options={pipedOptions.map((piped) => ({
label: `${piped.name} (${piped.id})`,
value: piped.id,
disabled: piped.disabled,
}))}
required
disabled={isSubmitting || pipeds.length === 0}
disabled={isSubmitting || pipedOptions.length === 0}
/>
<FormSelectInput
id="platformProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ const ApplicationFormManualV1: FC<ApplicationFormProps> = ({

const classes = useStyles();
const ps = useAppSelector((state) => selectAllPipeds(state));
const pipeds = ps
.filter((piped) => !piped.disabled)
const pipedOptions = ps
.filter((piped) => !piped.disabled || piped.id === detailApp?.pipedId)
.sort((a, b) => sortFunc(a.name, b.name));

const selectedPiped = useAppSelector(selectPipedById(values.pipedId));
Expand Down Expand Up @@ -259,12 +259,13 @@ const ApplicationFormManualV1: FC<ApplicationFormProps> = ({
pipedId: value,
});
}}
options={pipeds.map((piped) => ({
options={pipedOptions.map((piped) => ({
label: `${piped.name} (${piped.id})`,
value: piped.id,
disabled: piped.disabled,
}))}
required
disabled={isSubmitting || pipeds.length === 0}
disabled={isSubmitting || pipedOptions.length === 0}
/>

<FormControl variant="outlined">
Expand All @@ -275,7 +276,7 @@ const ApplicationFormManualV1: FC<ApplicationFormProps> = ({
value={values.deployTargets.map(
(item) => `${item.deployTarget} - ${item.pluginName}`
)}
disabled={isSubmitting || pipeds.length === 0}
disabled={isSubmitting || pipedOptions.length === 0}
onChange={(_e, value) => {
const selected = deployTargetOptions.filter((item) =>
value.includes(item.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ const ApplicationFormSuggestionV1: FC<Props> = ({
[apps, selectedPipedId]
);

const pipeds = useMemo(() => {
return ps.sort((a, b) => sortFunc(a.name, b.name));
const pipedOptions = useMemo(() => {
return ps
.filter((piped) => !piped.disabled)
.sort((a, b) => sortFunc(a.name, b.name));
}, [ps]);

/**
Expand All @@ -171,10 +173,10 @@ const ApplicationFormSuggestionV1: FC<Props> = ({
* Init selectedPipedId if there is only one piped
*/
useEffect(() => {
if (pipeds.length === 1 && !selectedApp) {
setSelectedPipedId(pipeds[0].id);
if (pipedOptions.length === 1 && !selectedApp) {
setSelectedPipedId(pipedOptions[0].id);
}
}, [pipeds, selectedApp]);
}, [pipedOptions, selectedApp]);

/**
* Init selectedApp if there is only one app
Expand Down Expand Up @@ -249,7 +251,7 @@ const ApplicationFormSuggestionV1: FC<Props> = ({
onSelectPiped(e.target.value as string);
}}
>
{pipeds.map((e) => (
{pipedOptions.map((e) => (
<MenuItem value={e.id} key={`piped-${e.id}`}>
{e.name} ({e.id})
</MenuItem>
Expand Down
6 changes: 5 additions & 1 deletion web/src/components/form-select-input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ const FormSelectInput = <T extends BaseOption>({
disabled={disabled}
>
{options.map((op) => (
<MenuItem value={String(op.value)} key={String(op.value)}>
<MenuItem
value={String(op.value)}
key={String(op.value)}
disabled={!!op?.disabled}
>
{getOptionLabel(op)}
</MenuItem>
))}
Expand Down

0 comments on commit acde5ae

Please sign in to comment.