1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

feat(templates): remove toggle and add sorting for app templates EE-2522 (#6884)

This commit is contained in:
matias-portainer 2022-07-20 16:27:15 -03:00 committed by GitHub
parent 9223c0226a
commit df381b6a33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 236 additions and 42 deletions

View file

@ -0,0 +1,32 @@
import { Select } from '@@/form-components/ReactSelect';
interface Filter {
label?: string;
}
interface Props {
options: string[];
onChange: (value: string | null) => void;
placeholder?: string;
value: string;
}
export function TemplateListDropdown({
options,
onChange,
placeholder,
value,
}: Props) {
const filterOptions: Filter[] = options.map((value) => ({ label: value }));
const filterValue: Filter | null = value ? { label: value } : null;
return (
<Select
placeholder={placeholder}
options={filterOptions}
value={filterValue}
isClearable
onChange={(option) => onChange(option?.label ?? null)}
/>
);
}

View file

@ -0,0 +1,11 @@
import { react2angular } from '@/react-tools/react2angular';
import { TemplateListDropdown } from './TemplateListDropdown';
const TemplateListDropdownAngular = react2angular(TemplateListDropdown, [
'options',
'onChange',
'placeholder',
'value',
]);
export { TemplateListDropdown, TemplateListDropdownAngular };

View file

@ -0,0 +1,18 @@
.sort-by-container {
display: flex;
align-items: center;
justify-content: flex-end;
}
.sort-by-element {
display: inline-block;
}
.sort-button {
background-color: var(--bg-sortbutton-color);
color: var(--text-ui-select-color);
border: 1px solid var(--border-sortbutton);
display: inline-block;
padding: 8px 10px;
border-radius: 5px;
}

View file

@ -0,0 +1,53 @@
import { TemplateListDropdown } from '../TemplateListDropdown';
import styles from './TemplateListSort.module.css';
interface Props {
options: string[];
onChange: (value: string | null) => void;
onDescending: () => void;
placeholder?: string;
sortByDescending: boolean;
sortByButton: boolean;
value: string;
}
export function TemplateListSort({
options,
onChange,
onDescending,
placeholder,
sortByDescending,
sortByButton,
value,
}: Props) {
const upIcon = 'fa fa-sort-alpha-up';
const downIcon = 'fa fa-sort-alpha-down';
const iconStyle = sortByDescending ? upIcon : downIcon;
return (
<div className={styles.sortByContainer}>
<div className={styles.sortByElement}>
<TemplateListDropdown
placeholder={placeholder}
options={options}
onChange={onChange}
value={value}
/>
</div>
<div className={styles.sortByElement}>
<button
className={styles.sortButton}
type="button"
disabled={!sortByButton || !value}
onClick={(e) => {
e.preventDefault();
onDescending();
}}
>
<i className={iconStyle} />
</button>
</div>
</div>
);
}

View file

@ -0,0 +1,14 @@
import { react2angular } from '@/react-tools/react2angular';
import { TemplateListSort } from './TemplateListSort';
const TemplateListSortAngular = react2angular(TemplateListSort, [
'options',
'onChange',
'onDescending',
'placeholder',
'sortByDescending',
'sortByButton',
'value',
]);
export { TemplateListSort, TemplateListSortAngular };