-
Notifications
You must be signed in to change notification settings - Fork 72
/
data-qualifier.slice.ts
73 lines (65 loc) · 2.14 KB
/
data-qualifier.slice.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { createSelector, createSlice } from "@reduxjs/toolkit";
import type { RootState } from "~/app/store";
import { baseApi } from "~/features/common/api.slice";
import { DataQualifier } from "~/types/api";
const dataQualifierApi = baseApi.injectEndpoints({
endpoints: (build) => ({
getAllDataQualifiers: build.query<DataQualifier[], void>({
query: () => ({ url: `data_qualifier/` }),
providesTags: () => ["Data Qualifiers"],
transformResponse: (qualifiers: DataQualifier[]) =>
qualifiers.sort((a, b) => a.fides_key.localeCompare(b.fides_key)),
}),
updateDataQualifier: build.mutation<
DataQualifier,
Partial<DataQualifier> & Pick<DataQualifier, "fides_key">
>({
query: (dataQualifier) => ({
url: `data_qualifier/`,
params: { resource_type: "data_qualifier" },
method: "PUT",
body: dataQualifier,
}),
invalidatesTags: ["Data Qualifiers"],
}),
createDataQualifier: build.mutation<DataQualifier, DataQualifier>({
query: (dataQualifier) => ({
url: `data_qualifier/`,
method: "POST",
body: dataQualifier,
}),
invalidatesTags: ["Data Qualifiers"],
}),
deleteDataQualifier: build.mutation<string, string>({
query: (key) => ({
url: `data_qualifier/${key}`,
params: { resource_type: "data_qualifier" },
method: "DELETE",
}),
invalidatesTags: ["Data Qualifiers"],
}),
}),
});
export const {
useGetAllDataQualifiersQuery,
useUpdateDataQualifierMutation,
useCreateDataQualifierMutation,
useDeleteDataQualifierMutation,
} = dataQualifierApi;
export interface State {}
const initialState: State = {};
export const dataQualifierSlice = createSlice({
name: "dataQualifier",
initialState,
reducers: {},
});
export const { reducer } = dataQualifierSlice;
const emptyDataQualifiers: DataQualifier[] = [];
export const selectDataQualifiers: (state: RootState) => DataQualifier[] =
createSelector(
[
(RootState) => RootState,
dataQualifierApi.endpoints.getAllDataQualifiers.select(),
],
(RootState, { data }) => data ?? emptyDataQualifiers
);