Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for inclusion of orphans in verbatim PFB (#264) #269

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ export const DownloadCurlCommand = ({
DownloadCurlStart,
DownloadCurlSuccess,
fileManifestState,
fileManifestType,
fileSummaryFacetName,
filters,
formFacet,
}: DownloadCurlCommandProps): JSX.Element => {
useRequestFileManifest(
fileManifestType,
MANIFEST_DOWNLOAD_FORMAT.CURL,
filters,
fileSummaryFacetName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const ExportToTerra = ({
ExportToTerraStart,
ExportToTerraSuccess,
fileManifestState,
fileManifestType,
fileSummaryFacetName,
filters,
formFacet,
Expand All @@ -38,7 +39,12 @@ export const ExportToTerra = ({
const {
exploreState: { tabValue: entityList },
} = useExploreState();
useRequestFileManifest(manifestDownloadFormat, filters, fileSummaryFacetName);
useRequestFileManifest(
fileManifestType,
manifestDownloadFormat,
filters,
fileSummaryFacetName
);
const { requestParams } = fileManifestState;
const { data, isLoading, run } = useFileManifest();
const exportURL = useExportToTerraResponseURL(requestParams, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ export interface ManifestDownloadEntityProps {
}

export const ManifestDownloadEntity = ({
fileManifestType,
filters,
metadataFilters,
}: ManifestDownloadEntityProps): JSX.Element => {
useRequestFileManifest(MANIFEST_DOWNLOAD_FORMAT.COMPACT, filters, undefined);
useRequestFileManifest(
fileManifestType,
MANIFEST_DOWNLOAD_FORMAT.COMPACT,
filters,
undefined
);
return (
<>
<FileManifestSpreadsheet filters={metadataFilters} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ManifestDownloadProps {

export const ManifestDownload = ({
fileManifestState,
fileManifestType,
fileSummaryFacetName,
filters,
formFacet,
Expand All @@ -33,6 +34,7 @@ export const ManifestDownload = ({
ManifestDownloadSuccess,
}: ManifestDownloadProps): JSX.Element => {
useRequestFileManifest(
fileManifestType,
MANIFEST_DOWNLOAD_FORMAT.COMPACT,
filters,
fileSummaryFacetName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ export interface FileManifestRequestURL {
*/
export const buildFileManifestRequestURL = (
url: string,
filters: Filters,
filters: Filters | undefined,
catalog: string,
manifestFormat: ManifestDownloadFormat | undefined
): FileManifestRequestURL | undefined => {
if (!manifestFormat) {
return;
}
if (!manifestFormat) return;
if (!filters) return;

// Build request params.
const requestParams = new URLSearchParams({
Expand Down
11 changes: 5 additions & 6 deletions src/hooks/useFileManifest/common/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,20 @@ export interface FileFacet {
export enum FILE_MANIFEST_TYPE {
BULK_DOWNLOAD = "BULK_DOWNLOAD",
DOWNLOAD_MANIFEST = "DOWNLOAD_MANIFEST",
ENITY_EXPORT_TO_TERRA = "ENITY_EXPORT_TO_TERRA",
ENTITY_BULK_DOWNLOAD = "ENTITY_BULK_DOWNLOAD",
ENTITY_DOWNLOAD_MANIFEST = "ENTITY_DOWNLOAD_MANIFEST",
ENTITY_EXPORT_TO_TERRA = "ENTITY_EXPORT_TO_TERRA",
EXPORT_TO_TERRA = "EXPORT_TO_TERRA",
}

export type FileManifestType = FILE_MANIFEST_TYPE;

export enum FILE_MANIFEST_STATE_STATUS {
ACTIVE = "ACTIVE",
INACTIVE = "INACTIVE",
export enum FILES_FACETS_STATUS {
COMPLETED = "COMPLETED",
IN_PROGRESS = "IN_PROGRESS",
NOT_STARTED = "NOT_STARTED",
}

export type FileManifestStateStatus = FILE_MANIFEST_STATE_STATUS;

export type SelectedSearchTermsBySearchKey = Map<
CategoryKey,
Set<CategoryValueKey>
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/useFileManifest/useRequestFileManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { ManifestDownloadFormat } from "../../apis/azul/common/entities";
import { Filters } from "../../common/entities";
import { FileManifestActionKind } from "../../providers/fileManifestState";
import { useFileManifestState } from "../useFileManifestState";
import { FileManifestType } from "./common/entities";

/**
* Initializes and fetches file manifest comprising file facets and summary for the given file manifest format.
* @param fileManifestType - File manifest type.
* @param fileManifestFormat - File manifest format.
* @param initialFilters - Filters to initialize file manifest request.
* @param fileSummaryFacetName - File summary facet name.
*/
export const useRequestFileManifest = (
fileManifestType: FileManifestType | undefined,
fileManifestFormat: ManifestDownloadFormat | undefined,
initialFilters: Filters | undefined = [],
fileSummaryFacetName?: string
Expand All @@ -26,6 +29,7 @@ export const useRequestFileManifest = (
fileManifestDispatch({
payload: {
fileManifestFormat,
fileManifestType,
fileSummaryFacetName,
filters: initFilters,
},
Expand All @@ -40,6 +44,7 @@ export const useRequestFileManifest = (
}, [
fileManifestDispatch,
fileManifestFormat,
fileManifestType,
fileSummaryFacetName,
initFilters,
]);
Expand Down
88 changes: 30 additions & 58 deletions src/providers/fileManifestState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,26 @@ import {
import { useCatalog } from "../hooks/useCatalog";
import { buildNextFilterState } from "../hooks/useCategoryFilter";
import { buildFileManifestRequestURL } from "../hooks/useFileManifest/common/buildFileManifestRequestURL";
import { FileFacet } from "../hooks/useFileManifest/common/entities";
import {
FileFacet,
FileManifestType,
FILES_FACETS_STATUS,
} from "../hooks/useFileManifest/common/entities";
import { useFetchFilesFacets } from "../hooks/useFileManifest/useFetchFilesFacets";
import { useFetchSummary } from "../hooks/useFileManifest/useFetchSummary";
import { useFileManifestURL } from "../hooks/useFileManifest/useFileManifestURL";

// Default file manifest state.
export const DEFAULT_FILE_MANIFEST_STATE = {
fileManifestFormat: undefined,
fileSummary: undefined,
fileSummaryFacetName: undefined,
fileSummaryFilters: [],
filesFacets: [],
filters: [],
isEnabled: false,
isFacetsLoading: false,
isFacetsSuccess: false,
isFileSummaryLoading: false,
isLoading: false,
isSummaryLoading: false,
requestParams: undefined,
requestURL: undefined,
summary: undefined,
};
import { updateFileManifestAction } from "./fileManifestState/actions";
import { FILE_MANIFEST_STATE } from "./fileManifestState/constants";
import { getRequestFilters } from "./fileManifestState/utils";

/**
* File manifest state.
*/
export type FileManifestState = {
fileManifestFormat?: ManifestDownloadFormat;
fileManifestType?: FileManifestType;
filesFacets: FileFacet[];
filesFacetsStatus: FILES_FACETS_STATUS;
fileSummary?: AzulSummaryResponse;
fileSummaryFacetName?: string;
fileSummaryFilters: Filters;
Expand Down Expand Up @@ -76,7 +66,7 @@ export const FileManifestStateContext =
createContext<FileManifestStateContextProps>({
// eslint-disable-next-line @typescript-eslint/no-empty-function -- allow dummy function for default state.
fileManifestDispatch: () => {},
fileManifestState: DEFAULT_FILE_MANIFEST_STATE,
fileManifestState: FILE_MANIFEST_STATE,
});

export interface FileManifestStateProps {
Expand All @@ -96,7 +86,7 @@ export function FileManifestStateProvider({
const [fileManifestState, fileManifestDispatch] = useReducer(
(s: FileManifestState, a: FileManifestAction) =>
fileManifestReducer(s, a, { URL, catalog }),
DEFAULT_FILE_MANIFEST_STATE
FILE_MANIFEST_STATE
);

const { fileSummaryFacetName, fileSummaryFilters, filters, isEnabled } =
Expand Down Expand Up @@ -233,14 +223,15 @@ type UpdateFiltersCategoryAction = {
*/
type FetchFileManifestPayload = {
fileManifestFormat?: ManifestDownloadFormat;
fileManifestType?: FileManifestType;
fileSummaryFacetName?: string;
filters: Filters;
};

/**
* Update file manifest payload.
*/
type UpdateFileManifestPayload = {
export type UpdateFileManifestPayload = {
filesFacets: FileFacet[];
fileSummary?: AzulSummaryResponse;
isFacetsLoading: boolean;
Expand Down Expand Up @@ -288,6 +279,7 @@ function fileManifestReducer(
return {
...state,
fileManifestFormat: undefined,
filesFacetsStatus: FILES_FACETS_STATUS.NOT_STARTED,
isEnabled: false,
requestParams: undefined,
requestURL: undefined,
Expand All @@ -300,35 +292,29 @@ function fileManifestReducer(
payload.filters,
payload.fileSummaryFacetName
);
// Build request params and request URL.
const { requestParams, requestURL } =
buildFileManifestRequestURL(
URL,
payload.filters,
catalog,
payload.fileManifestFormat
) || {};
return {
...state,
...payload,
fileSummaryFilters,
isEnabled: true,
requestParams,
requestURL,
requestParams: undefined,
requestURL: undefined,
};
}
// Updates file manifest.
case FileManifestActionKind.UpdateFileManifest: {
return {
...state,
...payload,
};
return updateFileManifestAction(state, payload, fileManifestContext);
}
// Updates file manifest format.
case FileManifestActionKind.UpdateFileManifestFormat: {
// Build request params and request URL.
const { requestParams, requestURL } =
buildFileManifestRequestURL(URL, state.filters, catalog, payload) || {};
buildFileManifestRequestURL(
URL,
getRequestFilters(state),
catalog,
payload
) || {};
return {
...state,
fileManifestFormat: payload,
Expand All @@ -350,20 +336,13 @@ function fileManifestReducer(
filters,
state.fileSummaryFacetName
);
// Build request params and request URL.
const { requestParams, requestURL } =
buildFileManifestRequestURL(
URL,
filters,
catalog,
state.fileManifestFormat
) || {};
return {
...state,
fileSummaryFilters,
filesFacetsStatus: FILES_FACETS_STATUS.NOT_STARTED,
filters,
requestParams,
requestURL,
requestParams: undefined,
requestURL: undefined,
};
}
// Updates selected file manifest filters by category.
Expand All @@ -379,20 +358,13 @@ function fileManifestReducer(
filters,
state.fileSummaryFacetName
);
// Build request params and request URL.
const { requestParams, requestURL } =
buildFileManifestRequestURL(
URL,
filters,
catalog,
state.fileManifestFormat
) || {};
return {
...state,
fileSummaryFilters,
filesFacetsStatus: FILES_FACETS_STATUS.NOT_STARTED,
filters,
requestParams,
requestURL,
requestParams: undefined,
requestURL: undefined,
};
}
default:
Expand Down
34 changes: 34 additions & 0 deletions src/providers/fileManifestState/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { buildFileManifestRequestURL } from "../../hooks/useFileManifest/common/buildFileManifestRequestURL";
import {
FileManifestContext,
FileManifestState,
UpdateFileManifestPayload,
} from "../fileManifestState";
import { getRequestFilters, updateFilesFacetsStatus } from "./utils";

/**
* Update file manifest action.
* @param state - State.
* @param payload - Payload.
* @param context - Context.
* @returns state.
*/
export function updateFileManifestAction(
state: FileManifestState,
payload: UpdateFileManifestPayload,
context: FileManifestContext
): FileManifestState {
const { catalog, URL } = context;
const filesFacetsStatus = updateFilesFacetsStatus(state, payload);
const nextState = { ...state, ...payload, filesFacetsStatus };
const fileManifestRequest = buildFileManifestRequestURL(
URL,
getRequestFilters(nextState),
catalog,
nextState.fileManifestFormat
);
return {
...nextState,
...fileManifestRequest,
};
}
31 changes: 31 additions & 0 deletions src/providers/fileManifestState/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
FILE_MANIFEST_TYPE,
FILES_FACETS_STATUS,
} from "../../hooks/useFileManifest/common/entities";
import { FileManifestState } from "../fileManifestState";

export const ENTITIES_FILE_MANIFEST_TYPES: FILE_MANIFEST_TYPE[] = [
FILE_MANIFEST_TYPE.BULK_DOWNLOAD,
FILE_MANIFEST_TYPE.DOWNLOAD_MANIFEST,
FILE_MANIFEST_TYPE.EXPORT_TO_TERRA,
];

export const FILE_MANIFEST_STATE: FileManifestState = {
fileManifestFormat: undefined,
fileManifestType: undefined,
fileSummary: undefined,
fileSummaryFacetName: undefined,
fileSummaryFilters: [],
filesFacets: [],
filesFacetsStatus: FILES_FACETS_STATUS.NOT_STARTED,
filters: [],
isEnabled: false,
isFacetsLoading: false,
isFacetsSuccess: false,
isFileSummaryLoading: false,
isLoading: false,
isSummaryLoading: false,
requestParams: undefined,
requestURL: undefined,
summary: undefined,
};
Loading