mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
console: remove old metadata hooks
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9118 GitOrigin-RevId: dc1e2131d647be60c43bdffebebe0e116c834764
This commit is contained in:
parent
770407110c
commit
573c3e3093
@ -1,22 +1,25 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import AceEditor from 'react-ace';
|
import AceEditor from 'react-ace';
|
||||||
import { useFormContext } from 'react-hook-form';
|
import { useFormContext } from 'react-hook-form';
|
||||||
import { MetadataTable, Table } from '../../../hasura-metadata-types';
|
|
||||||
import { useHttpClient } from '../../../Network';
|
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
import { DataSource, exportMetadata, Operator } from '../../../DataSource';
|
import { getIngForm } from '../../../../components/Services/Data/utils';
|
||||||
import { areTablesEqual } from '../../../hasura-metadata-api';
|
|
||||||
import { getTypeName } from '../../../GraphQLUtils';
|
|
||||||
import { InputField } from '../../../../new-components/Form';
|
import { InputField } from '../../../../new-components/Form';
|
||||||
import { IconTooltip } from '../../../../new-components/Tooltip';
|
import { IconTooltip } from '../../../../new-components/Tooltip';
|
||||||
import { Collapse } from '../../../../new-components/deprecated';
|
import { Collapse } from '../../../../new-components/deprecated';
|
||||||
import { getIngForm } from '../../../../components/Services/Data/utils';
|
import { DataSource, Operator, exportMetadata } from '../../../DataSource';
|
||||||
import { RowPermissionBuilder } from './RowPermissionsBuilder';
|
import { getTypeName } from '../../../GraphQLUtils';
|
||||||
|
import { useHttpClient } from '../../../Network';
|
||||||
|
import {
|
||||||
|
MetadataSelectors,
|
||||||
|
areTablesEqual,
|
||||||
|
useMetadata,
|
||||||
|
} from '../../../hasura-metadata-api';
|
||||||
|
import { Table } from '../../../hasura-metadata-types';
|
||||||
import { QueryType } from '../../types';
|
import { QueryType } from '../../types';
|
||||||
import { ReturnValue } from '../hooks';
|
import { ReturnValue } from '../hooks';
|
||||||
import { useMetadataTable } from '../../../hasura-metadata-api/metadataHooks';
|
|
||||||
import { getNonSelectedQueryTypePermissions } from '../utils/getMapQueryTypePermissions';
|
|
||||||
import { copyQueryTypePermissions } from '../utils/copyQueryTypePermissions';
|
import { copyQueryTypePermissions } from '../utils/copyQueryTypePermissions';
|
||||||
|
import { getNonSelectedQueryTypePermissions } from '../utils/getMapQueryTypePermissions';
|
||||||
|
import { RowPermissionBuilder } from './RowPermissionsBuilder';
|
||||||
|
|
||||||
const NoChecksLabel = () => (
|
const NoChecksLabel = () => (
|
||||||
<span data-test="without-checks">Without any checks </span>
|
<span data-test="without-checks">Without any checks </span>
|
||||||
@ -139,10 +142,13 @@ export const RowPermissionsSection: React.FC<RowPermissionsProps> = ({
|
|||||||
roleName,
|
roleName,
|
||||||
}) => {
|
}) => {
|
||||||
const { data: tableName, isLoading } = useTypeName({ table, dataSourceName });
|
const { data: tableName, isLoading } = useTypeName({ table, dataSourceName });
|
||||||
const metadataTable = useMetadataTable(dataSourceName, table);
|
|
||||||
|
const { data: metadataTable } = useMetadata(
|
||||||
|
MetadataSelectors.findTable(dataSourceName, table)
|
||||||
|
);
|
||||||
|
|
||||||
const nonSelectedQueryTypePermissions = getNonSelectedQueryTypePermissions(
|
const nonSelectedQueryTypePermissions = getNonSelectedQueryTypePermissions(
|
||||||
metadataTable?.data as MetadataTable,
|
metadataTable,
|
||||||
queryType,
|
queryType,
|
||||||
roleName
|
roleName
|
||||||
);
|
);
|
||||||
|
@ -53,7 +53,7 @@ const getPermissionsMappedByRole = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getNonSelectedQueryTypePermissions = (
|
export const getNonSelectedQueryTypePermissions = (
|
||||||
tableData: MetadataTable,
|
tableData: MetadataTable | undefined,
|
||||||
currentQueryType: string,
|
currentQueryType: string,
|
||||||
currentRole: string
|
currentRole: string
|
||||||
) => {
|
) => {
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
import { useQuery } from 'react-query';
|
|
||||||
import { exportMetadata } from '../DataSource';
|
|
||||||
import { Table } from '../hasura-metadata-types';
|
|
||||||
import { useHttpClient } from '../Network';
|
|
||||||
import { DEFAULT_STALE_TIME } from '../DatabaseRelationships';
|
|
||||||
import { areTablesEqual } from './areTablesEqual';
|
|
||||||
|
|
||||||
export const useMetadata = () => {
|
|
||||||
const httpClient = useHttpClient();
|
|
||||||
return useQuery({
|
|
||||||
queryKey: ['export_metadata'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const result = await exportMetadata({ httpClient });
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
refetchOnWindowFocus: false,
|
|
||||||
staleTime: DEFAULT_STALE_TIME,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useResourceVersion = () => {
|
|
||||||
const { data: result, isFetching } = useMetadata();
|
|
||||||
return useQuery({
|
|
||||||
queryKey: ['export_metadata', 'resource_version'],
|
|
||||||
queryFn: async () => {
|
|
||||||
if (!result) throw Error('Unable to find metadata');
|
|
||||||
|
|
||||||
const { resource_version } = result;
|
|
||||||
return resource_version;
|
|
||||||
},
|
|
||||||
refetchOnWindowFocus: false,
|
|
||||||
enabled: !isFetching,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useMetadataSource = (dataSourceName: string) => {
|
|
||||||
const { data: result, isFetching } = useMetadata();
|
|
||||||
return useQuery({
|
|
||||||
queryKey: ['export_metadata', dataSourceName],
|
|
||||||
queryFn: async () => {
|
|
||||||
const metadataSource = result?.metadata.sources.find(
|
|
||||||
s => s.name === dataSourceName
|
|
||||||
);
|
|
||||||
return metadataSource;
|
|
||||||
},
|
|
||||||
enabled: !isFetching,
|
|
||||||
refetchOnWindowFocus: false,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useMetadataTable = (dataSourceName: string, table: Table) => {
|
|
||||||
const { data: metadataSource, isFetching } =
|
|
||||||
useMetadataSource(dataSourceName);
|
|
||||||
return useQuery({
|
|
||||||
queryKey: ['export_metadata', dataSourceName, table],
|
|
||||||
queryFn: async () => {
|
|
||||||
const metadataTable = metadataSource?.tables.find(t =>
|
|
||||||
areTablesEqual(t.table, table)
|
|
||||||
);
|
|
||||||
return metadataTable;
|
|
||||||
},
|
|
||||||
enabled: !isFetching,
|
|
||||||
refetchOnWindowFocus: false,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useMetadataTables = (dataSourceName: string) => {
|
|
||||||
const { data: metadataSource, isFetching } =
|
|
||||||
useMetadataSource(dataSourceName);
|
|
||||||
return useQuery({
|
|
||||||
queryKey: ['export_metadata', dataSourceName, 'tables'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const metadataTables = metadataSource?.tables;
|
|
||||||
return metadataTables;
|
|
||||||
},
|
|
||||||
enabled: !isFetching && !!dataSourceName,
|
|
||||||
refetchOnWindowFocus: false,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useMetadataSources = () => {
|
|
||||||
const { data: metadata, isFetching } = useMetadata();
|
|
||||||
return useQuery({
|
|
||||||
queryKey: ['export_metadata', 'sources'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const metadataSources = metadata?.metadata.sources;
|
|
||||||
return metadataSources;
|
|
||||||
},
|
|
||||||
enabled: !isFetching,
|
|
||||||
refetchOnWindowFocus: false,
|
|
||||||
});
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user