Skip to content

Commit

Permalink
[Fix] refactor func isTaskShouldBeDisabled by isActionAvailable
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Huang <[email protected]>
  • Loading branch information
kentwelcome committed Dec 11, 2024
1 parent a2d9cd0 commit 39683c1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 39 deletions.
8 changes: 3 additions & 5 deletions js/src/components/lineage/LineageViewTopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ const ControlItem = (props: {
export const LineageViewTopBar = () => {
const { nodes, deselect, selectMode, ...lineageViewContext } =
useLineageViewContext();
const { isTaskShouldBeDisabled } = useLineageGraphContext();
const { isActionAvailable } = useLineageGraphContext();
const selectNodes = useMemo(() => {
return nodes.filter((node) => node.data.isSelected);
}, [nodes]);
Expand Down Expand Up @@ -386,8 +386,7 @@ export const LineageViewTopBar = () => {
</MenuItem>
<Tooltip
label={
isTaskShouldBeDisabled &&
isTaskShouldBeDisabled("value_diff")
!isActionAvailable("value_diff")
? DisableTooltipMessages.audit_helper
: null
}
Expand All @@ -398,8 +397,7 @@ export const LineageViewTopBar = () => {
fontSize="10pt"
isDisabled={
!(isNoSelect || isSingleSelect || isMultiSelect) ||
(isTaskShouldBeDisabled &&
isTaskShouldBeDisabled("value_diff"))
!isActionAvailable("value_diff")
}
icon={<Icon as={findByRunType("value_diff")?.icon} />}
onClick={() => {
Expand Down
21 changes: 10 additions & 11 deletions js/src/components/lineage/NodeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function NodeView({ node, onCloseNode }: NodeViewProps) {
onClose: onCodeDiffClose,
} = useDisclosure();
const { runAction } = useRecceActionContext();
const { envInfo, isTaskShouldBeDisabled } = useLineageGraphContext();
const { envInfo, isActionAvailable } = useLineageGraphContext();
const { primaryKey } = useModelColumns(node.name);
const refetchRowCount = () => {
runAction(
Expand All @@ -87,7 +87,7 @@ export function NodeView({ node, onCloseNode }: NodeViewProps) {
if (isAddedOrRemoved) {
return DisableTooltipMessages.add_or_remove;
}
if (isTaskShouldBeDisabled && isTaskShouldBeDisabled(runType)) {
if (!isActionAvailable(runType)) {
if (runType === "value_diff") {
return DisableTooltipMessages.audit_helper;
} else if (runType === "profile_diff") {
Expand Down Expand Up @@ -126,9 +126,12 @@ export function NodeView({ node, onCloseNode }: NodeViewProps) {
} else if (envInfo?.adapterType === "sqlmesh") {
setSqlQuery(`select * from ${node.name}`);
}
setPrimaryKeys(
primaryKey !== undefined ? [primaryKey] : undefined
);
if (isActionAvailable("query_diff_with_primary_key")) {
// Only set primary key if the action is available
setPrimaryKeys(
primaryKey !== undefined ? [primaryKey] : undefined
);
}
setLocation("/query");
}}
>
Expand Down Expand Up @@ -160,9 +163,7 @@ export function NodeView({ node, onCloseNode }: NodeViewProps) {
icon={<Icon as={findByRunType("profile_diff")?.icon} />}
fontSize="14px"
isDisabled={
isAddedOrRemoved ||
(isTaskShouldBeDisabled &&
isTaskShouldBeDisabled("profile_diff"))
isAddedOrRemoved || !isActionAvailable("profile_diff")
}
onClick={() => {
runAction(
Expand All @@ -182,9 +183,7 @@ export function NodeView({ node, onCloseNode }: NodeViewProps) {
icon={<Icon as={findByRunType("value_diff")?.icon} />}
fontSize="14px"
isDisabled={
isAddedOrRemoved ||
(isTaskShouldBeDisabled &&
isTaskShouldBeDisabled("value_diff"))
isAddedOrRemoved || !isActionAvailable("value_diff")
}
onClick={() => {
runAction(
Expand Down
9 changes: 3 additions & 6 deletions js/src/components/query/QueryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const QueryForm = ({
onPrimaryKeysChange,
...prob
}: QueryFormProps) => {
const { lineageGraph, isTaskShouldBeDisabled } = useLineageGraphContext();
const { lineageGraph, isActionAvailable } = useLineageGraphContext();

const labelInfo =
"Provide a primary key to perform query diff in data warehouse and only return changed rows.";

Expand Down Expand Up @@ -62,11 +63,7 @@ export const QueryForm = ({
size="xs"
width={"240px"}
placeholder="Start by typing key name..."
isDisabled={
(isTaskShouldBeDisabled &&
isTaskShouldBeDisabled("query_diff_with_primary_key")) ||
false
}
isDisabled={!isActionAvailable("query_diff_with_primary_key")}
/>
</FormControl>
</Flex>
Expand Down
7 changes: 0 additions & 7 deletions js/src/components/query/QueryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,5 @@ export const QueryPage = () => {
)}
</Box>
</Flex>
/* <QueryForm
p="5px"
border="1px"
borderColor="gray.300"
defaultPrimaryKeys={primaryKeys}
onPrimaryKeysChange={setPrimaryKeys}
/> */
);
};
20 changes: 10 additions & 10 deletions js/src/lib/hooks/LineageGraphContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ export interface LineageGraphContextType {
isLoading?: boolean;
error?: string;
supportTasks?: { [key: string]: boolean };
isTaskShouldBeDisabled?: (taskName: string) => boolean;
retchLineageGraph?: () => void;
isActionAvailable: (actionName: string) => boolean;

runsAggregated?: RunsAggregated;
refetchRunsAggregated?: () => void;
}

const defaultLineageGraphsContext: LineageGraphContextType = {};
const defaultLineageGraphsContext: LineageGraphContextType = {
isActionAvailable: () => true,
};

const LineageGraphContext = createContext(defaultLineageGraphsContext);

Expand Down Expand Up @@ -208,15 +210,13 @@ export function LineageGraphContextProvider({ children }: LineageGraphProps) {

const { connectionStatus, connect } = useLineageWatcher();

const isTaskShouldBeDisabled = useCallback(
(taskName: string) => {
const isActionAvailable = useCallback(
(name: string) => {
if (supportTasks) {
const isSupport = supportTasks[taskName];
if (isSupport !== undefined) {
return !isSupport;
}
return supportTasks[name] ?? true; // default to true if action not found in supportTasks
}
return false;
// If the supportTasks does not be provided, all actions are available
return true;
},
[supportTasks]
);
Expand All @@ -238,7 +238,7 @@ export function LineageGraphContextProvider({ children }: LineageGraphProps) {
isLoading,
runsAggregated,
supportTasks,
isTaskShouldBeDisabled,
isActionAvailable,
refetchRunsAggregated: () => {
refetchRunsAggregated();
},
Expand Down

0 comments on commit 39683c1

Please sign in to comment.