-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replacing use of store with
useQuery
for content packs. (#21358)
* Replacing use of store with `useQuery` for content packs. * Introducing hook, make `ContentPacksPage` use it instead of store. * Adding license headers. * Improving typing. * Fixing linter hint.
- Loading branch information
1 parent
bba32b0
commit 04214af
Showing
11 changed files
with
203 additions
and
86 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
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 |
---|---|---|
|
@@ -30,7 +30,7 @@ describe('<ContentPackListItem />', () => { | |
server_version: '6.0.0-SNAPSHOT', | ||
summary: 'The Open Thread Exchange Lookup Table of the Threat Intel Plugin', | ||
url: 'https://github.com/Graylog2/graylog2-server', | ||
v: 1, | ||
v: '1', | ||
vendor: 'Graylog <[email protected]>', | ||
}; | ||
|
||
|
25 changes: 25 additions & 0 deletions
25
graylog2-web-interface/src/components/content-packs/hooks/useContentPackInstallations.ts
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,25 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { SystemContentPacks } from '@graylog/server-api'; | ||
|
||
const useContentPackInstallations = (id: string) => useQuery( | ||
['content-packs', 'installations', id], | ||
() => SystemContentPacks.listContentPackInstallationsById(id), | ||
); | ||
export default useContentPackInstallations; |
43 changes: 43 additions & 0 deletions
43
graylog2-web-interface/src/components/content-packs/hooks/useContentPackRevisions.ts
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,43 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { SystemContentPacks } from '@graylog/server-api'; | ||
|
||
import ContentPackRevisions from 'logic/content-packs/ContentPackRevisions'; | ||
import { onError } from 'util/conditional/onError'; | ||
import UserNotification from 'util/UserNotification'; | ||
|
||
const fetchContentPackRevisions = async (id: string) => { | ||
const response = await SystemContentPacks.listContentPackRevisions(id); | ||
const contentPackRevision = new ContentPackRevisions(response.content_pack_revisions); | ||
const constraints = response.constraints_result; | ||
|
||
return { | ||
contentPackRevisions: contentPackRevision, | ||
selectedVersion: contentPackRevision.latestRevision, | ||
constraints: constraints, | ||
}; | ||
}; | ||
|
||
const defaultErrorHandler = (error: Error) => UserNotification.error(`Error while fetching content pack revisions: ${error}`, 'Unable to fetch content pack'); | ||
|
||
const useContentPackRevisions = (id: string, onFetchError: (e: Error) => void = defaultErrorHandler) => useQuery( | ||
['content-packs', 'revisions', id], | ||
() => onError(fetchContentPackRevisions(id), onFetchError), | ||
); | ||
export default useContentPackRevisions; |
22 changes: 22 additions & 0 deletions
22
graylog2-web-interface/src/components/content-packs/hooks/useContentPacks.ts
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,22 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { SystemContentPacks } from '@graylog/server-api'; | ||
|
||
const useContentPacks = () => useQuery(['content-packs', 'list'], () => SystemContentPacks.listContentPacks()); | ||
export default useContentPacks; |
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
Oops, something went wrong.