@gen3/frontend 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -15508,85 +15508,26 @@ const createFacetPanel = (facet, chartType, valueLabel, hooks)=>{
15508
15508
  return null;
15509
15509
  };
15510
15510
 
15511
- const GEN3_COHORT_DISCOVERY_API = process.env.GEN3_COHORT_DISCOVERY_API || `${core.GEN3_API}/api/auth/analysis/cohortDiscovery`;
15512
-
15513
- const useGraphQLData = (url, body, skip)=>{
15514
- // Create a fetcher function that handles the GraphQL POST request
15515
- const fetcher = async (fetchUrl, fetchBody)=>{
15516
- const headers = new Headers({
15517
- Accept: 'application/json',
15518
- 'Content-Type': 'application/json'
15519
- });
15520
- if (process.env.NODE_ENV === 'development') {
15521
- // NOTE: This cookie can only be accessed from the client side
15522
- // in development mode. Otherwise, the cookie is set as httpOnly
15523
- const accessToken = cookiesNext.getCookie('credentials_token');
15524
- if (accessToken) {
15525
- headers.set('Authorization', `Bearer ${accessToken}`);
15526
- }
15527
- }
15528
- const response = await fetch(fetchUrl, {
15529
- method: 'POST',
15530
- headers: headers,
15531
- body: JSON.stringify(fetchBody)
15532
- });
15533
- if (!response.ok) {
15534
- throw new Error(`Error ${response.status}: ${response.statusText}`);
15535
- }
15536
- return await response.json();
15537
- };
15538
- // Use SWR with the fetcher
15539
- const { data, error, isLoading, mutate } = useSWR(!skip ? [
15540
- url,
15541
- body
15542
- ] : null, ([fetchUrl, fetchBody])=>fetcher(fetchUrl, fetchBody), {
15543
- revalidateOnFocus: false
15544
- });
15545
- // Format error to match your ErrorDetails interface
15546
- const formattedError = error ? {
15547
- status: error.message.match(/\d+/)?.[0] || 'Unknown',
15548
- message: error.message
15549
- } : null;
15550
- return {
15551
- data,
15552
- isLoading,
15553
- isSuccess: !!data && !error,
15554
- isError: !!error,
15555
- error: formattedError,
15556
- mutate
15557
- };
15558
- };
15559
- const useRoundedAggsQuery = ({ type, fields, filters, accessibility = core.Accessibility.ALL }, { skip } = {
15560
- skip: false
15561
- })=>{
15562
- const response = useGraphQLData(GEN3_COHORT_DISCOVERY_API, core.buildGetAggregationQuery(type, fields, filters, accessibility, false), skip);
15563
- return {
15564
- ...response,
15565
- data: response?.data?.data ? core.processHistogramResponse(response?.data.data?._aggregation[type] ?? {}) : {}
15566
- };
15567
- };
15568
-
15569
15511
  const NUM_COLS = 2; // TODO: add to config
15570
15512
  /**
15571
15513
  * CartsAndFacetsPanel component
15572
15514
  *
15573
15515
  * @param {string} index - The index type used for querying data.
15516
+ * @param data
15517
+ * @param isLoading
15518
+ * @param isError
15519
+ * @param isSuccess
15574
15520
  * @param {Array} facets - The list of facets to be rendered.
15575
15521
  * @returns {JSX.Element} The rendered component showing facets.
15576
- */ const ChartsAndFacetsPanel = ({ index, facets })=>{
15522
+ */ const ChartsAndFacetsPanel = ({ index, data, isLoading, isError, isSuccess, facets })=>{
15577
15523
  const cohortFilters = useAppSelector((state)=>selectCurrentCohortIndexFilters(state, index));
15578
- const { data, isSuccess, isLoading: isAggsQueryFetching, isError: isAggsQueryError } = useRoundedAggsQuery({
15579
- type: index,
15580
- fields: facets.map((x)=>x.field),
15581
- filters: cohortFilters
15582
- });
15583
15524
  const getEnumFacetData = useDeepCompare.useDeepCompareCallback((field)=>{
15584
15525
  return {
15585
15526
  data: processBucketData(data?.[field]),
15586
15527
  enumFilters: field in cohortFilters.root ? core.extractEnumFilterValue(cohortFilters.root[field]) : undefined,
15587
15528
  isSuccess: isSuccess,
15588
- isFetching: isAggsQueryFetching,
15589
- isError: isAggsQueryError
15529
+ isFetching: isLoading,
15530
+ isError: isError
15590
15531
  };
15591
15532
  }, [
15592
15533
  cohortFilters,
@@ -16125,6 +16066,67 @@ const CohortManager = ({ indexResources, remoteSupportService, size = 'md' })=>{
16125
16066
  });
16126
16067
  };
16127
16068
 
16069
+ process.env.GEN3_COHORT_DISCOVERY_API || `${core.GEN3_API}/api/auth/analysis/cohortDiscovery`;
16070
+
16071
+ const useGraphQLData = (url, body, skip)=>{
16072
+ // Create a fetcher function that handles the GraphQL POST request
16073
+ const csrfToken = core.useCoreSelector((state)=>core.selectCSRFToken(state));
16074
+ const fetcher = async (fetchUrl, fetchBody)=>{
16075
+ const headers = new Headers({
16076
+ Accept: 'application/json',
16077
+ 'Content-Type': 'application/json',
16078
+ 'X-CSRF-Token': csrfToken ?? ''
16079
+ });
16080
+ if (process.env.NODE_ENV === 'development') {
16081
+ // NOTE: This cookie can only be accessed from the client side
16082
+ // in development mode. Otherwise, the cookie is set as httpOnly
16083
+ const accessToken = cookiesNext.getCookie('credentials_token');
16084
+ if (accessToken) {
16085
+ headers.set('Authorization', `Bearer ${accessToken}`);
16086
+ }
16087
+ }
16088
+ const response = await fetch(fetchUrl, {
16089
+ method: 'POST',
16090
+ headers: headers,
16091
+ body: JSON.stringify(fetchBody)
16092
+ });
16093
+ if (!response.ok) {
16094
+ throw new Error(`Error ${response.status}: ${response.statusText}`);
16095
+ }
16096
+ return await response.json();
16097
+ };
16098
+ // Use SWR with the fetcher
16099
+ const { data, error, isLoading, mutate } = useSWR(!skip ? [
16100
+ url,
16101
+ body
16102
+ ] : null, ([fetchUrl, fetchBody])=>fetcher(fetchUrl, fetchBody), {
16103
+ revalidateOnFocus: false
16104
+ });
16105
+ // Format error to match your ErrorDetails interface
16106
+ const formattedError = error ? {
16107
+ status: error.message.match(/\d+/)?.[0] || 'Unknown',
16108
+ message: error.message
16109
+ } : null;
16110
+ return {
16111
+ data,
16112
+ isLoading,
16113
+ isSuccess: !!data && !error,
16114
+ isError: !!error,
16115
+ error: formattedError,
16116
+ mutate
16117
+ };
16118
+ };
16119
+ const COHORT_DISCOVERY_LIMIT$1 = process.env.NEXT_PUBLIC_GEN3_COHORT_DISCOVERY_LIMIT ? Number(process.env.NEXT_PUBLIC_GEN3_COHORT_DISCOVERY_LIMIT) : 100;
16120
+ const useUnsecureRoundedAggsQuery = ({ type, fields, filters, accessibility = core.Accessibility.ALL }, { skip } = {
16121
+ skip: false
16122
+ })=>{
16123
+ const response = useGraphQLData(`${core.GEN3_GUPPY_API}/graphql`, core.buildGetAggregationQuery(type, fields, filters, accessibility, false), skip);
16124
+ return {
16125
+ ...response,
16126
+ data: response?.data?.data ? core.processHistogramResponse(core.roundHistogramResponse(response?.data?.data._aggregation[type], COHORT_DISCOVERY_LIMIT$1)) : {}
16127
+ };
16128
+ };
16129
+
16128
16130
  const CohortQueryExpression = ({ index })=>{
16129
16131
  const currentCohortId = useAppSelector((state)=>selectCurrentCohortId(state));
16130
16132
  const currentCohortName = useAppSelector((state)=>selectCurrentCohortName(state));
@@ -16198,13 +16200,12 @@ const IndexPanel = ({ dataConfig, tabs, tabTitle, emptySelection, indexResources
16198
16200
  facetDefinitions
16199
16201
  ]);
16200
16202
  const cohortFilters = useAppSelector((state)=>selectCurrentCohortIndexFilters(state, index));
16201
- const queryFields = categories.length === 0 ? fields : activeFieldDefinitions.map((x)=>x.field);
16202
- const { data, isSuccess, isError: isAggsQueryError } = useRoundedAggsQuery({
16203
+ const { data, isSuccess, isLoading: isAggsQueryFetching, isError: isAggsQueryError } = useUnsecureRoundedAggsQuery({
16203
16204
  type: index,
16204
- fields: queryFields,
16205
+ fields: fields,
16205
16206
  filters: cohortFilters
16206
16207
  }, {
16207
- skip: queryFields.length === 0
16208
+ skip: fields.length === 0
16208
16209
  });
16209
16210
  const updateFields = useDeepCompare.useDeepCompareCallback((field, checked)=>{
16210
16211
  if (!checked) {
@@ -16290,6 +16291,10 @@ const IndexPanel = ({ dataConfig, tabs, tabTitle, emptySelection, indexResources
16290
16291
  remoteSupportService: remoteSupportService
16291
16292
  }),
16292
16293
  selectedFacets.length > 0 ? /*#__PURE__*/ jsxRuntime.jsx(ChartsAndFacetsPanel, {
16294
+ data: data,
16295
+ isLoading: isAggsQueryFetching,
16296
+ isError: isAggsQueryError,
16297
+ isSuccess: isSuccess,
16293
16298
  index: index,
16294
16299
  facets: activeFieldDefinitions
16295
16300
  }) : /*#__PURE__*/ jsxRuntime.jsx(core$1.Center, {