Skip to content

Commit

Permalink
feat: Update applications add and remove (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmevladik committed Sep 25, 2024
1 parent d5cc72a commit 6410433
Show file tree
Hide file tree
Showing 18 changed files with 352 additions and 804 deletions.
15 changes: 10 additions & 5 deletions src/providers/Form/components/FormAutocomplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import {
import React from 'react';
import { Controller } from 'react-hook-form';
import { ICONS } from '../../../../icons/iconify-icons-mapping';
import { SelectOption } from '../../../../types/forms';
import { FormAutocompleteProps } from './types';

export const FormAutocomplete = <T,>(props: FormAutocompleteProps<T>) => {
export const FormAutocomplete = <T extends SelectOption>(props: FormAutocompleteProps<T>) => {
const {
name,
label,
Expand Down Expand Up @@ -88,7 +89,7 @@ export const FormAutocomplete = <T,>(props: FormAutocompleteProps<T>) => {
}}
checked={selected}
/>
{option}
{option.label}
</li>
);
}}
Expand Down Expand Up @@ -123,7 +124,7 @@ export const FormAutocomplete = <T,>(props: FormAutocompleteProps<T>) => {
<Chip
{...getTagProps({ index })}
key={index}
label={option}
label={option.label}
color="primary"
size="small"
/>
Expand All @@ -134,10 +135,14 @@ export const FormAutocomplete = <T,>(props: FormAutocompleteProps<T>) => {
);
}}
{...field}
isOptionEqualToValue={(option, value) => option.value === value.value}
onChange={(e, data) => {
field.onChange(data);
const valueArray = data.map((item) => item.value);
field.onChange(valueArray);
}}
value={field.value || []}
value={
field.value ? options.filter((option) => field.value.includes(option.value)) : []
}
/>
);
}}
Expand Down
14 changes: 9 additions & 5 deletions src/providers/Form/components/FormAutocompleteSingle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import {
import React from 'react';
import { Controller } from 'react-hook-form';
import { ICONS } from '../../../../icons/iconify-icons-mapping';
import { SelectOption } from '../../../../types/forms';
import { FormAutocompleteSingleProps } from './types';

export const FormAutocompleteSingle = <T,>(props: FormAutocompleteSingleProps<T>) => {
export const FormAutocompleteSingle = <T extends SelectOption>(
props: FormAutocompleteSingleProps<T>
) => {
const {
name,
label,
Expand Down Expand Up @@ -80,11 +83,12 @@ export const FormAutocompleteSingle = <T,>(props: FormAutocompleteSingleProps<T>
placeholder={placeholder}
/>
)}
{...field}
onChange={(e, data) => {
field.onChange(data.value);
isOptionEqualToValue={(option, value) => option.value === value.value}
getOptionLabel={(option) => option.label || ''}
onChange={(event, newValue) => {
field.onChange(newValue ? newValue.value : '');
}}
value={field.value || []}
value={options.find((option) => option.value === field.value) || null}
/>
);
}}
Expand Down
13 changes: 7 additions & 6 deletions src/utils/sort/sortKubeObjectsByCreationTimestamp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { EDPKubeObjectInterface } from '../../../types/k8s';

export const sortKubeObjectByCreationTimestamp = (
a: EDPKubeObjectInterface,
b: EDPKubeObjectInterface
b: EDPKubeObjectInterface,
backwards?: boolean
): number => {
const aPipelineRunCreationTimeStamp = a.metadata.creationTimestamp.valueOf();
const bPipelineRunCreationTimeStamp = b.metadata.creationTimestamp.valueOf();
const aResourceCreationTimeStamp = a.metadata.creationTimestamp.valueOf();
const bResourceCreationTimeStamp = b.metadata.creationTimestamp.valueOf();

if (aPipelineRunCreationTimeStamp > bPipelineRunCreationTimeStamp) {
return -1;
if (aResourceCreationTimeStamp > bResourceCreationTimeStamp) {
return backwards ? 1 : -1;
} else {
return 1;
return backwards ? -1 : 1;
}
};
Loading

0 comments on commit 6410433

Please sign in to comment.