Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilumilak committed Jul 10, 2024
1 parent 19ff0a6 commit 1052c3d
Showing 1 changed file with 32 additions and 99 deletions.
131 changes: 32 additions & 99 deletions frontend/src/lib/hooks/useMessagesFiltersFields.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PollingMode } from 'generated-sources';
import { MessagesFilterKeysTypes } from 'lib/types';
import { MessagesFilterKeys } from 'lib/constants';
import { useLocalStorage } from 'lib/hooks/useLocalStorage';
Expand Down Expand Up @@ -47,108 +46,42 @@ export function useMessagesFiltersFields(topicName: string) {

const initMessagesFiltersFields = (params: URLSearchParams) => {
const topicMessagesFilters = messageFilters[topicName];
if (params.size === 0 && !!topicMessagesFilters) {
if (topicMessagesFilters.mode) {
params.set(MessagesFilterKeys.mode, topicMessagesFilters.mode);
if (
topicMessagesFilters.mode === PollingMode.FROM_OFFSET ||
topicMessagesFilters.mode === PollingMode.TO_OFFSET
) {
if (topicMessagesFilters.offset) {
params.set(MessagesFilterKeys.offset, topicMessagesFilters.offset);
}
}

if (
topicMessagesFilters.mode === PollingMode.FROM_TIMESTAMP ||
topicMessagesFilters.mode === PollingMode.TO_TIMESTAMP
) {
if (topicMessagesFilters.timestamp) {
params.set(
MessagesFilterKeys.timestamp,
topicMessagesFilters.timestamp
);
}
}
}
if (topicMessagesFilters.partitions) {
params.set(
MessagesFilterKeys.partitions,
topicMessagesFilters.partitions
);
}
if (topicMessagesFilters.keySerde) {
params.set(MessagesFilterKeys.keySerde, topicMessagesFilters.keySerde);
}
if (topicMessagesFilters.valueSerde) {
params.set(
MessagesFilterKeys.valueSerde,
topicMessagesFilters.valueSerde
);
}
if (topicMessagesFilters.stringFilter) {
params.set(
MessagesFilterKeys.stringFilter,
topicMessagesFilters.stringFilter
);
}
} else {
const MessagesFiltersMode = params.get(MessagesFilterKeys.mode);
if (MessagesFiltersMode) {
removeMessagesFilterFields();
setMessagesFiltersField(MessagesFilterKeys.mode, MessagesFiltersMode);
const MessagesFiltersOffset = params.get(MessagesFilterKeys.offset);
if (MessagesFiltersOffset) {
setMessagesFiltersField(
MessagesFilterKeys.offset,
MessagesFiltersOffset
);
}
const MessagesFiltersTimestamp = params.get(
MessagesFilterKeys.timestamp
);
if (MessagesFiltersTimestamp) {
setMessagesFiltersField(
MessagesFilterKeys.timestamp,
MessagesFiltersTimestamp
);
}
const setTopicMessageFiltersFromLocalStorage = (
key: keyof MessagesFilterFieldsType
) => {
if (topicMessagesFilters[key]) {
params.set(MessagesFilterKeys[key], topicMessagesFilters[key]);
}
};

const MessageFiltersPartitions = params.get(
MessagesFilterKeys.partitions
);
if (MessageFiltersPartitions) {
setMessagesFiltersField(
MessagesFilterKeys.partitions,
MessageFiltersPartitions
);
}
const MessagesFiltersKeySerde = params.get(MessagesFilterKeys.keySerde);
if (MessagesFiltersKeySerde) {
setMessagesFiltersField(
MessagesFilterKeys.keySerde,
MessagesFiltersKeySerde
);
}
const MessagesFiltersValueSerde = params.get(
MessagesFilterKeys.valueSerde
);
if (MessagesFiltersValueSerde) {
setMessagesFiltersField(
MessagesFilterKeys.valueSerde,
MessagesFiltersValueSerde
);
}
const MessagesFiltersStringFilter = params.get(
MessagesFilterKeys.stringFilter
);
if (MessagesFiltersStringFilter) {
setMessagesFiltersField(
MessagesFilterKeys.stringFilter,
MessagesFiltersStringFilter
);
const setTopicMessageFiltersFromUrlParams = (
key: keyof MessagesFilterFieldsType
) => {
const filters = params.get(MessagesFilterKeys[key]);
if (filters) {
setMessagesFiltersField(key, filters);
}
};

// if url params are empty and topicMessagesFilters from local storage are existing then we apply them
if (params.size === 0 && !!topicMessagesFilters) {
setTopicMessageFiltersFromLocalStorage(MessagesFilterKeys.mode);
setTopicMessageFiltersFromLocalStorage(MessagesFilterKeys.offset);
setTopicMessageFiltersFromLocalStorage(MessagesFilterKeys.timestamp);
setTopicMessageFiltersFromLocalStorage(MessagesFilterKeys.partitions);
setTopicMessageFiltersFromLocalStorage(MessagesFilterKeys.keySerde);
setTopicMessageFiltersFromLocalStorage(MessagesFilterKeys.valueSerde);
setTopicMessageFiltersFromLocalStorage(MessagesFilterKeys.stringFilter);
} else {
removeMessagesFilterFields();
setTopicMessageFiltersFromUrlParams(MessagesFilterKeys.mode);
setTopicMessageFiltersFromUrlParams(MessagesFilterKeys.offset);
setTopicMessageFiltersFromUrlParams(MessagesFilterKeys.timestamp);
setTopicMessageFiltersFromUrlParams(MessagesFilterKeys.partitions);
setTopicMessageFiltersFromUrlParams(MessagesFilterKeys.keySerde);
setTopicMessageFiltersFromUrlParams(MessagesFilterKeys.valueSerde);
setTopicMessageFiltersFromUrlParams(MessagesFilterKeys.stringFilter);
}
};

Expand Down

0 comments on commit 1052c3d

Please sign in to comment.