Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

286 add filtering to events #415

Closed
wants to merge 38 commits into from
Closed

Conversation

tiniuspre
Copy link
Contributor

No description provided.

@tiniuspre tiniuspre requested a review from emilte as a code owner March 14, 2023 14:49
@tiniuspre tiniuspre self-assigned this Mar 14, 2023
@tiniuspre tiniuspre linked an issue Mar 14, 2023 that may be closed by this pull request
frontend/src/api.ts Outdated Show resolved Hide resolved
Comment on lines 50 to 65
-moz-column-rule: 1px solid rgba(28,110,164,0.39);
column-rule: 1px solid rgba(28,110,164,0.39);
@include for-mobile-down {
-webkit-column-count: 1;
-moz-column-count: 1;
column-count: 1;
-webkit-column-gap: 26px;
-moz-column-gap: 26px;
column-gap: 26px;
-webkit-column-rule: 1px solid rgba(28,110,164,0.39);
-moz-column-rule: 1px solid rgba(28,110,164,0.39);
column-rule: 1px solid rgba(28,110,164,0.39);
}

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trenger du alpha på disse?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finnes det ikke en ekvivalent i hex? Alpha er litt ulempe å bruke med mindre det er nødvendig nemlig. Det er fordi universell utforming-verktøy ikke klarer å avgjøre om kontrast er akseptabelt eller ikke da fargen er gjennomsiktig. Med andre ord avhenger fargene av bakgrunnen.

Comment on lines 89 to 118
def url_args(self, query_word: str) -> str:
query = self.request.GET.get(query_word, None)
if query is None:
return ''
return query.split(',')[0]

def general_search(self, events_query: QuerySet, search_term: str) -> QuerySet:
fields = [f for f in Event._meta.fields if (isinstance(f, CharField) or isinstance(f, TextField))]
queries = [Q(**{f.name + '__contains': search_term}) for f in fields]
qs = Q()
for query in queries:
qs = qs | query

return events_query.filter(qs)

def statusGroup(self) -> str:
if self.request.GET.get('archived', None) == 'true':
return 'active'
return 'archived'

def get(self, request: Request) -> Response:
events: dict = {}
for event in Event.objects.all().values():
events_query = Event.objects.all()

if '?' in self.request.build_absolute_uri():
events_query = self.general_search(events_query, self.url_args('search')).filter(
Q(location__contains=self.url_args('location')), Q(status_group=self.statusGroup())
)

for event in events_query.all().order_by('start_dt').values():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeg tror dette kan gjøres lettere med query params

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eller hvis du kan legge til docstring så kanskje jeg henger mer med

Comment on lines 95 to 102
def general_search(self, events_query: QuerySet, search_term: str) -> QuerySet:
fields = [f for f in Event._meta.fields if (isinstance(f, CharField) or isinstance(f, TextField))]
queries = [Q(**{f.name + '__contains': search_term}) for f in fields]
qs = Q()
for query in queries:
qs = qs | query

return events_query.filter(qs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trenger vi så generisk filter for bare ett view? Kan kanskje skjønne det hvis det var universalt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja, er enklest sånn for å søke etter ord i alle tekst felter, kunne evt laget en egen funksjon ett sted som alle kan ha nytte av

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hva om man ikke ønsker å søke i alle tekstfelt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fjerne if setningen så er det alle felter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kanskje man kan ta inn en liste med felter man ønsker å filtrere på?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

backend/samfundet/views.py Outdated Show resolved Hide resolved

<div className={styles.filterColumn}>
<label className={styles.container} key={t(KEY.all_venues)}>
<RadioButton name="venues" value="" onChange={() => setSelectedVenue(all_venues)} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trenger den ikke value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

</Button>
</div>
</div>
) : null}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dette er en stor ternary. Det kan gjøres enklere. Vurder subkomponent også

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


export function EventsPage() {
const all_venues = 'all';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trekk ut

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

getVenues().then((data) => {
setVenues(data);
});
setShowSpinner(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nå stopper den uansett om ting lastes eller ikke

backend/samfundet/views.py Outdated Show resolved Hide resolved

if '?' in self.request.build_absolute_uri():
events_query = general_search(events_query, self.url_args('search'))
events_query = events_query.filter(location__contains=self.url_args('location'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
events_query = events_query.filter(location__contains=self.url_args('location'))
location = request.query_params.get('location', '')
events_query = events_query.filter(location__contains=self.url_args('location'))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hva skjer dersom location ikke er der, da blir filteret rart?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hva med spørsmålet?

events_query = general_search(events_query, self.url_args('search'))
events_query = events_query.filter(location__contains=self.url_args('location'))

for event in events_query.order_by('start_dt').values():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trenger du .values()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Håndterer det som et dict når jeg sorterer den, da trenger jeg .values() for å gjøre det om

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ser ikke ut som du trenger det. Du henter jo bare ut et felt.

Som data i responsen kanskje vi kan bruke serializer i stedet slik at det blir likt som resten av api-et.

justify-content: center;
align-items: center;
background: #a03033;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

Comment on lines +64 to +76
-moz-column-rule: 1px solid rgba(28, 110, 164, 0.39);
column-rule: 2px solid rgba(28, 110, 164, 0.39);
@include for-mobile-down {
-webkit-column-count: 1;
-moz-column-count: 1;
column-count: 1;
-webkit-column-gap: 2%;
-moz-column-gap: 2%;
column-gap: 2%;
-webkit-column-rule: 1px solid rgba(28, 110, 164, 0.39);
-moz-column-rule: 1px solid rgba(28, 110, 164, 0.39);
column-rule: 1px solid rgba(28, 110, 164, 0.39);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Litt skeptisk til alpha. Tror du bør finne absolutt-farge for å garantere god kontrast.

const [venues, setVenues] = useState<VenueDto[]>([]);
const [filterToggle, setFilterToggle] = useState<boolean>(false);
const [eventsOptions, setEventsOption] = useState<EventOptionsDto | null>(null);
const handleClick = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function

.catch((error) => {
toast.error(t(KEY.common_something_went_wrong));
console.error(error);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

litt rar plassering

}, []);

const handleFilterToggle = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

};

export function FilterRow({ label, name, property, urlArgs }: FilterRowProps) {
const { t } = useTranslation<string>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hvorfor typer du denne?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prøv å følge komponent strukturen definert i docs.

{t(KEY.all)}
</label>
{Object.keys(property).map((option, key) => (
<label key={key} className={styles.container}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hvorfor label? RadioButton har det

Comment on lines +74 to 133
export type EventOptionsDto = {
name?: string;
description?: string;
renders?: object;
actions: { POST: EventOptionsPostDto };
};

export type EventOptionsPostDto = {
id?: EventOptionsPostKeysDto;
end_dt?: EventOptionsPostKeysDto;
image_url?: EventOptionsPostKeysDto;
title_nb: EventOptionsPostKeysDto;
title_en?: EventOptionsPostKeysDto;
description_long_nb?: EventOptionsPostKeysDto;
description_long_en?: EventOptionsPostKeysDto;
description_short_nb?: EventOptionsPostKeysDto;
description_short_en?: EventOptionsPostKeysDto;
location?: EventOptionsPostKeysDto;
codeword?: EventOptionsPostKeysDto;
created_at?: EventOptionsPostKeysDto;
updated_at?: EventOptionsPostKeysDto;
start_dt?: EventOptionsPostKeysDto;
duration?: EventOptionsPostKeysDto;
publish_dt?: EventOptionsPostKeysDto;
host?: EventOptionsPostKeysDto;
status_group: EventOptionsPostKeysChoisesDto;
age_group: EventOptionsPostKeysChoisesDto;
category: EventOptionsPostKeysChoisesDto;
price_group: EventOptionsPostKeysChoisesDto;
capacity?: EventOptionsPostKeysDto;
event_group?: EventOptionsPostKeysDto;
};

export type EventOptionsPostKeysDto = {
actions?: object;
type?: string;
required?: boolean;
read_only?: boolean;
label: string;
};

export type EventOptionsPostKeysChoisesDto = {
type: string;
required: boolean;
read_only: boolean;
label: string;
choices: EventOptionsChoises_Dto;
};

export type EventOptionsChoises_Dto = [
{
value: string;
display_name: string;
},
];


// ==================== //
// Event //
// ==================== //
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evgiz kan du ta en titt?

Comment on lines 149 to 174
form_confirm: 'form_confirm',
duration: 'duration',
publication: 'publication',
closed_period: 'closed_period',
saksdokument: 'saksdokument',
select_event: 'select_event',
all: 'all',
search_all: 'search_all',
archived_events: 'archived_events',
event_category: 'event_category',
choose_age: 'choose_age',
choose_status: 'choose_status',
photos: 'photos',
nybygg: 'nybygg',
common_sulten: 'common_sulten',
sulten_page_book_table: 'sulten_page_book_table',
sulten_page_kitchen: 'sulten_page_kitchen',
sulten_page_see_menu: 'sulten_page_see_menu',
sulten_page_about_us: 'sulten_page_about_us',
sulten_page_more_about_us: 'sulten_page_more_about_us',
admin_saksdokumenter_title: 'admin_saksdokumenter_title',
back_to_samfundet: 'back_to_samfundet',
no_file_selected: 'no_file_selected',
category: 'category',
choose_a_file: 'choose_a_file',
control_panel_faq: 'control_panel_faq',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Så du ikke hvor fin filen var?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Veldig tydelig mønster

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Les docstring øverst om navn

Comment on lines 134 to 153
[KEY.duration]: 'Varighet',
[KEY.publication]: 'Publisering',
[KEY.closed_period]: 'Stengt periode',
[KEY.saksdokument]: 'Saksdokument',
[KEY.select_event]: 'Velg lokale',
[KEY.all]: 'Alle',
[KEY.search_all]: 'Søk på alle arrangemanger!',
[KEY.archived_events]: 'Vis arkiverte arrangemanger',
[KEY.event]: '',
[KEY.event_category]: 'Velg type arrangemang',
[KEY.choose_age]: 'Aldersgrense',
[KEY.choose_status]: 'Status',
[KEY.photos]: 'Foto',
[KEY.nybygg]: 'Nybygg',
[KEY.common_sulten]: 'Lyche',
[KEY.sulten_page_book_table]: 'Bestill bord',
[KEY.sulten_page_kitchen]: 'Kjøkken',
[KEY.navbar_photos]: 'Foto',
[KEY.navbar_nybygg]: 'Nybygg',
[KEY.control_panel_faq]: 'Hjelp/spørsmål',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls rydd

@emilte emilte marked this pull request as draft April 18, 2023 23:03
@tiniuspre tiniuspre closed this Feb 8, 2024
@tiniuspre tiniuspre deleted the 286-add-filtering-to-events branch February 8, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add filtering to events
4 participants