-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'to-redux-toolkit-tableFilterProfiles' of Arnei/opencast…
…-admin-interface into admin-ui-picard Pull request #303 Modernize redux: tableFilterProfilesSlice
- Loading branch information
Showing
6 changed files
with
93 additions
and
124 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { RootState } from "../store"; | ||
/** | ||
* This file contains selectors regarding filter profiles | ||
*/ | ||
|
||
export const getFilterProfiles = (state: any) => state.tableFilterProfiles.profiles; | ||
export const getFilterProfiles = (state: RootState) => state.tableFilterProfiles.profiles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { PayloadAction, createSlice } from '@reduxjs/toolkit' | ||
|
||
/** | ||
* This file contains redux reducer for actions affecting the state of table filter profiles | ||
*/ | ||
|
||
type FilterProfile = { | ||
name: string, | ||
description: string, | ||
resource: string, | ||
filterMap: { | ||
label: string, | ||
name: string | ||
options: { | ||
label: string, | ||
value: string, | ||
}[], | ||
translatable: false, | ||
type: string, | ||
value: string, | ||
}[] | ||
} | ||
|
||
type TableFilterProfilesState = { | ||
profiles: FilterProfile[] | ||
} | ||
|
||
// Initial state of filter profiles in redux store | ||
const initialState: TableFilterProfilesState = { | ||
profiles: [] | ||
}; | ||
|
||
const tableFilterProfileSlice = createSlice({ | ||
name: 'tableFilterProfiles', | ||
initialState, | ||
reducers: { | ||
createFilterProfile(state, action: PayloadAction< | ||
FilterProfile | ||
>) { | ||
const filterProfile = action.payload; | ||
state.profiles = state.profiles.concat(filterProfile) | ||
}, | ||
editFilterProfile(state, action: PayloadAction< | ||
FilterProfile | ||
>) { | ||
const updatedFilterProfile = action.payload; | ||
state.profiles = state.profiles.map((filterProfile) => { | ||
if (filterProfile.name === updatedFilterProfile.name) { | ||
return updatedFilterProfile; | ||
} | ||
return filterProfile; | ||
}) | ||
}, | ||
removeFilterProfile(state, action: PayloadAction< | ||
FilterProfile | ||
>) { | ||
const filterProfileToRemove = action.payload; | ||
state.profiles = state.profiles.filter( | ||
(filterProfile) => filterProfile.name !== filterProfileToRemove.name | ||
) | ||
}, | ||
cancelEditFilterProfile(state) { | ||
return | ||
} | ||
}, | ||
}); | ||
|
||
export const { | ||
createFilterProfile, | ||
editFilterProfile, | ||
removeFilterProfile, | ||
cancelEditFilterProfile, | ||
} = tableFilterProfileSlice.actions; | ||
|
||
// Export the slice reducer as the default export | ||
export default tableFilterProfileSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters