(
state: ReverseState[],
action: PayloadAction<Partial<BackendState>>,
)
| 57 | builder.addCase(STATE_RECEIVE, updateState); |
| 58 | builder.addCase(STATE_UPDATE, updateState); |
| 59 | function updateState( |
| 60 | state: ReverseState[], |
| 61 | action: PayloadAction<Partial<BackendState>>, |
| 62 | ) { |
| 63 | if (action.payload.servers) { |
| 64 | // action.data.servers does not include servers that are currently inactive, |
| 65 | // but we want to keep them in the UI. So we need to merge UI state with what we got from the server. |
| 66 | |
| 67 | const activeServers = Object.fromEntries( |
| 68 | Object.entries(action.payload.servers) |
| 69 | .filter(([_, info]) => info.type === "reverse") |
| 70 | .map(([spec, _]) => [spec, parseSpec(spec)]), |
| 71 | ); |
| 72 | |
| 73 | const nextState: ReverseState[] = []; |
| 74 | |
| 75 | // keep current UI state as is, but correct `active` bit. |
| 76 | for (const server of state) { |
| 77 | const spec = getSpec(server); |
| 78 | const active = spec in activeServers; |
| 79 | delete activeServers[spec]; |
| 80 | nextState.push({ |
| 81 | ...server, |
| 82 | active, |
| 83 | }); |
| 84 | } |
| 85 | |
| 86 | // add all new specs |
| 87 | for (const x of Object.values(activeServers)) { |
| 88 | nextState.push(parseRaw(x)); |
| 89 | } |
| 90 | |
| 91 | // remove default config if still present. |
| 92 | if ( |
| 93 | nextState.length > 1 && |
| 94 | shallowEqual( |
| 95 | { |
| 96 | ...nextState[0], |
| 97 | ui_id: undefined, |
| 98 | } as ReverseState, |
| 99 | { |
| 100 | ...defaultReverseState(), |
| 101 | ui_id: undefined, |
| 102 | } as ReverseState, |
| 103 | ) |
| 104 | ) { |
| 105 | nextState.shift(); |
| 106 | } |
| 107 | |
| 108 | return nextState; |
| 109 | } |
| 110 | } |
| 111 | }, |
| 112 | }); |
| 113 | export const { addServer, removeServer } = reverseSlice.actions; |
nothing calls this directly
no test coverage detected
searching dependent graphs…