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 expanded view filtered tagging #1834

Merged
merged 1 commit into from
Jun 20, 2022
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
1 change: 0 additions & 1 deletion app/packages/app/src/components/Actions/Tagger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ const useTagCallback = (modal, targetLabels, lookerRef = null) => {
set(selectors.anyTagging, false);

refreshers.forEach((r) => r());
set(atoms.tagging({ modal, labels: targetLabels }), false);
},
[modal, targetLabels, lookerRef]
);
Expand Down
89 changes: 47 additions & 42 deletions app/packages/app/src/components/Actions/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const allTags = selector<{ sample: string[]; label: string[] } | null>({
const labels = get(
aggregationAtoms.labelTagCounts({ modal: false, extended: false })
);

const sample = get(
aggregationAtoms.sampleTagCounts({ modal: false, extended: false })
);
Expand All @@ -92,38 +93,40 @@ export const tagStatistics = selectorFamily<
{ modal: boolean; labels: boolean }
>({
key: "tagStatistics",
get: ({ modal, labels: count_labels }) => async ({ get }) => {
const activeLabels = get(schemaAtoms.activeLabelFields({ modal }));
const selected = get(atoms.selectedSamples);

let labels: State.SelectedLabel[] = [];
if (modal) {
labels = Object.entries(get(atoms.selectedLabels)).map(
([labelId, data]) => ({
labelId,
...data,
})
);
}

const { count, tags } = await getFetchFunction()("POST", "/tagging", {
dataset: get(atoms.dataset).name,
view: get(view),
active_label_fields: activeLabels,
sample_ids: selected.size
? [...selected]
: modal
? [get(atoms.modal).sample._id]
: null,
labels: toSnakeCase(labels),
count_labels,
filters: get(modal ? filterAtoms.modalFilters : filterAtoms.filters),
hidden_labels:
modal && labels ? toSnakeCase(get(hiddenLabelsArray)) : null,
});

return { count, tags };
},
get:
({ modal, labels: count_labels }) =>
async ({ get }) => {
const activeLabels = get(schemaAtoms.activeLabelFields({ modal }));
const selected = get(atoms.selectedSamples);

let labels: State.SelectedLabel[] = [];
if (modal) {
labels = Object.entries(get(atoms.selectedLabels)).map(
([labelId, data]) => ({
labelId,
...data,
})
);
}

const { count, tags } = await getFetchFunction()("POST", "/tagging", {
dataset: get(atoms.dataset).name,
view: get(view),
active_label_fields: activeLabels,
sample_ids: selected.size
? [...selected]
: modal
? [get(atoms.modal).sample._id]
: null,
labels: toSnakeCase(labels),
count_labels,
filters: get(modal ? filterAtoms.modalFilters : filterAtoms.filters),
hidden_labels:
modal && labels ? toSnakeCase(get(hiddenLabelsArray)) : null,
});

return { count, tags };
},
});

export const numLabelsInSelectedSamples = selector<number>({
Expand All @@ -138,15 +141,17 @@ export const tagStats = selectorFamily<
{ modal: boolean; labels: boolean }
>({
key: "tagStats",
get: ({ modal, labels }) => ({ get }) => {
const tags = get(allTags);
const results = Object.fromEntries(
tags[labels ? "label" : "sample"].map((t) => [t, 0])
);
get:
({ modal, labels }) =>
({ get }) => {
const tags = get(allTags);
const results = Object.fromEntries(
tags[labels ? "label" : "sample"].map((t) => [t, 0])
);

return {
...results,
...get(tagStatistics({ modal, labels })).tags,
};
},
return {
...results,
...get(tagStatistics({ modal, labels })).tags,
};
},
});
16 changes: 12 additions & 4 deletions app/packages/app/src/recoil/aggregations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,21 @@ export const aggregations = selectorFamily<
({ modal, extended }) =>
async ({ get }) => {
let filters = null;
let hiddenLabels = null;
get(atoms.refresher);

if (extended && get(filterAtoms.hasFilters(modal))) {
filters = get(modal ? filterAtoms.modalFilters : filterAtoms.filters);
hiddenLabels = modal
? toSnakeCase(
Object.entries(get(atoms.hiddenLabels)).map(
([labelId, data]) => ({
labelId,
...data,
})
)
)
: null;
} else if (extended) {
return get(
aggregations({ extended: false, modal })
Expand All @@ -149,10 +160,7 @@ export const aggregations = selectorFamily<
sample_ids: modal ? get(atoms.modal).sample._id : null,
dataset,
view: get(viewAtoms.view),
hidden_labels:
modal && extended
? toSnakeCase(get(selectors.hiddenLabelsArray))
: null,
hidden_labels: hiddenLabels,
}
)) as { aggregations: AggregationsData };

Expand Down
6 changes: 0 additions & 6 deletions app/packages/app/src/recoil/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,13 @@ export const hiddenLabelsArray = selector({
...data,
}));
},
cachePolicy_UNSTABLE: {
eviction: "most-recent",
},
});

export const hiddenLabelIds = selector({
key: "hiddenLabelIds",
get: ({ get }) => {
return new Set(Object.keys(get(atoms.hiddenLabels)));
},
cachePolicy_UNSTABLE: {
eviction: "most-recent",
},
});

export const pathHiddenLabelsMap = selector<{
Expand Down