-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/IRIS-2582-tag-management' into r…
…efactor/clean-fetch
- Loading branch information
Showing
17 changed files
with
194 additions
and
25 deletions.
There are no files selected for viewing
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 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 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 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,60 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2021 Zextras <https://www.zextras.com> | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import produce from 'immer'; | ||
import { | ||
CreateTagRequest, | ||
CreateTagResponse, | ||
TagActionRequest, | ||
TagActionResponse | ||
} from '../../types'; | ||
import { Tag } from '../../types/tags'; | ||
import { SHELL_APP_ID } from '../constants'; | ||
import { useTagStore } from '../store/tags'; | ||
import { getSoapFetch } from './fetch'; | ||
|
||
const set = useTagStore.setState; | ||
export const createTag = (tag: Omit<Tag, 'id'>): Promise<string> => | ||
getSoapFetch(SHELL_APP_ID)<CreateTagRequest, CreateTagResponse>('CreateTag', { | ||
_jsns: 'urn:zimbraMail', | ||
tag | ||
}).then((r: CreateTagResponse) => { | ||
set((state) => ({ tags: { ...state.tags, [r.tag[0].id]: r.tag[0] } })); | ||
return r.tag[0].id; | ||
}); | ||
|
||
export const deleteTag = (id: string): Promise<TagActionResponse> => | ||
getSoapFetch(SHELL_APP_ID)<TagActionRequest, TagActionResponse>('TagAction', { | ||
_jsns: 'urn:zimbraMail', | ||
action: { op: 'delete', id } | ||
}); | ||
|
||
export const renameTag = (id: string, name: string): Promise<void> => | ||
getSoapFetch(SHELL_APP_ID)<TagActionRequest, TagActionResponse>('TagAction', { | ||
_jsns: 'urn:zimbraMail', | ||
action: { op: 'rename', id, name } | ||
}).then((r: TagActionResponse) => { | ||
set( | ||
produce((state) => { | ||
state.tags[id].name = name; | ||
}) | ||
); | ||
}); | ||
export const changeTagColor = (id: string, color: string | number): Promise<void> => | ||
getSoapFetch(SHELL_APP_ID)<TagActionRequest, TagActionResponse>('TagAction', { | ||
_jsns: 'urn:zimbraMail', | ||
action: typeof color === 'number' ? { op: 'color', color, id } : { op: 'color', rgb: color, id } | ||
}).then((r: TagActionResponse) => { | ||
set( | ||
produce((state) => { | ||
if (color === 'number') { | ||
state.tags[id].color = color; | ||
} else { | ||
state.tags[id].rgb = color; | ||
} | ||
}) | ||
); | ||
}); |
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 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 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
*/ | ||
|
||
export * from './store'; | ||
export * from './hooks'; |
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,16 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2021 Zextras <https://www.zextras.com> | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import { Tag, Tags } from '../../../types'; | ||
import { useTagStore } from './store'; | ||
|
||
/* eslint-disable react-hooks/rules-of-hooks */ | ||
/* THIS FILE CONTAINS HOOKS, BUT ESLINT IS DUMB */ | ||
|
||
export const useTag = (id: string): Tag => useTagStore((s) => s.tags[id]); | ||
export const getTag = (id: string): Tag => useTagStore.getState().tags[id]; | ||
export const useTags = (): Tags => useTagStore((s) => s.tags); | ||
export const getTags = (): Tags => useTagStore.getState().tags; |
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,9 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com> | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
export * from './hooks'; | ||
export * from './store'; | ||
export * from './sync'; |
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,12 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com> | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import create, { StoreApi, UseBoundStore } from 'zustand'; | ||
import { TagState } from '../../../types'; | ||
|
||
export const useTagStore = create<TagState>(() => ({ | ||
tags: {} | ||
})) as UseBoundStore<TagState, StoreApi<TagState>>; |
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,28 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com> | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import { reduce } from 'lodash'; | ||
import { SoapContext, Tag, Tags } from '../../../types'; | ||
import { useTagStore } from './store'; | ||
|
||
export const handleTagSync = (context: SoapContext): void => { | ||
if (context.refresh?.tags?.tag) { | ||
useTagStore.setState({ | ||
tags: reduce( | ||
context.refresh.tags?.tag, | ||
(acc: Tags, val: Tag): Tags => { | ||
// eslint-disable-next-line no-param-reassign | ||
acc[val.id] = val; | ||
return acc; | ||
}, | ||
{} | ||
) | ||
}); | ||
} | ||
if (context.notify) { | ||
console.log(context.notify); | ||
} | ||
}; |
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 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 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 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 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 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,19 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com> | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
export type Tag = { | ||
color?: string; | ||
id: string; | ||
name: string; | ||
rgb?: string; | ||
}; | ||
|
||
export type Tags = Record<string, Tag>; | ||
|
||
export type TagState = { | ||
tags: Tags; | ||
}; |