Skip to content

Commit

Permalink
partial: deprecate FIELDS
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaquiery committed Jan 22, 2025
1 parent 9afc5c9 commit 9187b9a
Show file tree
Hide file tree
Showing 46 changed files with 704 additions and 599 deletions.
8 changes: 4 additions & 4 deletions cypress/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ describe('template spec', () => {
cy.intercept(
{
method: 'GET',
url: `${PATHS.CELL}`,
url: `${PATHS.Cell}`,
},
{ fixture: PATHS.CELL.replace(/^\//, '') },
{ fixture: PATHS.Cell.replace(/^\//, '') },
)
cy.intercept(
{
method: 'GET',
url: `${PATHS.CELL}/*`,
url: `${PATHS.Cell}/*`,
},
async (req) => {
const id = req.url.split('/').pop()
const cells = await cy.fixture(PATHS.CELL.replace(/^\//, ''))
const cells = await cy.fixture(PATHS.Cell.replace(/^\//, ''))
req.reply({
body: cells.results.find((cell) => cell.uuid === id),
})
Expand Down
34 changes: 17 additions & 17 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function Core() {
<Divider component="li" key="div0">
{open && 'Outputs'}
</Divider>
{[LOOKUP_KEYS.EXPERIMENT, LOOKUP_KEYS.CYCLER_TEST].map(
{[LOOKUP_KEYS.Experiment, LOOKUP_KEYS.CyclerTest].map(
(lookupKey) => (
<LI key={lookupKey} lookupKey={lookupKey} />
),
Expand All @@ -127,33 +127,33 @@ export function Core() {
{open && 'Resources'}
</Divider>
{[
LOOKUP_KEYS.FILE,
LOOKUP_KEYS.CELL,
LOOKUP_KEYS.EQUIPMENT,
LOOKUP_KEYS.SCHEDULE,
LOOKUP_KEYS.ARBITRARY_FILE,
LOOKUP_KEYS.File,
LOOKUP_KEYS.Cell,
LOOKUP_KEYS.Equipment,
LOOKUP_KEYS.Schedule,
LOOKUP_KEYS.ArbitraryFile,
].map((lookupKey) => (
<LI key={lookupKey} lookupKey={lookupKey} />
))}
<Divider component="li" key="div3">
{open && 'Inputs'}
</Divider>
{[
LOOKUP_KEYS.PATH,
LOOKUP_KEYS.VALIDATION_SCHEMA,
LOOKUP_KEYS.COLUMN_FAMILY,
LOOKUP_KEYS.UNIT,
LOOKUP_KEYS.Path,
LOOKUP_KEYS.ValidationSchema,
LOOKUP_KEYS.ColumnFamily,
LOOKUP_KEYS.Unit,
].map((lookupKey) => (
<LI key={lookupKey} lookupKey={lookupKey} />
))}
<Divider component="li" key="div4">
{open && 'Management'}
</Divider>
{[
LOOKUP_KEYS.LAB,
LOOKUP_KEYS.TEAM,
LOOKUP_KEYS.HARVESTER,
LOOKUP_KEYS.ADDITIONAL_STORAGE,
LOOKUP_KEYS.Lab,
LOOKUP_KEYS.Team,
LOOKUP_KEYS.Harvester,
LOOKUP_KEYS.AdditionalStorage,
].map((lookupKey) => (
<LI key={lookupKey} lookupKey={lookupKey} />
))}
Expand Down Expand Up @@ -275,7 +275,7 @@ export function Core() {
return (
<ResourceCard
resourceId={id ?? -1}
lookupKey={lookupKey ?? 'CYCLER_TEST'}
lookupKey={lookupKey ?? 'CyclerTest'}
expanded={true}
editing={searchParams.get('editing') === 'true'}
/>
Expand All @@ -292,7 +292,7 @@ export function Core() {
return <></>
}

return <ResourceList lookupKey={lookupKey ?? 'CYCLER_TEST'} />
return <ResourceList lookupKey={lookupKey ?? 'CyclerTest'} />
}

/* A <Routes> looks through its children <Route>s and renders the first one that matches the current URL. */
Expand All @@ -302,7 +302,7 @@ export function Core() {
<Route path={PATHS.DASHBOARD} element={Layout}>
{/*<Route path={PATHS.GRAPH} element={<DatasetChart />} />*/}
<Route
path={`${PATHS.MAPPING}/:id`}
path={`${PATHS.ColumnMapping}/:id`}
element={<Mapping />}
/>
{/* Handle direct resource lookups */}
Expand Down
2 changes: 1 addition & 1 deletion src/ClientCodeDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function DatasetSelector({
fileQueryLimit?: number
}) {
const { useListQuery } = useFetchResource()
const query = useListQuery(LOOKUP_KEYS.FILE, {
const query = useListQuery(LOOKUP_KEYS.File, {
limit: fileQueryLimit ?? DEFAULT_FETCH_LIMIT,
})

Expand Down
6 changes: 5 additions & 1 deletion src/Components/ApiResourceContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ export const get_select_function =
<T,>(lookupKey: LookupKey) =>
(data: AxiosResponse<GalvResource>) => {
Object.entries(FIELDS[lookupKey]).forEach(([k, v]) => {
if (has(v, 'transformation'))
if (has(v, 'transformation')) {
console.warn(
`[FIELDS deprecation] ${lookupKey}.${k} has a transformation`,
)
data.data[k as keyof typeof data.data] = v.transformation(
data.data[k as keyof typeof data.data],
)
}
})
return data as AxiosResponse<T>
}
Expand Down
4 changes: 2 additions & 2 deletions src/Components/AttachmentUploadContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export default function AttachmentUploadContextProvider({
},
onSuccess: async (data: AxiosResponse<ArbitraryFile>) => {
queryClient.setQueryData(
[LOOKUP_KEYS.ARBITRARY_FILE, data.data.id],
[LOOKUP_KEYS.ArbitraryFile, data.data.id],
data.data,
)
await queryClient.invalidateQueries({
queryKey: [LOOKUP_KEYS.ARBITRARY_FILE, 'list'],
queryKey: [LOOKUP_KEYS.ArbitraryFile, 'list'],
})
callback(data.data.url)
},
Expand Down
2 changes: 1 addition & 1 deletion src/Components/AuthImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function AuthImage({
'Galv-Storage-No-Redirect': true,
}
const query = useQuery({
queryKey: [LOOKUP_KEYS.FILE, file.id, 'png'],
queryKey: [LOOKUP_KEYS.File, file.id, 'png'],
queryFn: async () => {
const response = await axios.get(file.png, {
headers,
Expand Down
28 changes: 22 additions & 6 deletions src/Components/CardActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { has_value, id_from_ref_props } from './misc'
import clsx from 'clsx'
import UseStyles from '../styles/UseStyles'
import { useSelectionManagement } from './SelectionManagementContext'
import { representation } from './Representation'
import { genericRepresentation } from './representation/GenericRepresentation'
import SafeTooltip from './SafeTooltip'

export type CardActionBarProps = {
Expand Down Expand Up @@ -67,17 +67,33 @@ export type CardActionBarProps = {
*/
export default function CardActionBar(props: CardActionBarProps) {
const { classes, theme } = UseStyles()
const { apiResource } = useApiResource()
const { apiResource, apiResourceDescription } = useApiResource()
const iconProps: Partial<SvgIconProps> = {
...props.iconProps,
}
const selectable = props.selectable ?? typeof apiResource?.id === 'string'
const { toggleSelected, isSelected } = useSelectionManagement()

// Check differences between FIELDS context and apiResourceDescription context
const api_context = Object.values(apiResourceDescription ?? {}).filter(
(e) => e.galv_resource,
)
const fields_context = Object.values(FIELDS[props.lookupKey]).filter((e) =>
is_lookupKey(e.type),
)
// const api_only = api_context.filter((e) => !fields_context.includes(e))
const fields_only = fields_context.filter((e) => !api_context.includes(e))
if (fields_only.length > 0) {
console.warn(
`[FIELDS deprecation] FIELD[${props.lookupKey}] has fields not present in apiResourceDescription.`,
fields_only,
)
}

const context_section = (
<>
{Object.entries(FIELDS[props.lookupKey])
.filter((e) => is_lookupKey(e[1].type))
{Object.entries(apiResourceDescription ?? {})
.filter((e) => e[1].galv_resource)
.map(([k, v]) => {
const relative_lookupKey = v.type as LookupKey
let content: ReactNode
Expand Down Expand Up @@ -225,7 +241,7 @@ export default function CardActionBar(props: CardActionBarProps) {

const destroy_section = (
<Stack direction="row" spacing={1} alignItems="center">
{props.lookupKey === LOOKUP_KEYS.FILE && props.reimportable && (
{props.lookupKey === LOOKUP_KEYS.File && props.reimportable && (
<SafeTooltip
title="Force the harvester to re-import this file"
arrow
Expand Down Expand Up @@ -291,7 +307,7 @@ export default function CardActionBar(props: CardActionBarProps) {
{props.onFork && apiResource && (
<SafeTooltip
title={`
Create your own copy of ${representation({ data: apiResource, lookupKey: props.lookupKey })}
Create your own copy of ${genericRepresentation({ data: apiResource, lookupKey: props.lookupKey })}
`}
arrow
describeChild
Expand Down
4 changes: 2 additions & 2 deletions src/Components/CurrentUserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ export default function CurrentUserContextProvider({
})

const Refresh = useQuery({
queryKey: [LOOKUP_KEYS.USER, 'refresh'],
queryKey: [LOOKUP_KEYS.User, 'refresh'],
queryFn: () => {
if (!user) return
const api = new API_HANDLERS[LOOKUP_KEYS.USER](api_config)
const api = new API_HANDLERS[LOOKUP_KEYS.User](api_config)
return api
.usersRetrieve({ id: user.id })
.then((response: AxiosResponse<User>) => {
Expand Down
5 changes: 3 additions & 2 deletions src/Components/FetchResourceContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export type FieldDescription = {
| 'choice'
| 'json'
| string
many: boolean
galv_resource: boolean // Whether the `type` is a Galv Resource
many: boolean // Whether the field is a list
help_text: string
required: boolean
read_only: boolean
Expand Down Expand Up @@ -558,7 +559,7 @@ export default function FetchResourceContextProvider({
queryClient.invalidateQueries({
queryKey: [lookupKey, 'list'],
})
if (lookupKey === LOOKUP_KEYS.LAB) {
if (lookupKey === LOOKUP_KEYS.Lab) {
refresh_user()
}
// Invalidate autocomplete cache
Expand Down
22 changes: 11 additions & 11 deletions src/Components/Mapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function CreateColumnType({
onCreate(new_resource_url)
}}
onDiscard={() => setOpen(false)}
lookupKey={LOOKUP_KEYS.COLUMN_FAMILY}
lookupKey={LOOKUP_KEYS.ColumnFamily}
/>
</UndoRedoProvider>
</>
Expand All @@ -184,7 +184,7 @@ function SelectColumnType({
reset_name: string
}) {
const { useListQuery } = useFetchResource()
const query = useListQuery<DataColumnType>(LOOKUP_KEYS.COLUMN_FAMILY)
const query = useListQuery<DataColumnType>(LOOKUP_KEYS.ColumnFamily)
const { classes } = useStyles()
const [createModalOpen, setCreateModalOpen] = useState(false)

Expand Down Expand Up @@ -826,7 +826,7 @@ function MappingManager({
})
const { classes } = useStyles()
const { useListQuery, useCreateQuery, useUpdateQuery } = useFetchResource()
const col_query = useListQuery<DataColumnType>(LOOKUP_KEYS.COLUMN_FAMILY)
const col_query = useListQuery<DataColumnType>(LOOKUP_KEYS.ColumnFamily)
const [more, setMore] = React.useState(false)
const [advancedPropertiesOpen, setAdvancedPropertiesOpen] =
React.useState(false)
Expand All @@ -838,14 +838,14 @@ function MappingManager({
return m ? { ...m } : blank_map()
})
const navigate = useNavigate()
const updateFileMutation = useUpdateQuery<ObservedFile>(LOOKUP_KEYS.FILE)
const updateFileMutation = useUpdateQuery<ObservedFile>(LOOKUP_KEYS.File)
const updateFile = (new_mapping: DB_MappingResource) =>
updateFileMutation.mutate(
{ ...file!, mapping: new_mapping.url },
{ onSuccess: () => navigate(0) },
)
const createMapMutation = useCreateQuery<DB_MappingResource>(
LOOKUP_KEYS.MAPPING,
LOOKUP_KEYS.ColumnMapping,
{ after_cache: (r) => updateFile(r.data) },
)
const createMap = (data: ApplicableMappingResource) => {
Expand All @@ -864,12 +864,12 @@ function MappingManager({
})
}
const updateMapMutation = useUpdateQuery<DB_MappingResource>(
LOOKUP_KEYS.MAPPING,
LOOKUP_KEYS.ColumnMapping,
)
const updateMap = (data: DB_MappingResource) =>
updateMapMutation.mutate(data, { onSuccess: () => navigate(0) })
// TODO: Implement deleteMapMutation when backend supplies delete permissions
// const deleteMapMutation = useDeleteQuery<DB_MappingResource>(LOOKUP_KEYS.MAPPING)
// const deleteMapMutation = useDeleteQuery<DB_MappingResource>(LOOKUP_KEYS.ColumnMapping)
// const deleteMap = (data: DB_MappingResource) => deleteMapMutation.mutate(data, {onSuccess: () => navigate(0)})

if (col_query?.hasNextPage && !col_query.isFetchingNextPage)
Expand Down Expand Up @@ -963,7 +963,7 @@ function MappingManager({
{file?.id && (
<ResourceChip
resourceId={file.id as string}
lookupKey={LOOKUP_KEYS.FILE}
lookupKey={LOOKUP_KEYS.File}
/>
)}
</Typography>
Expand Down Expand Up @@ -1231,12 +1231,12 @@ Do you wish to continue?`)
<PrettyResource
target={{
_type: key_to_type(
LOOKUP_KEYS.TEAM,
LOOKUP_KEYS.Team,
),
_value: mapping.mapping
.team,
}}
lookupKey={LOOKUP_KEYS.TEAM}
lookupKey={LOOKUP_KEYS.Team}
edit_mode={true}
allow_new={false}
onChange={(
Expand Down Expand Up @@ -1498,7 +1498,7 @@ export default function WrappedMapping() {
>
<ApiResourceContextProvider
resourceId={id}
lookupKey={LOOKUP_KEYS.FILE}
lookupKey={LOOKUP_KEYS.File}
>
<Mapping />
</ApiResourceContextProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/Components/ResourceChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import QueryWrapper, { QueryWrapperProps } from './QueryWrapper'
import ErrorChip from './error/ErrorChip'
import { FAMILY_LOOKUP_KEYS, GalvResource, PATHS } from '../constants'
import ErrorBoundary from './ErrorBoundary'
import Representation from './Representation'
import Representation from './representation/GenericRepresentation'
import { FilterContext } from './filtering/FilterContext'
import ApiResourceContextProvider, {
ApiResourceContextProviderProps,
Expand Down
Loading

0 comments on commit 9187b9a

Please sign in to comment.