Skip to content

Commit 5979395

Browse files
committed
dev: Fix spacing issues in filters and small fixes
1 parent ddbe269 commit 5979395

File tree

5 files changed

+70
-47
lines changed

5 files changed

+70
-47
lines changed

src/components/FilterInput/Filter.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, { useState } from 'react';
2+
import { useTranslation } from 'react-i18next';
23
import styled from 'styled-components';
34
import FilterPopup from '@components/FilterInput/FilterPopup';
4-
import Icon from '../Icon';
5+
import Icon from '@components/Icon';
56

67
export type FilterProps = {
78
label: string;
@@ -51,12 +52,20 @@ const Filter: React.FC<FilterProps> = ({ label, labelRenderer, value = '', onSel
5152
);
5253
};
5354

54-
export const DefaultLabelRenderer = (label: string, value?: string | null) => (
55-
<>
56-
{`${label}${value ? ':' : ''}`}
57-
{value ? <SelectedValue>{value}</SelectedValue> : ''}
58-
</>
59-
);
55+
export const DefaultLabelRenderer = (label: string, value?: string | null) => {
56+
const { t } = useTranslation();
57+
const selectedValues = value?.split(',') || [];
58+
59+
const valueLabel =
60+
selectedValues?.length > 1 ? `${selectedValues.length} ${t('filters.selected')}` : selectedValues?.[0];
61+
62+
return (
63+
<>
64+
{`${label}${value ? ':' : ''}`}
65+
{value ? <SelectedValue>{valueLabel}</SelectedValue> : ''}
66+
</>
67+
);
68+
};
6069

6170
const FilterBase = styled.div`
6271
position: relative;

src/components/FilterInput/FilterRows.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ export const FilterTextRow = styled.div`
6969
margin: 0.5rem 0;
7070
color: var(--color-text-secondary);
7171
`;
72+
73+
export const FilterText = styled.span`
74+
color: var(--color-text-secondary);
75+
font-weight: 500;
76+
font-size: var(--font-size-3);
77+
`;

src/components/Table/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export const HeaderColumn: React.FC<HeaderColumnProps> = ({
143143

144144
return (
145145
<TH
146-
active={active}
146+
active={sortable && active}
147147
onClick={() => (sortable ? onSort(queryKey) : null)}
148148
{...rest}
149149
clickable={sortable}

src/pages/Home/Filters/TimerangeSelection.tsx

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import { TFunction } from 'i18next';
2-
import React, { useContext } from 'react';
2+
import React, { useContext, useState } from 'react';
33
import { useTranslation } from 'react-i18next';
44
import spacetime from 'spacetime';
55
import styled from 'styled-components';
66
import Filter from '@components/FilterInput/Filter';
7-
import {
8-
FilterClickableRow,
9-
FilterPopupTrailing,
10-
FilterSeparator,
11-
FilterTextRow,
12-
} from '@components/FilterInput/FilterRows';
7+
import { FilterClickableRow, FilterSeparator, FilterText } from '@components/FilterInput/FilterRows';
138
import DateInput from '@components/Form/DateInput';
9+
import HeightAnimatedContainer from '@components/HeightAnimatedContainer';
10+
import Icon from '@components/Icon';
1411
import { TimezoneContext } from '@components/TimezoneProvider';
15-
import { getDateTimeLocalString, getTimeFromPastByDays, getTimeRangeString } from '@utils/date';
12+
import { getDateTimeLocalString, getTimeFromPastByDays } from '@utils/date';
1613

1714
export type TimerangeValues = { start: number | null; end: number | null };
1815
type Props = {
@@ -30,6 +27,7 @@ const TimerangeSelection: React.FC<Props> = ({ value, onChange }) => {
3027
<Filter
3128
label="Time frame"
3229
value={labelValue}
30+
onClear={() => onChange({ start: null, end: null })}
3331
content={({ onClose }) => (
3432
<TimeRangePopup label={labelValue} value={value} onChange={onChange} onClose={onClose} />
3533
)}
@@ -43,9 +41,11 @@ const TimeRangePopup: React.FC<{
4341
label: string | null;
4442
onChange: (args: TimerangeValues) => void;
4543
onClose: () => void;
46-
}> = ({ value, onChange, onClose }) => {
44+
}> = ({ value, label, onChange }) => {
4745
const { t } = useTranslation();
4846
const { timezone } = useContext(TimezoneContext);
47+
const [customOpen, setCustomOpen] = useState(label === t('date.custom'));
48+
4949
const presets = [
5050
{ label: t('date.today'), start: getTimeFromPastByDays(0, timezone), end: null },
5151
{ label: t('date.yesterday'), start: getTimeFromPastByDays(1, timezone), end: getTimeFromPastByDays(0, timezone) },
@@ -61,31 +61,34 @@ const TimeRangePopup: React.FC<{
6161
</FilterClickableRow>
6262
))}
6363
<FilterSeparator />
64-
<FilterTextRow>{t('filters.custom')}</FilterTextRow>
65-
66-
<TimerangeFields>
67-
<DateInput
68-
inputType="datetime-local"
69-
onChange={(newValue) => onChange({ ...value, start: newValue ? spacetime(newValue, timezone).epoch : null })}
70-
initialValue={value.start ? getDateTimeLocalString(new Date(value.start), timezone) : undefined}
71-
/>
64+
<FilterClickableRow onClick={() => setCustomOpen(!customOpen)}>
65+
<CollapseRow>
66+
<FilterText>{t('filters.custom')}</FilterText>
67+
<Icon name="chevron" size="xs" rotate={customOpen ? -180 : 0} />
68+
</CollapseRow>
69+
</FilterClickableRow>
7270

73-
<DateInput
74-
inputType="datetime-local"
75-
onChange={(newValue) => onChange({ ...value, end: newValue ? spacetime(newValue, timezone).epoch : null })}
76-
initialValue={value.end ? getDateTimeLocalString(new Date(value.end), timezone) : undefined}
77-
/>
78-
</TimerangeFields>
71+
<HeightAnimatedContainer>
72+
{customOpen && (
73+
<TimerangeFields>
74+
<DateInput
75+
inputType="datetime-local"
76+
onChange={(newValue) =>
77+
onChange({ ...value, start: newValue ? spacetime(newValue, timezone).epoch : null })
78+
}
79+
initialValue={value.start ? getDateTimeLocalString(new Date(value.start), timezone) : undefined}
80+
/>
7981

80-
<FilterPopupTrailing
81-
clear={{
82-
onClick: () => {
83-
onChange({ start: null, end: null });
84-
onClose();
85-
},
86-
disabled: value.start === null && value.end === null,
87-
}}
88-
/>
82+
<DateInput
83+
inputType="datetime-local"
84+
onChange={(newValue) =>
85+
onChange({ ...value, end: newValue ? spacetime(newValue, timezone).epoch : null })
86+
}
87+
initialValue={value.end ? getDateTimeLocalString(new Date(value.end), timezone) : undefined}
88+
/>
89+
</TimerangeFields>
90+
)}
91+
</HeightAnimatedContainer>
8992
</div>
9093
);
9194
};
@@ -111,19 +114,21 @@ function formatString(value: TimerangeValues, timezone: string, t: TFunction): s
111114
return t('date.yesterday');
112115
}
113116

114-
return getRawDateString(value, timezone);
115-
}
116-
117-
function getRawDateString(value: TimerangeValues, timezone: string): string {
118-
return `${value.start ? getTimeRangeString(new Date(value.start), timezone) : ''} - ${
119-
value.end ? getTimeRangeString(new Date(value.end), timezone) : ''
120-
}`;
117+
return t('date.custom');
121118
}
122119

123120
const TimerangeFields = styled.div`
124121
display: flex;
125122
flex-direction: column;
126123
gap: 0.5rem;
124+
margin-top: 0.5rem;
125+
`;
126+
127+
const CollapseRow = styled.div`
128+
width: 100%;
129+
display: flex;
130+
justify-content: space-between;
131+
align-items: center;
127132
`;
128133

129134
export default TimerangeSelection;

src/translations/en.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ const en = {
8585
'branch-placeholder': 'Filter by branch',
8686
'user-placeholder': 'Filter by user',
8787
'tag-placeholder': 'Filter by tag',
88+
89+
selected: 'selected',
8890
},
8991

9092
run: {
@@ -303,6 +305,7 @@ const en = {
303305
twoweeks: 'Last 14 days',
304306
yesterday: 'Yesterday',
305307
today: 'Today',
308+
custom: 'Custom',
306309
},
307310

308311
debug: {

0 commit comments

Comments
 (0)