-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@leav/ui): init an api call to get data
- Loading branch information
Showing
8 changed files
with
132 additions
and
18 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 |
---|---|---|
@@ -1,18 +1,12 @@ | ||
// Copyright LEAV Solutions 2017 | ||
// This file is released under LGPL V3 | ||
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt | ||
import {FunctionComponent, useState} from 'react'; | ||
import {IDataGroupedFilteredSorted} from '_ui/components/Explorer/types'; | ||
import {FunctionComponent} from 'react'; | ||
import {DataView} from './DataView'; | ||
import {useExplorerData} from './useExplorerData'; | ||
|
||
export const Explorer: FunctionComponent<{library: string}> = ({library}) => { | ||
// TODO: make API call | ||
const [data, setData] = useState<IDataGroupedFilteredSorted[] | null>(null); | ||
const {data, loading} = useExplorerData(library); | ||
|
||
return ( | ||
<div> | ||
This is the Explorer! on library {library} | ||
{data === null ? 'Loading...' : <DataView data={data} />} | ||
</div> | ||
); | ||
return <div>{loading ? 'Loading...' : <DataView dataGroupedFilteredSorted={data ?? []} />}</div>; | ||
}; |
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,17 @@ | ||
query Explorer($libraryId: ID!) { | ||
records(library: $libraryId) { | ||
list { | ||
id | ||
whoAmI { | ||
label | ||
subLabel | ||
preview | ||
id | ||
color | ||
library { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"strictNullChecks": true, | ||
} | ||
} |
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,8 +1,10 @@ | ||
// Copyright LEAV Solutions 2017 | ||
// This file is released under LGPL V3 | ||
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt | ||
export interface IDataGroupedFilteredSorted { | ||
import {ExplorerQuery} from '_ui/_gqlTypes'; | ||
|
||
export type IDataGroupedFilteredSorted<Field extends keyof ExplorerQuery['records']['list'][number]> = Array<{ | ||
libraryId: string; | ||
itemId: string; | ||
value: Record<string, unknown>; | ||
} | ||
value: Required<ExplorerQuery['records']['list'][number][Field]>; | ||
}>; |
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,27 @@ | ||
// Copyright LEAV Solutions 2017 | ||
// This file is released under LGPL V3 | ||
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt | ||
import {IDataGroupedFilteredSorted} from './types'; | ||
import {ExplorerQuery, useExplorerQuery} from '_ui/_gqlTypes'; | ||
|
||
const _mapping = (data: ExplorerQuery, libraryId: string): IDataGroupedFilteredSorted<'whoAmI'> => | ||
data.records.list.map(({id, whoAmI}) => ({ | ||
libraryId, | ||
itemId: id, | ||
value: { | ||
label: null, | ||
subLabel: null, | ||
color: null, | ||
preview: null, | ||
...whoAmI | ||
} | ||
})); | ||
|
||
export const useExplorerData = (libraryId: string) => { | ||
const {data, loading} = useExplorerQuery({variables: {libraryId}}); | ||
|
||
return { | ||
data: data !== undefined ? _mapping(data, libraryId) : null, | ||
loading | ||
}; | ||
}; |