Skip to content

Commit

Permalink
Merge pull request #464 from uhh-lt/yannick-feedback
Browse files Browse the repository at this point in the history
Yannick feedback
  • Loading branch information
bigabig authored Nov 12, 2024
2 parents cccf0c4 + d93ca16 commit 905cc05
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 53 deletions.
88 changes: 44 additions & 44 deletions backend/src/app/core/data/crud/document_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ def link_multiple_document_tags(
if len(sdoc_ids) == 0 or len(tag_ids) == 0:
return 0

# create before state
from app.core.data.crud.source_document import crud_sdoc
# # create before state
# from app.core.data.crud.source_document import crud_sdoc

sdoc_orms = crud_sdoc.read_by_ids(db, sdoc_ids)
before_states = [
crud_sdoc._get_action_state_from_orm(sdoc_orm) for sdoc_orm in sdoc_orms
]
# sdoc_orms = crud_sdoc.read_by_ids(db, sdoc_ids)
# before_states = [
# crud_sdoc._get_action_state_from_orm(sdoc_orm) for sdoc_orm in sdoc_orms
# ]

# insert links (sdoc <-> tag)
from sqlalchemy.dialects.postgresql import insert
Expand All @@ -84,22 +84,22 @@ def link_multiple_document_tags(
new_rows = db.execute(insert_stmt, insert_values).fetchall()
db.commit()

# create after state
sdoc_orms = crud_sdoc.read_by_ids(db, sdoc_ids)
after_states = [
crud_sdoc._get_action_state_from_orm(sdoc_orm) for sdoc_orm in sdoc_orms
]

# create actions
for db_obj, before_state, after_state in zip(
sdoc_orms, before_states, after_states
):
crud_sdoc._create_action(
db_obj=db_obj,
action_type=ActionType.UPDATE,
before_state=before_state,
after_state=after_state,
)
# # create after state
# sdoc_orms = crud_sdoc.read_by_ids(db, sdoc_ids)
# after_states = [
# crud_sdoc._get_action_state_from_orm(sdoc_orm) for sdoc_orm in sdoc_orms
# ]

# # create actions
# for db_obj, before_state, after_state in zip(
# sdoc_orms, before_states, after_states
# ):
# crud_sdoc._create_action(
# db_obj=db_obj,
# action_type=ActionType.UPDATE,
# before_state=before_state,
# after_state=after_state,
# )

return len(new_rows)

Expand All @@ -112,13 +112,13 @@ def unlink_multiple_document_tags(
if len(sdoc_ids) == 0 or len(tag_ids) == 0:
return 0

# create before state
from app.core.data.crud.source_document import crud_sdoc
# # create before state
# from app.core.data.crud.source_document import crud_sdoc

sdoc_orms = crud_sdoc.read_by_ids(db, sdoc_ids)
before_states = [
crud_sdoc._get_action_state_from_orm(sdoc_orm) for sdoc_orm in sdoc_orms
]
# sdoc_orms = crud_sdoc.read_by_ids(db, sdoc_ids)
# before_states = [
# crud_sdoc._get_action_state_from_orm(sdoc_orm) for sdoc_orm in sdoc_orms
# ]

# remove links (sdoc <-> tag)
del_rows = db.execute(
Expand All @@ -131,22 +131,22 @@ def unlink_multiple_document_tags(
).fetchall()
db.commit()

# create after state
sdoc_orms = crud_sdoc.read_by_ids(db, sdoc_ids)
after_states = [
crud_sdoc._get_action_state_from_orm(sdoc_orm) for sdoc_orm in sdoc_orms
]

# create actions
for db_obj, before_state, after_state in zip(
sdoc_orms, before_states, after_states
):
crud_sdoc._create_action(
db_obj=db_obj,
action_type=ActionType.UPDATE,
before_state=before_state,
after_state=after_state,
)
# # create after state
# sdoc_orms = crud_sdoc.read_by_ids(db, sdoc_ids)
# after_states = [
# crud_sdoc._get_action_state_from_orm(sdoc_orm) for sdoc_orm in sdoc_orms
# ]

# # create actions
# for db_obj, before_state, after_state in zip(
# sdoc_orms, before_states, after_states
# ):
# crud_sdoc._create_action(
# db_obj=db_obj,
# action_type=ActionType.UPDATE,
# before_state=before_state,
# after_state=after_state,
# )

return len(del_rows)

Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/TagHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const useCreateTag = () =>
mutationFn: DocumentTagService.createNewDocTag,
onSuccess: (tag) => {
queryClient.invalidateQueries({ queryKey: [QueryKey.PROJECT_TAGS, tag.project_id] });
queryClient.invalidateQueries({ queryKey: [QueryKey.TAG_SDOC_COUNT] });
},
});

Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/Tag/TagMenu/TagMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ function TagMenuContent({
new Map(
checked.set(
tagId,
checked.get(tagId) === CheckboxState.NOT_CHECKED || checked.get(tagId) === CheckboxState.INDETERMINATE
? CheckboxState.CHECKED
: CheckboxState.NOT_CHECKED,
checked.get(tagId) === CheckboxState.CHECKED ? CheckboxState.NOT_CHECKED : CheckboxState.CHECKED,
),
),
);
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/tableSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const tableReducer = {
// query
onSearchQueryChange: (state: Draft<TableState>, action: PayloadAction<string | undefined>) => {
state.searchQuery = action.payload;
// reset variables that depend on search parameters
state.rowSelectionModel = initialTableState.rowSelectionModel;
state.fetchSize = initialTableState.fetchSize;
},
// selection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ export const AnnotatedSegmentsSlice = createSlice({
}, {});
})
.addCase(SATFilterActions.onFinishFilterEdit, (state) => {
// reset selection when filter changes
state.rowSelectionModel = {};
// reset variables that depend on search parameters
state.rowSelectionModel = initialTableState.rowSelectionModel;
state.fetchSize = initialTableState.fetchSize;
})
.addDefaultCase(() => {});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ export const WordFrequencySlice = createSlice({
// extend filterReducer's onFinishFilterEdit
onFinishFilterEdit: (state) => {
filterReducer.onFinishFilterEdit(state);
// reset selection when filter changes
state.rowSelectionModel = {};
// reset variables that depend on search parameters
state.rowSelectionModel = initialTableState.rowSelectionModel;
state.fetchSize = initialTableState.fetchSize;
},
},
extraReducers: (builder) => {
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/views/logbook/logbookSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ const logbookSlice = createSlice({
reducers: {
...filterReducer,
...tableReducer,
// extend filterReducer's onFinishFilterEdit
onFinishFilterEdit: (state) => {
filterReducer.onFinishFilterEdit(state);
// reset variables that depend on search parameters
state.rowSelectionModel = initialTableState.rowSelectionModel;
state.fetchSize = initialTableState.fetchSize;
},
// memo search
onChangeIsSearchContent: (state, action: PayloadAction<boolean>) => {
state.isSearchContent = action.payload;
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/views/search/DocumentSearch/searchSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const searchSlice = createSlice({
delete state.rowSelectionModel[`${sdocId}`];
}
},
// tag explorer
setExpandedTagIds: (state, action: PayloadAction<string[]>) => {
state.expandedTagIds = action.payload;
},
Expand Down Expand Up @@ -188,9 +189,13 @@ export const searchSlice = createSlice({
resetProjectFilterState({ state, defaultFilterExpression, projectId: action.payload, sliceName: "search" });
})
.addMatcher(
(action) => action.type.startsWith("search/") && action.type.toLowerCase().includes("filter"),
(action) =>
(action.type.startsWith("search/onAdd") && action.type.toLowerCase().includes("filter")) || // add filter
(action.type.startsWith("search/") && action.type.includes("onFinishFilterEdit")), // edit filter
(state) => {
console.log("Search Filter Actions dispatched! Resetting fetchSize.");
console.log("Search filters changed! Resetting search parameter dependent variables.");
// reset variables that depend on search parameters
state.rowSelectionModel = initialTableState.rowSelectionModel;
state.fetchSize = initialTableState.fetchSize;
},
);
Expand Down

0 comments on commit 905cc05

Please sign in to comment.